Repository navigation
Expand file tree
/
Copy pathIPCMsgModule.cpp
More file actions
148 lines (121 loc) · 3.5 KB
/
Copy pathIPCMsgModule.cpp
File metadata and controls
148 lines (121 loc) · 3.5 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "IPCMsgModule.h"
#include "SysVMsgQueue.h"
#include "../../config/node_list.h"
#include "../../util/StringHelper.h"
using namespace dispatch::config::filter;
namespace dispatch { namespace module { namespace ipcmsg {
_ListenerSpec::_ListenerSpec(key_t k, int t, int c, NodeIdent id) :
key(k),
type(t),
count(c),
ident(id) {
}
//IPCMsgModule::IPCMsgModule();
string IPCMsgModule::getModuleName() {
return "IPCMsgSource";
}
bool IPCMsgModule::isEventSource() {
return true;
}
bool IPCMsgModule::isEventHandler() {
return false;
}
IPCMsgModule::~IPCMsgModule() {
vector<IPCMsgListener*>::iterator l_it;
for(l_it = listeners.begin(); l_it != listeners.end(); l_it++) {
delete (*l_it);
}
}
bool IPCMsgModule::shutdown() {
vector<IPCMsgListener*>::iterator l_it;
bool retval = false;
for(l_it = listeners.begin(); l_it != listeners.end(); l_it++) {
(*l_it)->stop();
retval = true;
}
return retval;
}
bool IPCMsgModule::startup() {
vector<IPCMsgListener*>::iterator l_it;
bool retval = false;
for(l_it = listeners.begin(); l_it != listeners.end(); l_it++) {
out() << "Starter opp ipc-lytter " << endl;
(*l_it)->start();
retval = true;
}
return retval;
}
bool IPCMsgModule::preInitialize() {
vector<_ListenerSpec*>::iterator it;
for(it = specs.begin(); it < specs.end(); it++) {
initializeListeners((*it)->key, (*it)->type, (*it)->count, (*it)->ident);
}
return true;
}
bool IPCMsgModule::scanConfigNode(GConfigNode* node) {
vector<string> keys = StringVariableHelper::getStrings(node, "key", 1);
vector<string> types = StringVariableHelper::getStrings(node, "type", 1);
string count_str = StringVariableHelper::getString(node, "threads", 1, true);
NodeIdent ident = node->getFullNodeIdent();
int count = 1;
if (count_str.length()) {
count = string_conv<int>(count_str);
if (count < 1) {
err() << "Thread count was less than 1, setting it to 1" << endl;
count = 1;
}
}
vector<string>::iterator key_it;
vector<string>::iterator type_it;
bool retval = false;
for(key_it = keys.begin(); key_it != keys.end(); key_it++) {
int key = string_conv<int>(*key_it);
if (!key) {
err() << "Key " << *key_it << " is illegal" << endl;
continue;
}
if (types.size()) {
for(type_it = types.begin(); type_it != types.end(); type_it++) {
long type = string_conv<long>(*type_it);
if (type) {
specs.push_back(new _ListenerSpec(key, type, count, ident));
// initializeListeners(key, type, count);
retval = true;
} else {
err() << "Type " << *type_it << " is illegal" << endl;
}
}
} else {
specs.push_back(new _ListenerSpec(key, 0, count, ident));
// initializeListeners(key, 0, count);
retval = true;
}
}
return retval;
}
void IPCMsgModule::initializeListeners(key_t key, long type, int count, NodeIdent& ident) {
out() << "Initaliserer " << count << " ipc-lyttere med key " << key << " og type " << type << endl;
for(int i = 0; i < count; i++) {
if (type) {
listeners.push_back(new IPCMsgListener(
new StreamEventQueueProvidingHandler(this, ident),
new SysVMsgQueue<IPCMsg>(key)
));
} else {
listeners.push_back(new IPCMsgListener(
new StreamEventQueueProvidingHandler(this, ident),
new SysVMsgQueue<IPCMsg>(key),
type
));
}
}
}
}}} // end namespace
extern "C" {
extern dispatch::module::DispatchModule* initialize_dispatch_module() {
return new dispatch::module::ipcmsg::IPCMsgModule();
}
extern void destroy_dispatch_module(dispatch::module::DispatchModule* ptr) {
delete ptr;
}
}