--- /dev/null
+#include "scd_cont_man_master.h"
+
+#include "scd_logging.h"
+#include "scd_exception.h"
+
+
+scd_cont_man_master::scd_cont_man_master(scd_simulator& sim):
+ _sim(sim), scd_cont_fsm("master"),
+ _st_init(sim, *this), _st_busy(sim, *this), _st_idle(sim, *this),
+ _st_done(sim, *this), _st_time_req(sim, *this), _st_time(sim, *this),
+ _st_term_req(sim, *this), _st_terminate(sim, *this),
+ _st_terminated(sim, *this), _st_fail(sim, *this), _st_failed(sim, *this)
+{
+ // set initial state
+ set_state(_st_init);
+}
+
+
+scd_cont_man_master::~scd_cont_man_master()
+{
+ std::list<scd_cont_slave_wrapper*>::iterator it;
+
+ for (it = _slaves.begin(); it != _slaves.end(); it++)
+ delete *it;
+}
+
+
+void scd_cont_man_master::connect_slave(const scd_command &c, scd_socket* sock)
+{
+ std::string name = c.get_string();
+
+ scd_cont_slave_wrapper* slave = _get_slave(name);
+
+ if (slave == NULL)
+ {
+ scd_warn("unknown slave \"" + name + "\"");
+ delete sock;
+ }
+ else
+ slave->connect(sock);
+
+} // connect()
+
+
+void scd_cont_man_master::set_master(const std::string& host, uint16_t port)
+{
+ scd_error("simulator is master, can not have another master");
+ throw scd_exception("simulator is master");
+} // set_master()
+
+
+void scd_cont_man_master::register_slave(const std::string& name)
+{
+ if ( _get_slave(name) != NULL )
+ {
+ scd_warn("slave \"" + name + "\" already registered, ignoring...");
+ }
+ else
+ {
+ scd_cont_slave_wrapper* wrap;
+ wrap = new scd_cont_slave_wrapper(_sim, name);
+ _slaves.push_back(wrap);
+ }
+
+} // register_slave
+
+
+void scd_cont_man_master::process()
+{
+ std::list<scd_cont_slave_wrapper*>::iterator it;
+
+ // process all slaves
+ for (it = _slaves.begin(); it != _slaves.end(); it++)
+ (*it)->process();
+
+ // process the local state
+ _state->process();
+}
+
+
+scd_cont_slave_wrapper* scd_cont_man_master::_get_slave(const std::string& name)
+{
+ std::list<scd_cont_slave_wrapper*>::iterator it;
+
+ for (it = _slaves.begin(); it != _slaves.end(); it++)
+ {
+ if ( (*it)->get_name() == name )
+ return *it;
+ }
+
+ return NULL;
+
+} // _get_slave()