Browse Source

Remove link list manipulation in Coordinator classes

Eric Ramat 11 years ago
parent
commit
9c5a825b92

+ 2 - 30
src/dtss/Coordinator.hpp

@@ -79,27 +79,7 @@ public:
 
     common::Time dispatch_events(common::Bag bag, common::Time t)
     {
-        for (auto & ymsg : bag) {
-            common::Links::Result result_model =
-                _graph_manager.links().find(ymsg.get_model(), ymsg.get_port_name());
-
-            for (common::Links::const_iterator it = result_model.first;
-                 it != result_model.second; ++it) {
-                // event on output port of coupled model
-                if (it->second.get_model() == this) {
-                    common::Bag ymessages;
-
-                    ymessages.push_back(
-                        common::ExternalEvent(it->second, ymsg.get_content()));
-                    dynamic_cast < common::Coordinator* >(get_parent())
-                        ->dispatch_events(ymessages, t);
-                } else { // event on input port of internal model
-                    it->second.get_model()->post_event(
-                        t, common::ExternalEvent(it->second,
-                                                 ymsg.get_content()));
-                }
-            }
-        }
+        _graph_manager.dispatch_events(bag, t);
         return _tn;
     }
 
@@ -123,15 +103,7 @@ public:
                     const common::ExternalEvent& event)
     {
         if (t == _tn) {
-            common::Links::Result result =
-                _graph_manager.links().find(this, event.get_port_name());
-
-            for (common::Links::const_iterator it_r = result.first;
-                 it_r != result.second; ++it_r) {
-                it_r->second.get_model()->post_event(
-                    t, common::ExternalEvent(it_r->second,
-                                             event.get_content()));
-            }
+            _graph_manager.post_event(t, event);
         } else {
             _policy(t, event, _tl, _tn);
         }

+ 44 - 2
src/dtss/GraphManager.cpp

@@ -45,10 +45,52 @@ void GraphManager::add_child(common::Model* child)
     child->set_parent(_coordinator);
 }
 
-void GraphManager::add_link(common::Model* out_model, const std::string& out_port_name,
-                            common::Model* in_model, const std::string& in_port_name)
+void GraphManager::add_link(common::Model* out_model,
+                            const std::string& out_port_name,
+                            common::Model* in_model,
+                            const std::string& in_port_name)
 {
     _link_list.add(out_model, out_port_name, in_model, in_port_name);
 }
 
+void GraphManager::dispatch_events(common::Bag bag, common::Time t)
+{
+    for (auto & ymsg : bag) {
+        common::Links::Result result_model =
+            _link_list.find(ymsg.get_model(),
+                            ymsg.get_port_name());
+
+        for (common::Links::const_iterator it = result_model.first;
+             it != result_model.second; ++it) {
+            // event on output port of coupled model
+            if (it->second.get_model() == _coordinator) {
+                common::Bag ymessages;
+
+                ymessages.push_back(
+                    common::ExternalEvent(it->second, ymsg.get_content()));
+                dynamic_cast < common::Coordinator* >(
+                    _coordinator->get_parent())->dispatch_events(ymessages, t);
+            } else { // event on input port of internal model
+                it->second.get_model()->post_event(
+                    t, common::ExternalEvent(it->second,
+                                             ymsg.get_content()));
+            }
+        }
+    }
+}
+
+void GraphManager::post_event(common::Time t,
+                              const common::ExternalEvent& event)
+{
+    common::Links::Result result =
+        _link_list.find(_coordinator, event.get_port_name());
+
+    for (common::Links::const_iterator it_r = result.first;
+         it_r != result.second; ++it_r) {
+        it_r->second.get_model()->post_event(
+            t, common::ExternalEvent(it_r->second,
+                                     event.get_content()));
+    }
+}
+
 } } // namespace paradevs dtss

+ 10 - 4
src/dtss/GraphManager.hpp

@@ -40,12 +40,18 @@ public:
     virtual ~GraphManager();
 
     virtual void add_child(common::Model* child);
-    virtual void add_link(common::Model* out_model, const std::string& out_port_name,
-                          common::Model* in_model, const std::string& in_port_name);
+
+    virtual void add_link(common::Model* out_model,
+                          const std::string& out_port_name,
+                          common::Model* in_model,
+                          const std::string& in_port_name);
+
     const common::Models& children() const
     { return _child_list; }
-    const common::Links& links() const
-    { return _link_list; }
+
+    void dispatch_events(common::Bag bag, common::Time t);
+
+    void post_event(common::Time t, const common::ExternalEvent& event);
 
 private:
     common::Links        _link_list;

