|
@@ -39,8 +39,9 @@ Coordinator::Coordinator(const std::string& name) : common::Coordinator(name)
|
|
|
|
|
|
Coordinator::~Coordinator()
|
|
Coordinator::~Coordinator()
|
|
{
|
|
{
|
|
- for (unsigned int i = 0; i < _child_list.size(); i++)
|
|
|
|
- { delete _child_list[i]; }
|
|
|
|
|
|
+ for (auto & child : _child_list) {
|
|
|
|
+ delete child;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
common::Time Coordinator::start(common::Time t)
|
|
common::Time Coordinator::start(common::Time t)
|
|
@@ -135,41 +136,17 @@ common::Time Coordinator::transition(common::Time t)
|
|
|
|
|
|
common::Models receivers = _event_table.get_current_models(t);
|
|
common::Models receivers = _event_table.get_current_models(t);
|
|
|
|
|
|
- for (common::Models::const_iterator it = _child_list.begin();
|
|
|
|
- it != _child_list.end(); ++it) {
|
|
|
|
- Model* model = dynamic_cast < Model* >(*it);
|
|
|
|
-
|
|
|
|
- if (model->event_number() > 0) {
|
|
|
|
- common::Models::const_iterator itm = std::find(receivers.begin(),
|
|
|
|
- receivers.end(),
|
|
|
|
- model);
|
|
|
|
- if (itm == receivers.end()) {
|
|
|
|
- receivers.push_back(model);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ add_models_with_inputs(receivers);
|
|
|
|
|
|
common::Trace::trace() << common::TraceElement(get_name(), t,
|
|
common::Trace::trace() << common::TraceElement(get_name(), t,
|
|
common::S_MESSAGE)
|
|
common::S_MESSAGE)
|
|
<< ": receivers = " << receivers.to_string();
|
|
<< ": receivers = " << receivers.to_string();
|
|
common::Trace::trace().flush();
|
|
common::Trace::trace().flush();
|
|
|
|
|
|
- for (common::Models::const_iterator it = receivers.begin();
|
|
|
|
- it != receivers.end(); ++it) {
|
|
|
|
- common::Time tn = (*it)->transition(t);
|
|
|
|
-
|
|
|
|
- _event_table.put(tn, *it);
|
|
|
|
|
|
+ for (auto & model : receivers) {
|
|
|
|
+ _event_table.put(model->transition(t), model);
|
|
}
|
|
}
|
|
-
|
|
|
|
- for (common::Models::const_iterator it = _child_list.begin();
|
|
|
|
- it != _child_list.end(); ++it) {
|
|
|
|
- Model* model = dynamic_cast < Model* >(*it);
|
|
|
|
-
|
|
|
|
- if (model->event_number() > 0) {
|
|
|
|
- _event_table.put(t, model);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ update_event_table(t);
|
|
_tl = t;
|
|
_tl = t;
|
|
_tn = _event_table.get_current_time();
|
|
_tn = _event_table.get_current_time();
|
|
clear_bag();
|
|
clear_bag();
|
|
@@ -184,42 +161,31 @@ common::Time Coordinator::transition(common::Time t)
|
|
return _tn;
|
|
return _tn;
|
|
}
|
|
}
|
|
|
|
|
|
-void Coordinator::post_message(common::Time t,
|
|
|
|
- const common::ExternalEvent& message)
|
|
|
|
|
|
+void Coordinator::post_event(common::Time t,
|
|
|
|
+ const common::ExternalEvent& event)
|
|
{
|
|
{
|
|
|
|
|
|
common::Trace::trace() << common::TraceElement(get_name(), t,
|
|
common::Trace::trace() << common::TraceElement(get_name(), t,
|
|
- common::POST_MESSAGE)
|
|
|
|
- << ": BEFORE => " << message.to_string();
|
|
|
|
|
|
+ common::POST_EVENT)
|
|
|
|
+ << ": BEFORE => " << event.to_string();
|
|
common::Trace::trace().flush();
|
|
common::Trace::trace().flush();
|
|
|
|
|
|
- add_event(message);
|
|
|
|
|
|
+ add_event(event);
|
|
|
|
|
|
- std::pair < common::Links::iterator, common::Links::iterator > result =
|
|
|
|
- _link_list.equal_range(common::Node(message.get_port_name(), this));
|
|
|
|
|
|
+ common::Links::Result result =
|
|
|
|
+ _link_list.find(this, event.get_port_name());
|
|
|
|
|
|
for (common::Links::iterator it_r = result.first;
|
|
for (common::Links::iterator it_r = result.first;
|
|
it_r != result.second; ++it_r) {
|
|
it_r != result.second; ++it_r) {
|
|
- Model* model = dynamic_cast < Model* >((*it_r).second.get_model());
|
|
|
|
-
|
|
|
|
- model->post_message(t,
|
|
|
|
- common::ExternalEvent(it_r->second.get_port_name(),
|
|
|
|
- model,
|
|
|
|
- message.get_content()));
|
|
|
|
- }
|
|
|
|
- for (common::Models::const_iterator it = _child_list.begin();
|
|
|
|
- it != _child_list.end(); ++it) {
|
|
|
|
- Model* model = dynamic_cast < Model* >(*it);
|
|
|
|
-
|
|
|
|
- if (model->event_number() > 0) {
|
|
|
|
- _event_table.put(t, model);
|
|
|
|
- }
|
|
|
|
|
|
+ it_r->second.get_model()->post_event(
|
|
|
|
+ t, common::ExternalEvent(it_r->second, event.get_content()));
|
|
}
|
|
}
|
|
|
|
+ update_event_table(t);
|
|
_tn = _event_table.get_current_time();
|
|
_tn = _event_table.get_current_time();
|
|
|
|
|
|
common::Trace::trace() << common::TraceElement(get_name(), t,
|
|
common::Trace::trace() << common::TraceElement(get_name(), t,
|
|
- common::POST_MESSAGE)
|
|
|
|
- << ": AFTER => " << message.to_string();
|
|
|
|
|
|
+ common::POST_EVENT)
|
|
|
|
+ << ": AFTER => " << event.to_string();
|
|
common::Trace::trace().flush();
|
|
common::Trace::trace().flush();
|
|
|
|
|
|
}
|
|
}
|
|
@@ -238,10 +204,8 @@ common::Time Coordinator::dispatch_events(common::Bag bag, common::Time t)
|
|
common::Trace::trace().flush();
|
|
common::Trace::trace().flush();
|
|
|
|
|
|
for (auto & ymsg : bag) {
|
|
for (auto & ymsg : bag) {
|
|
- std::pair < common::Links::iterator ,
|
|
|
|
- common::Links::iterator > result_model =
|
|
|
|
- _link_list.equal_range(common::Node(ymsg.get_port_name(),
|
|
|
|
- ymsg.get_model()));
|
|
|
|
|
|
+ common::Links::Result result_model =
|
|
|
|
+ _link_list.find(ymsg.get_model(), ymsg.get_port_name());
|
|
|
|
|
|
for (common::Links::iterator it = result_model.first;
|
|
for (common::Links::iterator it = result_model.first;
|
|
it != result_model.second; ++it) {
|
|
it != result_model.second; ++it) {
|
|
@@ -250,18 +214,13 @@ common::Time Coordinator::dispatch_events(common::Bag bag, common::Time t)
|
|
common::Bag ymessages;
|
|
common::Bag ymessages;
|
|
|
|
|
|
ymessages.push_back(
|
|
ymessages.push_back(
|
|
- common::ExternalEvent(it->second.get_port_name(),
|
|
|
|
- it->second.get_model(),
|
|
|
|
- ymsg.get_content()));
|
|
|
|
|
|
+ common::ExternalEvent(it->second, ymsg.get_content()));
|
|
dynamic_cast < Coordinator* >(get_parent())->dispatch_events(
|
|
dynamic_cast < Coordinator* >(get_parent())->dispatch_events(
|
|
ymessages, t);
|
|
ymessages, t);
|
|
} else { // event on input port of internal model
|
|
} else { // event on input port of internal model
|
|
- Model* model = dynamic_cast < Model* >(
|
|
|
|
- it->second.get_model());
|
|
|
|
- common::ExternalEvent message(it->second.get_port_name(),
|
|
|
|
- model, ymsg.get_content());
|
|
|
|
-
|
|
|
|
- model->post_message(t, message);
|
|
|
|
|
|
+ it->second.get_model()->post_event(
|
|
|
|
+ t, common::ExternalEvent(it->second,
|
|
|
|
+ ymsg.get_content()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -277,8 +236,8 @@ common::Time Coordinator::dispatch_events(common::Bag bag, common::Time t)
|
|
|
|
|
|
void Coordinator::observation(std::ostream& file) const
|
|
void Coordinator::observation(std::ostream& file) const
|
|
{
|
|
{
|
|
- for (unsigned i = 0; i < _child_list.size(); i++) {
|
|
|
|
- _child_list[i]->observation(file);
|
|
|
|
|
|
+ for (auto & child : _child_list) {
|
|
|
|
+ child->observation(file);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -288,9 +247,31 @@ void Coordinator::add_child(Model* child)
|
|
child->set_parent(this);
|
|
child->set_parent(this);
|
|
}
|
|
}
|
|
|
|
|
|
-void Coordinator::add_link(const common::Node& source,
|
|
|
|
- const common::Node& destination)
|
|
|
|
-{ _link_list.insert(std::pair < common::Node, common::Node >(source,
|
|
|
|
- destination)); }
|
|
|
|
|
|
+void Coordinator::add_link(Model* out_model, const std::string& out_port_name,
|
|
|
|
+ Model* in_model, const std::string& in_port_name)
|
|
|
|
+{
|
|
|
|
+ _link_list.add(out_model, out_port_name, in_model, in_port_name);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Coordinator::add_models_with_inputs(common::Models& receivers)
|
|
|
|
+{
|
|
|
|
+ for (auto & model : _child_list) {
|
|
|
|
+ if (model->event_number() > 0) {
|
|
|
|
+ if (std::find(receivers.begin(), receivers.end(), model) ==
|
|
|
|
+ receivers.end()) {
|
|
|
|
+ receivers.push_back(model);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Coordinator::update_event_table(common::Time t)
|
|
|
|
+{
|
|
|
|
+ for (auto & model : _child_list) {
|
|
|
|
+ if (model->event_number() > 0) {
|
|
|
|
+ _event_table.put(t, model);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
} } // namespace paradevs pdevs
|
|
} } // namespace paradevs pdevs
|