X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2Fscd%2Fscd_chan_man.h;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2Fscd%2Fscd_chan_man.h;h=0b026ccf134b5ae92d1ab8186ffb8e60f98777a7;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/hdsd/scd/scd_chan_man.h b/dol/src/dol/visitor/hdsd/scd/scd_chan_man.h new file mode 100644 index 0000000..0b026cc --- /dev/null +++ b/dol/src/dol/visitor/hdsd/scd/scd_chan_man.h @@ -0,0 +1,117 @@ +#ifndef SCD_CHAN_MAN_H +#define SCD_CHAN_MAN_H + +#include +#include + +#include +using sc_core::sc_prim_channel; + +#include "scd_simulator.h" +#include "scd_command.h" +#include "scd_chan_wrapper.h" +#include "scd_out_connector.h" + + +/* forward declaration */ +class scd_out_connector; +class scd_chan_wrapper; + + +/** + * The channel manager holds all remote channels. The channels have + * to be registered before the simulator is initiated. The channel + * manager will then initiate connections to other simulators + * and will handle channels from incomming connections. + * During simulation data is sent from the channel output buffers + * to remote hosts and data is received and stored in the input buffers. + * The channel implementation will then generate events to resume + * simulation processes. + */ +class scd_chan_man +{ +public: + /** + * Constructor. + * \param sim the simulator + */ + scd_chan_man(scd_simulator &sim); + + virtual ~scd_chan_man(); + + /** + * Registers a remote channel with master endpoint on this host. + * Another host will initiate the connection and the channel will + * be connected by an in-connector calling connect_channel(). + * \param name the name of the remote channel + * \param mchan the SystemC channel implementing the + * remote-in and/or the remote-out interface. + */ + void register_channel(const std::string &name, sc_prim_channel& mchan); + + /** + * Registers a remote channel with slave endpoint on this host. + * This host will initiate the connection to the host with the + * master endpoint. To drive this process init_process() has to + * be called periodically. + * \param name the name of the remote channel + * \param mchan the SystemC channel implementing the + * remote-in and/or the remote-out interface. + * \param host the FQDN or IP address of the remote simulator + * with the master endpoint of the channel + * \param port TCP port of the remote simulator + */ + void register_channel(const std::string &name, sc_prim_channel& schan, + const std::string &host, const uint16_t port); + /** + * Drives the initialization process. Restarts outgoing connection + * attempts to connect channels to other simulators if previous + * attempts have timed out. ready() indicates the end of the + * initialization. + */ + void init_process(); + + /** + * Connects a channel from an incomming connection. Is intended to be + * called from an in-connector. + * \param c the register command received by the in-connector (contains + * the channel name) + * \param sock the socket of the incoming connection that is used + * as the data channel + */ + void connect_channel(const scd_command &c, scd_socket* sock); + + /** + * Indicates if all clients have been connected. + * \return true if the channel manager completed initialization + */ + bool ready() const; + + /** + * Checks if channels have data in the output buffers and activates + * the transmission if necessary. Receiption is resumed if the input + * buffer can accept data again. Call this function after each + * simulation step (which might fill data into the buffers that has + * to be sent). + */ + void process(); + + /** + * Closes all channels. + */ + void close(); + +private: + /* member variables */ + scd_simulator& _sim; + std::list _channels; + std::list _connectors; + + bool _is_ready; + + /* member functions */ + bool _check_ready(); + scd_chan_wrapper* _get_channel(const std::string& name); +}; + +#endif