+ 2 - 30
src/pdevs/Coordinator.hpp

@@ -187,15 +187,7 @@ public:
         common::Trace::trace().flush();
 
         add_event(event);
-
-        common::Links::Result result =
-            _graph_manager.links().find(this, event.get_port_name());
-
-        for (common::Links::const_iterator it_r = result.first;
-             it_r != result.second; ++it_r) {
-            it_r->second.get_model()->post_event(
-                t, common::ExternalEvent(it_r->second, event.get_content()));
-        }
+        _graph_manager.post_event(t, event);
         update_event_table(t);
         _tn = _event_table.get_current_time();
 
@@ -219,27 +211,7 @@ public:
                                << " ; bag = " << bag.to_string();
         common::Trace::trace().flush();
 
-        for (auto & ymsg : bag) {
-            common::Links::Result result_model =
-                _graph_manager.links().find(ymsg.get_model(), ymsg.get_port_name());
-
-            for (common::Links::const_iterator it = result_model.first;
-                 it != result_model.second; ++it) {
-                // event on output port of coupled model
-                if (it->second.get_model() == this) {
-                    common::Bag ymessages;
-
-                    ymessages.push_back(
-                        common::ExternalEvent(it->second, ymsg.get_content()));
-                    dynamic_cast < common::Coordinator* >(get_parent())->dispatch_events(
-                        ymessages, t);
-                } else { // event on input port of internal model
-                    it->second.get_model()->post_event(
-                        t, common::ExternalEvent(it->second,
-                                                 ymsg.get_content()));
-                }
-            }
-        }
+        _graph_manager.dispatch_events(bag, t);
 
         common::Trace::trace() << common::TraceElement(get_name(), t,
                                                        common::Y_MESSAGE)

+ 44 - 2
src/pdevs/GraphManager.cpp

@@ -45,10 +45,52 @@ void GraphManager::add_child(common::Model* child)
     child->set_parent(_coordinator);
 }
 
-void GraphManager::add_link(common::Model* out_model, const std::string& out_port_name,
-                            common::Model* in_model, const std::string& in_port_name)
+void GraphManager::add_link(common::Model* out_model,
+                            const std::string& out_port_name,
+                            common::Model* in_model,
+                            const std::string& in_port_name)
 {
     _link_list.add(out_model, out_port_name, in_model, in_port_name);
 }
 
+void GraphManager::dispatch_events(common::Bag bag, common::Time t)
+{
+    for (auto & ymsg : bag) {
+        common::Links::Result result_model =
+            _link_list.find(ymsg.get_model(),
+                            ymsg.get_port_name());
+
+        for (common::Links::const_iterator it = result_model.first;
+             it != result_model.second; ++it) {
+            // event on output port of coupled model
+            if (it->second.get_model() == _coordinator) {
+                common::Bag ymessages;
+
+                ymessages.push_back(
+                    common::ExternalEvent(it->second, ymsg.get_content()));
+                dynamic_cast < common::Coordinator* >(
+                    _coordinator->get_parent())->dispatch_events(ymessages, t);
+            } else { // event on input port of internal model
+                it->second.get_model()->post_event(
+                    t, common::ExternalEvent(it->second,
+                                             ymsg.get_content()));
+            }
+        }
+    }
+}
+
+void GraphManager::post_event(common::Time t,
+                              const common::ExternalEvent& event)
+{
+    common::Links::Result result =
+        _link_list.find(_coordinator, event.get_port_name());
+
+    for (common::Links::const_iterator it_r = result.first;
+         it_r != result.second; ++it_r) {
+        it_r->second.get_model()->post_event(
+            t, common::ExternalEvent(it_r->second,
+                                     event.get_content()));
+    }
+}
+
 } } // namespace paradevs pdevs

+ 8 - 4
src/pdevs/GraphManager.hpp

@@ -40,12 +40,16 @@ public:
     virtual ~GraphManager();
 
     virtual void add_child(common::Model* child);
-    virtual void add_link(common::Model* out_model, const std::string& out_port_name,
-                          common::Model* in_model, const std::string& in_port_name);
+    virtual void add_link(common::Model* out_model,
+                          const std::string& out_port_name,
+                          common::Model* in_model,
+                          const std::string& in_port_name);
     const common::Models& children() const
     { return _child_list; }
-    const common::Links& links() const
-    { return _link_list; }
+
+    void dispatch_events(common::Bag bag, common::Time t);
+
+    void post_event(common::Time t, const common::ExternalEvent& event);
 
 private:
     common::Links        _link_list;