dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_chan_wrapper.h
diff --git a/dol/src/dol/visitor/hdsd/scd/scd_chan_wrapper.h b/dol/src/dol/visitor/hdsd/scd/scd_chan_wrapper.h
new file mode 100644 (file)
index 0000000..44115b0
--- /dev/null
@@ -0,0 +1,95 @@
+#ifndef SCD_CHAN_WRAPPER_H
+#define SCD_CHAN_WRAPPER_H
+
+#include <string>
+
+#include <systemc>
+using sc_core::sc_prim_channel;
+
+#include "scd_sock_poller.h"
+#include "scd_socket.h"
+#include "scd_simulator.h"
+#include "scd_rem_chan_if.h"
+
+
+/**
+ * Size of the input buffer. Limits the ammount of data that
+ * can be read from the socket in one system call.
+ */
+static const size_t SCD_CHAN_BUFLEN = 512;
+
+/* forward declaration */
+class scd_simulator;
+
+
+/**
+ * Wrapper for a remote channel. Writes data from the output buffer
+ * of the channel to the socket. Receives data from the socket and 
+ * writes it to the input buffer of the channel.
+ */
+class scd_chan_wrapper : public scd_sock_ev_handler_if
+{
+public:
+    /**
+     * Constructor.
+     * \param sim the simulation environment
+     * \param name the name of the channel
+     * \param chan the SystemC channel implementing 
+     * remote channel interface(s)
+     */
+    scd_chan_wrapper(scd_simulator& sim, const std::string& name,
+            sc_prim_channel& chan);
+
+    virtual ~scd_chan_wrapper();
+
+    /**
+     * Indicates if a socket has been set for this channel.
+     * \return true if a socket has been set
+     */
+    bool is_initialized() const;
+
+    /**
+     * Returns the name of the channel.
+     */
+    const std::string& get_name() const;
+
+    /**
+     * Sets the socket of the channel.
+     */
+    void connect(scd_socket* sock);
+
+    /**
+     * Checks if data has to be send or can be received again and activates
+     * transmission if necessary. Call this function after every simulation
+     * step.
+     */
+    void process();
+
+    /**
+     * Closes the connection to the peer.
+     */
+    void close();
+    
+
+    /* scd_sock_ev_handler_if */
+    void handle_sock_ev(sock_ev events);
+    const scd_socket &get_sock();
+
+private:
+    scd_simulator& _sim;
+    std::string _name;
+    bool _is_initialized;
+
+    scd_socket* _socket;
+    scd_rem_chan_in_if* _chan_in;
+    scd_rem_chan_out_if* _chan_out;
+    char _buf[SCD_CHAN_BUFLEN];
+    bool _is_writing;
+    bool _is_reading;
+
+    /* member functions */
+    void _write_event();
+    void _read_event();
+};
+
+#endif