-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathseda.cpp
More file actions
48 lines (43 loc) · 1.47 KB
/
Copy pathseda.cpp
File metadata and controls
48 lines (43 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "seda.h"
#include "log.h"
stage *SEDA::create_stage(string stage_name) {
stage *sg = new stage(stage_name);
map<string, stage *>::iterator it = stages.find(stage_name);
if (it != stages.end()) {
LogUtil::debug("The stage : %s is already existed", stage_name.c_str());
return NULL;
}
stages[stage_name] = sg;
stages_v.push_back(sg);
return sg;
}
bool SEDA::add_msg_edge(stage *from, stage *to, string msg) {
stage_message *sm = new stage_message(msg);
if (msgExist2Stages(from, to, sm)) {
LogUtil::debug("The msg : %s is already exsited from the stage : %s to stage : %s", msg.c_str(), from->get_stage_name().c_str(), to->get_stage_name().c_str());
return false;
}
addSM(from, to, sm);
return true;
}
bool SEDA::msgExist2Stages(stage *from, stage *to, stage_message *sm) {
map<stage_message *, pair<stage *, stage *> >::iterator it = msg_relat.find(sm);
if (it != msg_relat.end()) {
if ((it->second.first == from) && it->second.second == to) {
return false;
}
}
return true;
}
void SEDA::addSM(stage *from, stage *to, stage_message *sm) {
msg_relat.insert(pair<stage_message *, pair<stage *, stage *> >(sm, pair<stage *, stage *>(from, to)));
}
bool SEDA::run() {
for (size_t i = 0; i < stages_v.size(); ++i) {
if (!stages_v[i]->run()) {
LogUtil::debug("stage : %s run fail", stages_v[i]->get_stage_name().c_str());
return false;
}
}
return true;
}