X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2Fscd%2Fscd_chan_wrapper.h;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2Fscd%2Fscd_chan_wrapper.h;h=44115b0a69e1a5e9947e9aa6f104bcc68d6ddf39;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git 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 index 0000000..44115b0 --- /dev/null +++ b/dol/src/dol/visitor/hdsd/scd/scd_chan_wrapper.h @@ -0,0 +1,95 @@ +#ifndef SCD_CHAN_WRAPPER_H +#define SCD_CHAN_WRAPPER_H + +#include + +#include +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