summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gr-run-waveform/xyzzy.cc118
-rw-r--r--gr-run-waveform/xyzzy.h9
2 files changed, 59 insertions, 68 deletions
diff --git a/gr-run-waveform/xyzzy.cc b/gr-run-waveform/xyzzy.cc
index a734b6995..807824a4c 100644
--- a/gr-run-waveform/xyzzy.cc
+++ b/gr-run-waveform/xyzzy.cc
@@ -38,71 +38,6 @@
using namespace std;
typedef void* handle_t;
-static int
-xyzzy_fill_input (SCM port)
-{
- size_t count;
- scm_t_port *gr_port = SCM_PTAB_ENTRY (port);
- SCM bport = SCM_PACK(SCM_STREAM(port));
- scm_t_port *gr_bport = SCM_PTAB_ENTRY (bport);
-
- // FLush the output if a write is artive
- if (gr_bport->rw_active == SCM_PORT_WRITE) {
- scm_force_output (bport);
- }
-
- count = gr_bport->read_end - gr_bport->read_pos;
-
- if (gr_bport->read_pos >= gr_bport->read_end) {
- scm_fill_input (bport);
- }
-
- count = gr_bport->read_end - gr_bport->read_pos;
- if (count > gr_port->read_buf_size) {
- count = gr_port->read_buf_size;
- }
-
- memcpy (gr_port->read_buf, gr_bport->read_pos, count);
- gr_bport->read_pos += count;
-
- if (gr_bport->rw_random) {
- gr_bport->rw_active = SCM_PORT_READ;
- }
-
- if (count == 0) {
- return EOF;
- } else {
- gr_port->read_pos = gr_port->read_buf;
- gr_port->read_end = gr_port->read_buf + count;
- return *gr_port->read_buf;
- }
-}
-
-static int
-xyzzy_flush (SCM port)
-{
- SCM bport = SCM_PACK(SCM_STREAM(port));
- scm_t_port *c_port = SCM_PTAB_ENTRY (port);
- size_t count = c_port->write_pos - c_port->write_buf;
-
- scm_c_write (bport, c_port->write_buf, count);
-
- c_port->write_pos = c_port->write_buf;
- c_port->rw_active = SCM_PORT_NEITHER;
-
- scm_force_output (bport);
-}
-
-
-static int
-xyzzy_close (SCM port)
-{
- if (SCM_OUTPUT_PORT_P (port)) {
- xyzzy_flush (port);
- return scm_is_true (scm_close_port (SCM_PACK(SCM_STREAM(port)))) ? 0 : -1;
- }
- return 0;
-}
XYZZY::XYZZY()
{
@@ -193,7 +128,8 @@ XYZZY::file_exists(const std::string &filespec)
SCM
XYZZY::make_read_only_port(const std::string &filespec)
{
- scm_t_bits bits = scm_make_port_type("gnuradio", xyzzy_fill_input, 0);
+ scm_t_bits bits = scm_make_port_type("gnuradio", xyzzy_fill_input, xyzzy_write);
+ scm_set_port_flush (bits, xyzzy_flush);
scm_set_port_close (bits, xyzzy_close);
}
@@ -266,7 +202,55 @@ XYZZY::read_dir_entry(boost::uint8_t *entry)
extern "C" {
static XYZZY datafile;
+
+void
+xyzzy_write (SCM port, const void *data, size_t size)
+{
+ // This is a read only file
+}
+
+void
+xyzzy_flush (SCM port)
+{
+ SCM bport = SCM_PACK(SCM_STREAM(port));
+ scm_t_port *c_port = SCM_PTAB_ENTRY (port);
+ size_t count = c_port->write_pos - c_port->write_buf;
+
+ scm_c_write (bport, c_port->write_buf, count);
+
+ c_port->write_pos = c_port->write_buf;
+ c_port->rw_active = SCM_PORT_NEITHER;
+
+ scm_force_output (bport);
+}
+
+int
+xyzzy_close (SCM port)
+{
+ if (SCM_OUTPUT_PORT_P (port)) {
+ // XYZZY::flush (port);
+ return scm_is_true (scm_close_port (SCM_PACK(SCM_STREAM(port)))) ? 0 : -1;
+ }
+ return 0;
+}
+int
+xyzzy_fill_input (SCM port)
+{
+ scm_t_port *gr_port = SCM_PTAB_ENTRY (port);
+ if (gr_port->read_pos + gr_port->read_buf_size > gr_port->read_end) {
+ return EOF;
+ }
+
+ // if (_contents.empty()) {
+ // gr_port->read_buf; // = datafile.file_exists("FOO");
+ // gr_port->read_end = gr_port->read_buf + gr_port->read_buf_size;
+ // gr_port->read_pos += gr_port->read_buf_size;
+ // }
+
+ return *gr_port->read_buf;
+}
+
// Initialize with the data file produced by gen-xyzzy.
bool
xyzzy_init(const std::string &filespec)
@@ -287,5 +271,5 @@ xyzzy_make_read_only_port(const std::string &filespec)
{
return datafile.make_read_only_port(filespec);
}
-
+
} // end of extern C
diff --git a/gr-run-waveform/xyzzy.h b/gr-run-waveform/xyzzy.h
index aaadd8560..5bdb531e9 100644
--- a/gr-run-waveform/xyzzy.h
+++ b/gr-run-waveform/xyzzy.h
@@ -94,6 +94,7 @@ public:
static std::string read_string(struct string_entry &entry);
static std::string read_string(std::ifstream &stream);
+ // Read the header of the datafile
boost::shared_ptr<struct header> read_header(boost::uint8_t *header);
boost::shared_ptr<struct directory_entry> read_dir_entry(boost::uint8_t *header);
@@ -105,6 +106,12 @@ private:
// C linkage bindings for Guile
extern "C" {
+
+// These are the callbacks for thw guile ports
+int xyzzy_fill_input (SCM port);
+void xyzzy_write (SCM port, const void *data, size_t size);
+void xyzzy_flush (SCM port);
+int xyzzy_close (SCM port);
// Initialize with the data file produced by gen-xyzzy.
bool xyzzy_init(const std::string &filespec);
@@ -114,7 +121,7 @@ bool xyzzy_file_exists(const std::string &filespec);
// Return a C port that will read the file contents
SCM xyzzy_make_read_only_port(const std::string &filespec);
-
+
} // end of extern C
#endif // _XYZZY_H_ 1