dol: initial dol commit
[jump.git] / dol / src / dol / visitor / hdsd / scd / fsm / scd_stm_base.cpp
diff --git a/dol/src/dol/visitor/hdsd/scd/fsm/scd_stm_base.cpp b/dol/src/dol/visitor/hdsd/scd/fsm/scd_stm_base.cpp
new file mode 100644 (file)
index 0000000..a0175a3
--- /dev/null
@@ -0,0 +1,103 @@
+#include "fsm/scd_stm_base.h"
+
+#include "scd_logging.h"
+#include "scd_exception.h"
+#include "scd_cont_man_master.h"
+#include "scd_command.h"
+#include "scd_cont_man.h"
+
+
+scd_stm_base::scd_stm_base(scd_simulator& sim, scd_cont_man_master& fsm):
+    scd_cont_state(sim), _fsm(fsm), _slaves(fsm._slaves),
+    _time_step(fsm._time_step),
+    _st_init(fsm._st_init), _st_busy(fsm._st_busy), _st_idle(fsm._st_idle),
+    _st_done(fsm._st_done), _st_time_req(fsm._st_time_req),
+    _st_time(fsm._st_time), _st_term_req(fsm._st_term_req),
+    _st_terminate(fsm._st_terminate), _st_terminated(fsm._st_terminated),
+    _st_fail(fsm._st_fail), _st_failed(fsm._st_failed)
+{
+}
+
+
+void scd_stm_base::set_fail()
+{
+    std::list<scd_cont_slave_wrapper*>::iterator it;
+
+    for (it = _slaves.begin(); it != _slaves.end(); it++)
+    {
+        (*it)->set_fail();
+    }
+
+    _fsm.set_state(_st_fail);
+} // set_fail()
+
+
+void scd_stm_base::process()
+{
+    // check for failed slaves and react
+    if (!_check_slaves())
+        return;
+}
+
+
+bool scd_stm_base::active() const { return true; }
+
+
+bool scd_stm_base::busy() const { return false; }
+
+
+bool scd_stm_base::failed() const { return false; }
+
+
+bool scd_stm_base::advance_time() const { return false; }
+
+
+const sc_core::sc_time& scd_stm_base::get_time_step()
+{
+    scd_error("illegal call to get_time_step()");
+    throw scd_exception("illegal call");
+}
+
+
+bool scd_stm_base::_check_slaves()
+{
+
+    std::list<scd_cont_slave_wrapper*>::iterator iter;
+
+    for (iter = _slaves.begin(); iter != _slaves.end(); iter++)
+    {
+        if ( (*iter)->failed() )
+        {
+            scd_error("slave \"" + (*iter)->get_name() + "\" failed");
+            set_fail();
+            return false;
+        }
+    }
+
+    return true;
+
+} // _check_slaves()
+
+
+bool scd_stm_base::_some_slaves_active()
+{
+    std::list<scd_cont_slave_wrapper*>::iterator iter;
+
+    for (iter = _slaves.begin(); iter != _slaves.end(); iter++)
+    {
+        if ( (*iter)->active() )
+            return true;
+    }
+
+    return false;
+
+} // _some_slaves_active()
+
+
+void scd_stm_base::_close_slaves()
+{
+    std::list<scd_cont_slave_wrapper*>::iterator iter;
+
+    for (iter = _slaves.begin(); iter != _slaves.end(); iter++)
+        (*iter)->close();
+}