1 #include "scd_chan_man.h"
3 #include "scd_logging.h"
6 scd_chan_man::scd_chan_man(scd_simulator &sim):
7 _sim(sim), _is_ready(false) {}
10 scd_chan_man::~scd_chan_man()
12 std::list<scd_out_connector*>::iterator coit;
13 std::list<scd_chan_wrapper*>::iterator chit;
15 for (coit = _connectors.begin(); coit != _connectors.end(); coit++)
18 for (chit = _channels.begin(); chit != _channels.end(); chit++)
23 void scd_chan_man::register_channel(const std::string &name, sc_prim_channel& mchan)
25 if ( _get_channel(name) != NULL )
27 scd_warn("channel \"" + name + "\" already registered, ignoring...");
31 scd_chan_wrapper* wrap = new scd_chan_wrapper(_sim, name, mchan);
32 _channels.push_back(wrap);
35 } // register_channel() - master
38 void scd_chan_man::register_channel(const std::string &name,
39 sc_prim_channel& schan, const std::string &host, const uint16_t port)
41 if ( _get_channel(name) != NULL )
43 scd_warn("channel \"" + name + "\" already registered, ignoring...");
48 scd_chan_wrapper* wrap = new scd_chan_wrapper(_sim, name, schan);
49 _channels.push_back(wrap);
52 scd_out_connector* conn = new scd_out_connector(_sim, SCD_CM_CHANNEL,
54 conn->connect_to(host, port);
55 _connectors.push_back(conn);
58 } // register_channel() - slave
61 void scd_chan_man::init_process()
66 std::list<scd_out_connector*>::iterator coit;
68 // check all connectors
69 for (coit = _connectors.begin(); coit != _connectors.end();)
71 scd_out_connector& conn = **coit;
73 // retry to connect if necessary
76 if (!conn.is_connecting() && !conn.has_connection())
79 scd_error("failed to connect channel \""
80 + conn.get_name() + "\"");
83 coit = _connectors.erase(coit);
85 _sim.get_cont_man().set_fail();
88 else if (!conn.is_connecting() && conn.has_connection())
90 // channel is connected
91 scd_chan_wrapper& chan = *_get_channel(conn.get_name());
93 if (chan.is_initialized())
95 scd_error("channel \""
96 + conn.get_name() + "\" already connected");
99 coit = _connectors.erase(coit);
101 _sim.get_cont_man().set_fail();
106 scd_info("connected channel \"" + conn.get_name() + "\"");
107 chan.connect(conn.get_connection());
110 coit = _connectors.erase(coit);
112 } // end channel connected
115 // still trying to connect
118 // end this connector
119 } // end check all connectors
121 // check if everything is initiated
127 void scd_chan_man::connect_channel(const scd_command &c, scd_socket* sock)
129 std::string name = c.get_string();
131 scd_chan_wrapper* chan = _get_channel(name);
135 scd_warn("unknown channel \"" + name + "\" supplied by peer");
138 else if (chan->is_initialized())
140 scd_warn("channel \"" + name + "\" supplied by peer already connected");
144 scd_info("connected channel \"" + name + "\"");
151 bool scd_chan_man::ready() const { return _is_ready; }
154 void scd_chan_man::process()
156 std::list<scd_chan_wrapper*>::iterator chit;
158 for (chit = _channels.begin(); chit != _channels.end(); chit++)
164 void scd_chan_man::close()
166 std::list<scd_out_connector*>::iterator coit;
167 std::list<scd_chan_wrapper*>::iterator chit;
169 for (coit = _connectors.begin(); coit != _connectors.end(); coit++)
172 for (chit = _channels.begin(); chit != _channels.end(); chit++)
178 bool scd_chan_man::_check_ready()
183 if (_connectors.empty())
185 std::list<scd_chan_wrapper*>::iterator chit;
187 // check all channels
188 for (chit = _channels.begin(); chit != _channels.end(); chit++)
190 if ( !(*chit)->is_initialized() )
194 // all channels initiated
204 scd_chan_wrapper* scd_chan_man::_get_channel(const std::string& name)
206 std::list<scd_chan_wrapper*>::iterator chit;
208 for (chit = _channels.begin(); chit != _channels.end(); chit++)
210 if ( (*chit)->get_name() == name )