Rev 1916 | Rev 2082 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1916 | Rev 1971 | ||
|---|---|---|---|
| Line 25... | Line 25... | ||
| 25 | #include "broker/Manager.h" |
25 | #include "broker/Manager.h" |
| 26 | #include "broker/Message.h" |
26 | #include "broker/Message.h" |
| 27 | #include "common/common.h" |
27 | #include "common/common.h" |
| 28 | #include "timer/Manager.h" |
28 | #include "timer/Manager.h" |
| 29 | #include "storage/Manager.h" |
29 | #include "storage/Manager.h" |
| - | 30 | #include "common/log.h" |
|
| 30 | 31 | ||
| 31 | #include "can/Message.h" |
32 | #include "can/Message.h" |
| 32 | 33 | ||
| 33 | namespace atom { |
34 | namespace atom { |
| 34 | namespace control { |
35 | namespace control { |
| 35 | 36 | ||
| 36 | Manager::Pointer Manager::instance_; |
37 | Manager::Pointer Manager::instance_; |
| 37 | 38 | ||
| - | 39 | static const std::string log_module_ = "control::manager"; |
|
| - | 40 | ||
| 38 | Manager::Manager() : broker::Subscriber(false |
41 | Manager::Manager() : broker::Subscriber(false) |
| 39 | { |
42 | { |
| - | 43 | LOG_DEBUG_ENTER; |
|
| - | 44 | ||
| 40 | Node::SetupStateMachine(); |
45 | Node::SetupStateMachine(); |
| 41 | 46 | ||
| 42 | this->active_programming_node_id_ = ""; |
47 | this->active_programming_node_id_ = ""; |
| 43 | 48 | ||
| 44 | // Nyquist–Shannon sampling theorem state that we need to double the time, modules send every 10 seconds |
49 | // Nyquist–Shannon sampling theorem state that we need to double the time, modules send every 10 seconds |
| 45 | this->timer_id_ = timer::Manager::Instance()->SetTimer(20000, true); |
50 | this->timer_id_ = timer::Manager::Instance()->SetTimer(20000, true); |
| - | 51 | ||
| - | 52 | LOG_DEBUG_EXIT; |
|
| 46 | } |
53 | } |
| 47 | 54 | ||
| 48 | Manager::~Manager() |
55 | Manager::~Manager() |
| 49 | { |
56 | { |
| - | 57 | LOG_DEBUG_ENTER; |
|
| - | 58 | LOG_DEBUG_EXIT; |
|
| 50 | } |
59 | } |
| 51 | 60 | ||
| 52 | Manager::Pointer Manager::Instance() |
61 | Manager::Pointer Manager::Instance() |
| 53 | { |
62 | { |
| - | 63 | LOG_DEBUG_ENTER; |
|
| - | 64 | LOG_DEBUG_EXIT; |
|
| - | 65 | ||
| 54 | return Manager::instance_; |
66 | return Manager::instance_; |
| 55 | } |
67 | } |
| 56 | 68 | ||
| 57 | void Manager::Create() |
69 | void Manager::Create() |
| 58 | { |
70 | { |
| - | 71 | LOG_DEBUG_ENTER; |
|
| - | 72 | ||
| 59 | Manager::instance_ = Manager::Pointer(new Manager()); |
73 | Manager::instance_ = Manager::Pointer(new Manager()); |
| - | 74 | ||
| - | 75 | LOG_DEBUG_EXIT; |
|
| 60 | } |
76 | } |
| 61 | 77 | ||
| 62 | void Manager::Delete() |
78 | void Manager::Delete() |
| 63 | { |
79 | { |
| - | 80 | LOG_DEBUG_ENTER; |
|
| - | 81 | ||
| 64 | Manager::instance_.reset(); |
82 | Manager::instance_.reset(); |
| - | 83 | ||
| - | 84 | LOG_DEBUG_EXIT; |
|
| 65 | } |
85 | } |
| 66 | 86 | ||
| 67 | void Manager::ConnectSlotNode(const SignalOnNodeChange::slot_type& signal_on_node_change_) |
87 | void Manager::ConnectSlotNode(const SignalOnNodeChange::slot_type& signal_on_node_change_) |
| 68 | { |
88 | { |
| - | 89 | LOG_DEBUG_ENTER; |
|
| - | 90 | ||
| 69 | this->signal_on_node_change_.connect(signal_on_node_change_); |
91 | this->signal_on_node_change_.connect(signal_on_node_change_); |
| - | 92 | ||
| - | 93 | LOG_DEBUG_EXIT; |
|
| 70 | } |
94 | } |
| 71 | 95 | ||
| 72 | void Manager::ConnectSlotModule(const SignalOnModuleChange::slot_type& slot_on_module_change) |
96 | void Manager::ConnectSlotModule(const SignalOnModuleChange::slot_type& slot_on_module_change) |
| 73 | { |
97 | { |
| - | 98 | LOG_DEBUG_ENTER; |
|
| - | 99 | ||
| 74 | this->signal_on_module_change_.connect(slot_on_module_change); |
100 | this->signal_on_module_change_.connect(slot_on_module_change); |
| - | 101 | ||
| - | 102 | LOG_DEBUG_EXIT; |
|
| 75 | } |
103 | } |
| 76 | 104 | ||
| 77 | void Manager::ConnectSlotModule(const SignalOnModuleMessage::slot_type& slot_on_module_message) |
105 | void Manager::ConnectSlotModule(const SignalOnModuleMessage::slot_type& slot_on_module_message) |
| 78 | { |
106 | { |
| - | 107 | LOG_DEBUG_ENTER; |
|
| - | 108 | ||
| 79 | this->signal_on_module_message_.connect(slot_on_module_message); |
109 | this->signal_on_module_message_.connect(slot_on_module_message); |
| - | 110 | ||
| - | 111 | LOG_DEBUG_EXIT; |
|
| 80 | } |
112 | } |
| 81 | 113 | ||
| 82 | void Manager::SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat) |
114 | void Manager::SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat) |
| 83 | { |
115 | { |
| - | 116 | LOG_DEBUG_ENTER; |
|
| - | 117 | ||
| 84 | if (timer_id != this->timer_id_) |
118 | if (timer_id != this->timer_id_) |
| 85 | { |
119 | { |
| 86 | return; |
120 | return; |
| 87 | } |
121 | } |
| 88 | 122 | ||
| 89 | for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++) |
123 | for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++) |
| 90 | { |
124 | { |
| 91 | if (!it->second->CheckTimeout()) |
125 | if (!it->second->CheckTimeout()) |
| 92 | { |
126 | { |
| 93 |
|
127 | log::Info(log_module_, "Node %s has not sent anything in a long time, setting offline.", it->second->GetId().c_str()); |
| - | 128 | ||
| 94 | this->RemoveModules(it->second->GetId()); |
129 | this->RemoveModules(it->second->GetId()); |
| 95 | 130 | ||
| 96 | storage::Manager::Instance()->FlushStore("NodeList"); |
131 | storage::Manager::Instance()->FlushStore("NodeList"); |
| 97 | storage::Manager::Instance()->FlushStore("ModuleList"); |
132 | storage::Manager::Instance()->FlushStore("ModuleList"); |
| 98 | } |
- | |
| 99 | } |
133 | } |
| - | 134 | } |
|
| - | 135 | ||
| - | 136 | LOG_DEBUG_EXIT; |
|
| 100 | } |
137 | } |
| 101 | 138 | ||
| 102 | void Manager::SlotOnMessageHandler(broker::Message::Pointer message) |
139 | void Manager::SlotOnMessageHandler(broker::Message::Pointer message) |
| 103 | { |
140 | { |
| - | 141 | LOG_DEBUG_ENTER; |
|
| - | 142 | ||
| 104 | if (message->GetType() == broker::Message::CAN_MESSAGE) |
143 | if (message->GetType() == broker::Message::CAN_MESSAGE) |
| 105 | { |
144 | { |
| 106 | //LOG.Debug("Message received"); |
145 | //LOG.Debug("Message received"); |
| 107 | can::Message* payload = static_cast<can::Message*>(message->GetPayload().get()); |
146 | can::Message* payload = static_cast<can::Message*>(message->GetPayload().get()); |
| 108 | Node::Pointer node; |
147 | Node::Pointer node; |
| Line 149... | Line 188... | ||
| 149 | if (this->GetNumberOfModules(node->GetId()) == boost::lexical_cast<unsigned int>(payload->GetVariables()["NumberOfModules"])) |
188 | if (this->GetNumberOfModules(node->GetId()) == boost::lexical_cast<unsigned int>(payload->GetVariables()["NumberOfModules"])) |
| 150 | { |
189 | { |
| 151 | node->Trigger(Node::EVENT_LIST_DONE, payload->GetVariables()); |
190 | node->Trigger(Node::EVENT_LIST_DONE, payload->GetVariables()); |
| 152 | } |
191 | } |
| 153 | 192 | ||
| 154 |
|
193 | log::Info(log_module_, "Module %s is available on node %s.", module->GetFullId().c_str(), node->GetId().c_str()); |
| 155 | this->signal_on_module_change_(module->GetFullId(), true); |
194 | this->signal_on_module_change_(module->GetFullId(), true); |
| 156 | } |
195 | } |
| 157 | else if (module->GetNodeId() != "") |
196 | else if (module->GetNodeId() != "") |
| 158 | { |
197 | { |
| 159 | node = this->GetNode(module->GetNodeId()); |
198 | node = this->GetNode(module->GetNodeId()); |
| Line 161... | Line 200... | ||
| 161 | 200 | ||
| 162 | this->signal_on_module_message_(module->GetFullId(), payload->GetCommandName(), payload->GetVariables()); |
201 | this->signal_on_module_message_(module->GetFullId(), payload->GetCommandName(), payload->GetVariables()); |
| 163 | } |
202 | } |
| 164 | } |
203 | } |
| 165 | } |
204 | } |
| - | 205 | ||
| - | 206 | LOG_DEBUG_EXIT; |
|
| 166 | } |
207 | } |
| 167 | 208 | ||
| 168 | void Manager::SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state) |
209 | void Manager::SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state) |
| 169 | { |
210 | { |
| - | 211 | LOG_DEBUG_ENTER; |
|
| - | 212 | ||
| 170 | if (target_state != Node::STATE_NORM_INITIALIZED) |
213 | if (target_state != Node::STATE_NORM_INITIALIZED) |
| 171 | { |
214 | { |
| 172 | this->RemoveModules(node_id); |
215 | this->RemoveModules(node_id); |
| 173 | } |
216 | } |
| 174 | 217 | ||
| Line 183... | Line 226... | ||
| 183 | } |
226 | } |
| 184 | else if (target_state == Node::STATE_NORM_OFFLINE) |
227 | else if (target_state == Node::STATE_NORM_OFFLINE) |
| 185 | { |
228 | { |
| 186 | this->active_programming_node_id_ = ""; |
229 | this->active_programming_node_id_ = ""; |
| 187 | } |
230 | } |
| - | 231 | ||
| - | 232 | LOG_DEBUG_EXIT; |
|
| 188 | } |
233 | } |
| 189 | 234 | ||
| 190 | void Manager::SendMessageHandler(std::string full_id, std::string command, common::StringMap variables) |
235 | void Manager::SendMessageHandler(std::string full_id, std::string command, common::StringMap variables) |
| 191 | { |
236 | { |
| - | 237 | LOG_DEBUG_ENTER; |
|
| - | 238 | ||
| 192 | ModuleList::iterator it = this->modules_.find(full_id); |
239 | ModuleList::iterator it = this->modules_.find(full_id); |
| 193 | 240 | ||
| 194 | if (it == this->modules_.end()) |
241 | if (it == this->modules_.end()) |
| 195 | { |
242 | { |
| 196 |
|
243 | log::Warning(log_module_, "Can not send message to %s , it is not available.", full_id.c_str()); |
| 197 | return; |
244 | return; |
| 198 | } |
245 | } |
| 199 | 246 | ||
| 200 | try |
247 | try |
| 201 | { |
248 | { |
| 202 | can::Message* payload = new can::Message(it->second->GetClassName(), "To_Owner", it->second->GetName(), it->second->GetId(), command); |
249 | can::Message* payload = new can::Message(it->second->GetClassName(), "To_Owner", it->second->GetName(), it->second->GetId(), command); |
| 203 | payload->SetVariables(variables); |
250 | payload->SetVariables(variables); |
| 204 | 251 | ||
| 205 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this))); |
252 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this))); |
| 206 | //LOG.Debug("Command " + command + " sent to " + it->second->GetName()); |
253 | //LOG.Debug("Command " + command + " sent to " + it->second->GetName()); |
| 207 | } |
254 | } |
| 208 | catch (std::runtime_error& e) |
255 | catch (std::runtime_error& e) |
| 209 | { |
256 | { |
| 210 |
|
257 | log::Error(log_module_, "Failed to send message, %s", e.what()); |
| 211 | } |
258 | } |
| - | 259 | ||
| - | 260 | LOG_DEBUG_EXIT; |
|
| 212 | } |
261 | } |
| 213 | 262 | ||
| 214 | void Manager::SendMessage(std::string full_id, std::string command, common::StringMap variables) |
263 | void Manager::SendMessage(std::string full_id, std::string command, common::StringMap variables) |
| 215 | { |
264 | { |
| - | 265 | LOG_DEBUG_ENTER; |
|
| - | 266 | ||
| 216 | this->io_service_.post(boost::bind(&Manager::SendMessageHandler, this, full_id, command, variables)); |
267 | this->io_service_.post(boost::bind(&Manager::SendMessageHandler, this, full_id, command, variables)); |
| - | 268 | ||
| - | 269 | LOG_DEBUG_EXIT; |
|
| 217 | } |
270 | } |
| 218 | 271 | ||
| 219 | common::StringList Manager::GetAvailableModules() |
272 | common::StringList Manager::GetAvailableModules() |
| 220 | { |
273 | { |
| - | 274 | LOG_DEBUG_ENTER; |
|
| - | 275 | ||
| 221 | common::StringList available_modules; |
276 | common::StringList available_modules; |
| 222 | 277 | ||
| 223 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
278 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
| 224 | { |
279 | { |
| 225 | available_modules.push_back(it->first); |
280 | available_modules.push_back(it->first); |
| 226 | } |
281 | } |
| - | 282 | ||
| - | 283 | LOG_DEBUG_EXIT; |
|
| 227 | 284 | ||
| 228 | return available_modules; |
285 | return available_modules; |
| 229 | } |
286 | } |
| 230 | 287 | ||
| 231 | common::StringList Manager::GetAvailableNodes() |
288 | common::StringList Manager::GetAvailableNodes() |
| 232 | { |
289 | { |
| - | 290 | LOG_DEBUG_ENTER; |
|
| - | 291 | ||
| 233 | common::StringList available_nodes; |
292 | common::StringList available_nodes; |
| 234 | 293 | ||
| 235 | for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++) |
294 | for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++) |
| 236 | { |
295 | { |
| 237 | std::string node = it->first; |
296 | std::string node = it->first; |
| 238 | 297 | ||
| 239 | for (ModuleList::iterator it2 = this->modules_.begin(); it2 != this->modules_.end(); it2++) |
298 | for (ModuleList::iterator it2 = this->modules_.begin(); it2 != this->modules_.end(); it2++) |
| 240 | { |
299 | { |
| 241 | if (it2->second->GetNodeId() == it->first) |
300 | if (it2->second->GetNodeId() == it->first) |
| 242 | { |
301 | { |
| 243 | node += "," + it2->first; |
302 | node += "," + it2->first; |
| 244 | } |
303 | } |
| 245 | } |
304 | } |
| 246 | 305 | ||
| 247 | available_nodes.push_back(node); |
306 | available_nodes.push_back(node); |
| 248 | } |
307 | } |
| - | 308 | ||
| - | 309 | LOG_DEBUG_EXIT; |
|
| 249 | 310 | ||
| 250 | return available_nodes; |
311 | return available_nodes; |
| 251 | } |
312 | } |
| 252 | 313 | ||
| 253 | bool Manager::ResetNode(Node::Id node_id) |
314 | bool Manager::ResetNode(Node::Id node_id) |
| 254 | { |
315 | { |
| - | 316 | LOG_DEBUG_ENTER; |
|
| - | 317 | ||
| 255 | NodeList::iterator it = this->nodes_.find(node_id); |
318 | NodeList::iterator it = this->nodes_.find(node_id); |
| 256 | 319 | ||
| 257 | if (it == this->nodes_.end()) |
320 | if (it == this->nodes_.end()) |
| 258 | { |
321 | { |
| 259 |
|
322 | log::Error(log_module_, "Could not find node %s.", node_id.c_str()); |
| 260 | return false; |
323 | return false; |
| 261 | } |
324 | } |
| 262 | 325 | ||
| 263 | it->second->Reset(); |
326 | it->second->Reset(); |
| - | 327 | ||
| - | 328 | LOG_DEBUG_EXIT; |
|
| - | 329 | ||
| 264 | return true; |
330 | return true; |
| 265 | } |
331 | } |
| 266 | 332 | ||
| 267 | bool Manager::ProgramNode(Node::Id node_id, bool is_bios, std::string filename) |
333 | bool Manager::ProgramNode(Node::Id node_id, bool is_bios, std::string filename) |
| 268 | { |
334 | { |
| - | 335 | LOG_DEBUG_ENTER; |
|
| - | 336 | ||
| 269 | NodeList::iterator it = this->nodes_.find(node_id); |
337 | NodeList::iterator it = this->nodes_.find(node_id); |
| 270 | 338 | ||
| 271 | if (it == this->nodes_.end()) |
339 | if (it == this->nodes_.end()) |
| 272 | { |
340 | { |
| 273 |
|
341 | log::Error(log_module_, "Could not find node %s.", node_id.c_str()); |
| 274 | return false; |
342 | return false; |
| 275 | } |
343 | } |
| 276 | 344 | ||
| 277 | Code::Pointer code = Code::Pointer(new Code()); |
345 | Code::Pointer code = Code::Pointer(new Code()); |
| 278 | if (!code->LoadIntelHexFile(filename)) |
346 | if (!code->LoadIntelHexFile(filename)) |
| 279 | { |
347 | { |
| 280 |
|
348 | log::Error(log_module_, "Could not parse %s.", filename.c_str()); |
| 281 | return false; |
349 | return false; |
| 282 | } |
350 | } |
| 283 | 351 | ||
| 284 | if (is_bios) |
352 | if (is_bios) |
| 285 | { |
353 | { |
| 286 |
|
354 | log::Debug(log_module_, "is_bios true"); |
| 287 | it->second->ProgramBios(code); |
355 | it->second->ProgramBios(code); |
| 288 | } |
356 | } |
| 289 | else |
357 | else |
| 290 | { |
358 | { |
| 291 |
|
359 | log::Debug(log_module_, "is_bios false"); |
| 292 | it->second->ProgramApplication(code); |
360 | it->second->ProgramApplication(code); |
| 293 | } |
361 | } |
| - | 362 | ||
| - | 363 | LOG_DEBUG_EXIT; |
|
| 294 | 364 | ||
| 295 | return true; |
365 | return true; |
| 296 | } |
366 | } |
| 297 | 367 | ||
| 298 | /* Program node with hexdata as argument */ |
368 | /* Program node with hexdata as argument */ |
| 299 | bool Manager::ProgramNodeHex(Node::Id node_id, bool is_bios, std::string hex_data) |
369 | bool Manager::ProgramNodeHex(Node::Id node_id, bool is_bios, std::string hex_data) |
| 300 | { |
370 | { |
| - | 371 | LOG_DEBUG_ENTER; |
|
| - | 372 | ||
| 301 | NodeList::iterator it = this->nodes_.find(node_id); |
373 | NodeList::iterator it = this->nodes_.find(node_id); |
| 302 | 374 | ||
| 303 | if (it == this->nodes_.end()) |
375 | if (it == this->nodes_.end()) |
| 304 | { |
376 | { |
| 305 |
|
377 | log::Error(log_module_, "Could not find node %s.", node_id.c_str()); |
| 306 | return false; |
378 | return false; |
| 307 | } |
379 | } |
| 308 | 380 | ||
| 309 | Code::Pointer code = Code::Pointer(new Code()); |
381 | Code::Pointer code = Code::Pointer(new Code()); |
| - | 382 | ||
| 310 | if (!code->ParseIntelHex(hex_data)) |
383 | if (!code->ParseIntelHex(hex_data)) |
| 311 | { |
384 | { |
| 312 |
|
385 | log::Error(log_module_, "Could not parse hexdata %s.", hex_data.c_str()); |
| 313 | return false; |
386 | return false; |
| 314 | } |
387 | } |
| 315 | 388 | ||
| 316 | if (is_bios) |
389 | if (is_bios) |
| 317 | { |
390 | { |
| 318 |
|
391 | log::Debug(log_module_, "is_bios true"); |
| 319 | it->second->ProgramBios(code); |
392 | it->second->ProgramBios(code); |
| 320 | } |
393 | } |
| 321 | else |
394 | else |
| 322 | { |
395 | { |
| 323 |
|
396 | log::Debug(log_module_, "is_bios false"); |
| 324 | it->second->ProgramApplication(code); |
397 | it->second->ProgramApplication(code); |
| 325 | } |
398 | } |
| - | 399 | ||
| - | 400 | LOG_DEBUG_EXIT; |
|
| 326 | 401 | ||
| 327 | return true; |
402 | return true; |
| 328 | } |
403 | } |
| 329 | 404 | ||
| 330 | Node::Information Manager::GetNodeInformation(Node::Id node_id) |
405 | Node::Information Manager::GetNodeInformation(Node::Id node_id) |
| 331 | { |
406 | { |
| - | 407 | LOG_DEBUG_ENTER; |
|
| - | 408 | ||
| 332 | NodeList::iterator it = this->nodes_.find(node_id); |
409 | NodeList::iterator it = this->nodes_.find(node_id); |
| 333 | 410 | ||
| 334 | if (it == this->nodes_.end()) |
411 | if (it == this->nodes_.end()) |
| 335 | { |
412 | { |
| 336 | throw std::runtime_error("No such node exists, " + node_id); |
413 | throw std::runtime_error("No such node exists, " + node_id); |
| 337 | } |
414 | } |
| - | 415 | ||
| - | 416 | LOG_DEBUG_EXIT; |
|
| 338 | 417 | ||
| 339 | return it->second->GetInformation(); |
418 | return it->second->GetInformation(); |
| 340 | } |
419 | } |
| 341 | 420 | ||
| 342 | Node::Pointer Manager::GetNode(Node::Id node_id) |
421 | Node::Pointer Manager::GetNode(Node::Id node_id) |
| 343 | { |
422 | { |
| - | 423 | LOG_DEBUG_ENTER; |
|
| - | 424 | ||
| 344 | Node::Pointer node; |
425 | Node::Pointer node; |
| 345 | NodeList::iterator it = this->nodes_.find(node_id); |
426 | NodeList::iterator it = this->nodes_.find(node_id); |
| 346 | 427 | ||
| 347 | if (it == this->nodes_.end()) |
428 | if (it == this->nodes_.end()) |
| 348 | { |
429 | { |
| 349 | node = Node::Pointer(new Node(node_id)); |
430 | node = Node::Pointer(new Node(node_id)); |
| 350 | node->ConnectSlots(Node::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, _2, _3).track(this->tracker_)); |
431 | node->ConnectSlots(Node::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, _2, _3).track(this->tracker_)); |
| 351 | this->nodes_[node_id] = node; |
432 | this->nodes_[node_id] = node; |
| 352 | } |
433 | } |
| 353 | else |
434 | else |
| 354 | { |
435 | { |
| 355 | node = it->second; |
436 | node = it->second; |
| 356 | } |
437 | } |
| - | 438 | ||
| - | 439 | LOG_DEBUG_EXIT; |
|
| 357 | 440 | ||
| 358 | return node; |
441 | return node; |
| 359 | } |
442 | } |
| 360 | 443 | ||
| 361 | Module::Pointer Manager::GetModule(Module::Id module_id, std::string module_name, std::string class_name) |
444 | Module::Pointer Manager::GetModule(Module::Id module_id, std::string module_name, std::string class_name) |
| 362 | { |
445 | { |
| - | 446 | LOG_DEBUG_ENTER; |
|
| - | 447 | ||
| 363 | Module::Pointer module; |
448 | Module::Pointer module; |
| 364 | ModuleList::iterator it = this->modules_.find(Module::MakeFullId(module_id, module_name)); |
449 | ModuleList::iterator it = this->modules_.find(Module::MakeFullId(module_id, module_name)); |
| 365 | 450 | ||
| 366 | if (it == this->modules_.end()) |
451 | if (it == this->modules_.end()) |
| 367 | { |
452 | { |
| 368 | module = Module::Pointer(new Module(module_id, module_name, class_name)); |
453 | module = Module::Pointer(new Module(module_id, module_name, class_name)); |
| 369 | this->modules_[module->GetFullId()] = module; |
454 | this->modules_[module->GetFullId()] = module; |
| 370 | } |
455 | } |
| 371 | else |
456 | else |
| 372 | { |
457 | { |
| 373 | module = it->second; |
458 | module = it->second; |
| 374 | } |
459 | } |
| - | 460 | ||
| - | 461 | LOG_DEBUG_EXIT; |
|
| 375 | 462 | ||
| 376 | return module; |
463 | return module; |
| 377 | } |
464 | } |
| 378 | 465 | ||
| 379 | void Manager::RemoveModules(Node::Id node_id) |
466 | void Manager::RemoveModules(Node::Id node_id) |
| 380 | { |
467 | { |
| - | 468 | LOG_DEBUG_ENTER; |
|
| - | 469 | ||
| 381 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
470 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
| 382 | { |
471 | { |
| 383 | if (it->second->GetNodeId() == node_id) |
472 | if (it->second->GetNodeId() == node_id) |
| 384 | { |
473 | { |
| 385 |
|
474 | log::Info(log_module_, "Module %s is unavailable.", it->second->GetFullId().c_str()); |
| 386 | this->signal_on_module_change_(it->second->GetFullId(), false); |
475 | this->signal_on_module_change_(it->second->GetFullId(), false); |
| 387 | 476 | ||
| 388 | this->modules_.erase(it); |
477 | this->modules_.erase(it); |
| - | 478 | break; |
|
| 389 | } |
479 | } |
| - | 480 | } |
|
| 390 |
|
481 | |
| - | 482 | LOG_DEBUG_EXIT; |
|
| 391 | } |
483 | } |
| 392 | 484 | ||
| 393 | unsigned int Manager::GetNumberOfModules(Node::Id node_id) |
485 | unsigned int Manager::GetNumberOfModules(Node::Id node_id) |
| 394 | { |
486 | { |
| - | 487 | LOG_DEBUG_ENTER; |
|
| - | 488 | ||
| 395 | unsigned int number_of_modules = 0; |
489 | unsigned int number_of_modules = 0; |
| 396 | 490 | ||
| 397 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
491 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
| 398 | { |
492 | { |
| 399 | if (it->second->GetNodeId() == node_id) |
493 | if (it->second->GetNodeId() == node_id) |
| 400 | { |
494 | { |
| 401 | number_of_modules++; |
495 | number_of_modules++; |
| 402 | } |
496 | } |
| 403 | } |
497 | } |
| - | 498 | ||
| - | 499 | LOG_DEBUG_EXIT; |
|
| 404 | 500 | ||
| 405 | return number_of_modules; |
501 | return number_of_modules; |
| 406 | } |
502 | } |
| 407 | 503 | ||
| 408 | }; // namespace control |
504 | }; // namespace control |