dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / scd_chan_man.h
1 #ifndef SCD_CHAN_MAN_H
2 #define SCD_CHAN_MAN_H
3
4 #include <string>
5 #include <list>
6
7 #include <systemc>
8 using sc_core::sc_prim_channel;
9
10 #include "scd_simulator.h"
11 #include "scd_command.h"
12 #include "scd_chan_wrapper.h"
13 #include "scd_out_connector.h"
14
15
16 /* forward declaration */
17 class scd_out_connector;
18 class scd_chan_wrapper;
19
20
21 /**
22  * The channel manager holds all remote channels. The channels have
23  * to be registered before the simulator is initiated. The channel
24  * manager will then initiate connections to other simulators
25  * and will handle channels from incomming connections.
26  * During simulation data is sent from the channel output buffers
27  * to remote hosts and data is received and stored in the input buffers.
28  * The channel implementation will then generate events to resume
29  * simulation processes.
30  */
31 class scd_chan_man
32 {
33 public:
34     /**
35      * Constructor.
36      * \param sim the simulator
37      */
38     scd_chan_man(scd_simulator &sim);
39
40     virtual ~scd_chan_man();
41
42     /**
43      * Registers a remote channel with master endpoint on this host.
44      * Another host will initiate the connection and the channel will
45      * be connected by an in-connector calling connect_channel().
46      * \param name the name of the remote channel
47      * \param mchan the SystemC channel implementing the
48      * remote-in and/or the remote-out interface.
49      */
50     void register_channel(const std::string &name, sc_prim_channel& mchan);
51
52     /**
53      * Registers a remote channel with slave endpoint on this host.
54      * This host will initiate the connection to the host with the
55      * master endpoint. To drive this process init_process() has to
56      * be called periodically.
57      * \param name the name of the remote channel
58      * \param mchan the SystemC channel implementing the
59      * remote-in and/or the remote-out interface.
60      * \param host the FQDN or IP address of the remote simulator
61      * with the master endpoint of the channel
62      * \param port TCP port of the remote simulator
63      */
64     void register_channel(const std::string &name, sc_prim_channel& schan,
65             const std::string &host, const uint16_t port);
66     /**
67      * Drives the initialization process. Restarts outgoing connection
68      * attempts to connect channels to other simulators if previous
69      * attempts have timed out. ready() indicates the end of the
70      * initialization.
71      */
72     void init_process();
73
74     /**
75      * Connects a channel from an incomming connection. Is intended to be
76      * called from an in-connector.
77      * \param c the register command received by the in-connector (contains
78      * the channel name)
79      * \param sock the socket of the incoming connection that is used
80      * as the data channel
81      */
82     void connect_channel(const scd_command &c, scd_socket* sock);
83
84     /**
85      * Indicates if all clients have been connected.
86      * \return true if the channel manager completed initialization
87      */
88     bool ready() const;
89
90     /**
91      * Checks if channels have data in the output buffers and activates
92      * the transmission if necessary. Receiption is resumed if the input
93      * buffer can accept data again. Call this function after each
94      * simulation step (which might fill data into the buffers that has
95      * to be sent).
96      */
97     void process();
98
99     /**
100      * Closes all channels.
101      */
102     void close();
103
104 private:
105     /* member variables */
106     scd_simulator& _sim;
107     std::list<scd_chan_wrapper*> _channels;
108     std::list<scd_out_connector*> _connectors;
109
110     bool _is_ready;
111
112     /* member functions */
113     bool _check_ready();
114     scd_chan_wrapper* _get_channel(const std::string& name);
115 };
116
117 #endif