|
From: <ma...@us...> - 2011-02-17 18:01:04
|
Revision: 1041
http://scstudio.svn.sourceforge.net/scstudio/?rev=1041&view=rev
Author: madzin
Date: 2011-02-17 18:00:58 +0000 (Thu, 17 Feb 2011)
Log Message:
-----------
Fix bug in message addition.
Modified Paths:
--------------
trunk/src/membership/diff_impl.cpp
trunk/src/membership/diff_impl.h
trunk/tests/diff/CMakeLists.txt
Modified: trunk/src/membership/diff_impl.cpp
===================================================================
--- trunk/src/membership/diff_impl.cpp 2011-02-15 17:34:51 UTC (rev 1040)
+++ trunk/src/membership/diff_impl.cpp 2011-02-17 18:00:58 UTC (rev 1041)
@@ -102,8 +102,8 @@
StrictOrderAreaPtr a_soa = boost::dynamic_pointer_cast<StrictOrderArea > (a_area);
StrictOrderAreaPtr b_soa = boost::dynamic_pointer_cast<StrictOrderArea > (b_area);
- StrictEventPtr event_a = a_soa->get_first();
- StrictEventPtr event_b = b_soa->get_first();
+ StrictEventPtr event_a = a_soa!=NULL ? a_soa->get_first() : NULL;
+ StrictEventPtr event_b = b_soa!=NULL ? b_soa->get_first() : NULL;
StrictEventPtr start_a, start_b;
@@ -435,9 +435,13 @@
EventAreaPtr e_a = (*instances_it)->get_first();
if(e_a == NULL)
- throw std::runtime_error("Error: unexpected behaviour");
-
- s_e_a = boost::dynamic_pointer_cast<StrictOrderArea> (e_a);
+ {
+ s_e_a = new StrictOrderArea();
+ s_e_a->set_instance(instances_it->get());
+ (*instances_it)->set_first(s_e_a);
+ }
+ else
+ s_e_a = boost::dynamic_pointer_cast<StrictOrderArea> (e_a);
}
if(s_e_a == NULL)
@@ -497,6 +501,11 @@
/*
* create new event and incomplete message
* then add it to the proper ordering
+ *
+ * parameters - bmsc
+ * - diff, difference to process
+ * - msg, original message which is supposed to add
+ * - ins_name
*/
void add_incomplete_message(BMscPtr dup_flow, Difference* diff, IncompleteMessagePtr msg, std::wstring ins_name)
{
@@ -574,6 +583,30 @@
predecessor2->set_successor(new_e2);
}
+StrictEventPtr create_event(BMscPtr dup_flow, Difference* diff, std::wstring inst_name)
+{
+ StrictEventPtr predecessor = diff->getLocation();
+ StrictOrderAreaPtr strict_e_a;
+
+ if(predecessor == NULL)
+ strict_e_a = get_proper_area(dup_flow, diff, inst_name);
+ else
+ strict_e_a = predecessor->get_area();
+
+ StrictEventPtr new_e = new StrictEvent();
+ set_event_position(new_e, diff, inst_name, dup_flow);
+
+ new_e->set_area(strict_e_a.get());
+ new_e->set_marked(ADDED);
+
+ if(predecessor == NULL)
+ strict_e_a->set_first(new_e);
+ else
+ predecessor->set_successor(new_e);
+
+ return new_e;
+}
+
void process_diffrences(BMscPtr dup_flow, const std::map<std::wstring, Difference*>& diff_map)
{
std::map<std::wstring, Difference*>::const_iterator it;
@@ -604,8 +637,10 @@
insert_map.insert(std::make_pair(it->first, insert_list));
}
- std::set<Difference*> recently_processed;
std::map<std::wstring, std::list<Difference*> >::iterator ins_map_it;
+ std::map<std::wstring, std::set<Unmatched*> > unmatched_map;
+ std::map<std::wstring, std::set<Unmatched*> >::iterator unmatched_map_it;
+
for (ins_map_it = insert_map.begin(); ins_map_it != insert_map.end(); ins_map_it++)
{
std::list<Difference*> insert_list = ins_map_it->second;
@@ -613,9 +648,6 @@
for (ins_list_it = insert_list.begin(); ins_list_it != insert_list.end(); ins_list_it++)
{
- if(recently_processed.find(*ins_list_it) != recently_processed.end())
- continue;
-
MscMessagePtr message = (*ins_list_it)->getMessage();
CompleteMessagePtr com_msg = boost::dynamic_pointer_cast<CompleteMessage> (message);
@@ -627,30 +659,70 @@
continue;
}
- std::wstring match_inst;
+ unmatched_map_it = unmatched_map.find(ins_map_it->first);
- if ((*ins_list_it)->getDirection() == SEND)
- match_inst = com_msg->get_receiver()->get_label();
- else
- match_inst = com_msg->get_sender()->get_label();
+ //create new record in unmatched_map
+ if(unmatched_map_it == unmatched_map.end())
+ {
+ std::wstring match_inst;
- std::list<Difference*> match_insert_list = insert_map.find(match_inst)->second;
- std::list<Difference*>::iterator match_ins_list_it;
- Difference* match_diff;
+ if ((*ins_list_it)->getDirection() == SEND)
+ match_inst = com_msg->get_receiver()->get_label();
+ else
+ match_inst = com_msg->get_sender()->get_label();
+
+ //create new event and add it as unmatched
+ StrictEventPtr new_e = create_event(dup_flow, *ins_list_it, ins_map_it->first);
+ Unmatched* unmatched = new Unmatched(new_e, message);
- for (match_ins_list_it = match_insert_list.begin();
- match_ins_list_it != match_insert_list.end();
- match_ins_list_it++)
+ std::map<std::wstring, std::set<Unmatched*> >::iterator match_it = unmatched_map.find(match_inst);
+
+ if(match_it == unmatched_map.end())
+ {
+ std::set<Unmatched*> unmatched_set;
+ unmatched_set.insert(unmatched);
+ unmatched_map.insert(std::make_pair(match_inst, unmatched_set));
+ }
+ else
+ match_it->second.insert(unmatched);
+ continue;
+ }
+
+ bool was_created = false;
+ std::set<Unmatched*> unmatched_set = unmatched_map_it->second;
+ std::set<Unmatched*>::iterator unmatched_set_it;
+
+ for(unmatched_set_it = unmatched_set.begin(); unmatched_set_it != unmatched_set.end(); unmatched_set_it++)
{
- if ((*match_ins_list_it)->getMessage() == message)
+ if(com_msg == (*unmatched_set_it)->getMessage())
{
- match_diff = *match_ins_list_it;
- break;
+ StrictEventPtr new_e = create_event(dup_flow, *ins_list_it, ins_map_it->first);
+
+ CompleteMessagePtr new_msg = new CompleteMessage(message->get_label());
+ new_msg->set_marked(ADDED);
+
+ if((*ins_list_it)->getDirection() == SEND)
+ new_msg->glue_events(new_e, (*unmatched_set_it)->getEvent());
+ else
+ new_msg->glue_events((*unmatched_set_it)->getEvent(), new_e);
+
+ was_created = true;
}
}
- recently_processed.insert(match_diff);
- add_complete_message(dup_flow, *ins_list_it, match_diff, com_msg, ins_map_it->first, match_inst);
+ if(!was_created)
+ {
+ std::wstring match_inst;
+
+ if ((*ins_list_it)->getDirection() == SEND)
+ match_inst = com_msg->get_receiver()->get_label();
+ else
+ match_inst = com_msg->get_sender()->get_label();
+
+ StrictEventPtr new_e = create_event(dup_flow, *ins_list_it, ins_map_it->first);
+ Unmatched* unmatched = new Unmatched(new_e, message);
+ unmatched_map_it->second.insert(unmatched);
+ }
}
}
}
Modified: trunk/src/membership/diff_impl.h
===================================================================
--- trunk/src/membership/diff_impl.h 2011-02-15 17:34:51 UTC (rev 1040)
+++ trunk/src/membership/diff_impl.h 2011-02-17 18:00:58 UTC (rev 1041)
@@ -57,6 +57,30 @@
}
};
+class Unmatched
+{
+private:
+ StrictEventPtr event;
+ MscMessagePtr original_message;
+
+public:
+ Unmatched(StrictEventPtr e, MscMessagePtr m)
+ {
+ event = e;
+ original_message = m;
+ }
+
+ StrictEventPtr getEvent()
+ {
+ return event;
+ }
+
+ MscMessagePtr getMessage()
+ {
+ return original_message;
+ }
+};
+
class Difference
{
private:
Modified: trunk/tests/diff/CMakeLists.txt
===================================================================
--- trunk/tests/diff/CMakeLists.txt 2011-02-15 17:34:51 UTC (rev 1040)
+++ trunk/tests/diff/CMakeLists.txt 2011-02-17 18:00:58 UTC (rev 1041)
@@ -27,4 +27,6 @@
ADD_DIFF_TEST(spec04.mpr flow04_2.mpr 1)
ADD_DIFF_TEST(spec04.mpr flow04_3.mpr 1)
ADD_DIFF_TEST(spec04.mpr flow04_4.mpr 1)
+ADD_DIFF_TEST(spec05.mpr flow05_1.mpr 1)
+ADD_DIFF_TEST(spec06.mpr flow06_1.mpr 1)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|