Rev 1887 | Rev 1916 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1887 | Rev 1914 | ||
|---|---|---|---|
| 1 | /* |
1 | /* |
| 2 | * |
2 | * |
| 3 | * Copyright (C) 2010 Mattias Runge |
3 | * Copyright (C) 2010 Mattias Runge |
| 4 | * |
4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
8 | * (at your option) any later version. |
| 9 | * |
9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
13 | * GNU General Public License for more details. |
| 14 | * |
14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
18 | * |
| 19 | */ |
19 | */ |
| 20 | 20 | ||
| 21 | #include "Manager.h" |
21 | #include "Manager.h" |
| 22 | 22 | ||
| 23 | #include <boost/lexical_cast.hpp> |
23 | #include <boost/lexical_cast.hpp> |
| 24 | 24 | ||
| 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 | 30 | ||
| 31 | #include "can/Message.h" |
31 | #include "can/Message.h" |
| - | 32 | #include "can/CanDaemon.cpp" |
|
| 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 | ||
| 38 | Manager::Manager() : broker::Subscriber(false), LOG("control::Manager") |
39 | Manager::Manager() : broker::Subscriber(false), LOG("control::Manager") |
| 39 | { |
40 | { |
| 40 | Node::SetupStateMachine(); |
41 | Node::SetupStateMachine(); |
| 41 | 42 | ||
| 42 | this->active_programming_node_id_ = ""; |
43 | this->active_programming_node_id_ = ""; |
| 43 | 44 | ||
| 44 | // Nyquist–Shannon sampling theorem state that we need to double the time, modules send every 10 seconds |
45 | // 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); |
46 | this->timer_id_ = timer::Manager::Instance()->SetTimer(20000, true); |
| 46 | } |
47 | } |
| 47 | 48 | ||
| 48 | Manager::~Manager() |
49 | Manager::~Manager() |
| 49 | { |
50 | { |
| 50 | } |
51 | } |
| 51 | 52 | ||
| 52 | Manager::Pointer Manager::Instance() |
53 | Manager::Pointer Manager::Instance() |
| 53 | { |
54 | { |
| 54 | return Manager::instance_; |
55 | return Manager::instance_; |
| 55 | } |
56 | } |
| 56 | 57 | ||
| 57 | void Manager::Create() |
58 | void Manager::Create() |
| 58 | { |
59 | { |
| 59 | Manager::instance_ = Manager::Pointer(new Manager()); |
60 | Manager::instance_ = Manager::Pointer(new Manager()); |
| 60 | } |
61 | } |
| 61 | 62 | ||
| 62 | void Manager::Delete() |
63 | void Manager::Delete() |
| 63 | { |
64 | { |
| 64 | Manager::instance_.reset(); |
65 | Manager::instance_.reset(); |
| 65 | } |
66 | } |
| 66 | 67 | ||
| 67 | void Manager::ConnectSlotNode(const SignalOnNodeChange::slot_type& signal_on_node_change_) |
68 | void Manager::ConnectSlotNode(const SignalOnNodeChange::slot_type& signal_on_node_change_) |
| 68 | { |
69 | { |
| 69 | this->signal_on_node_change_.connect(signal_on_node_change_); |
70 | this->signal_on_node_change_.connect(signal_on_node_change_); |
| 70 | } |
71 | } |
| 71 | 72 | ||
| 72 | void Manager::ConnectSlotModule(const SignalOnModuleChange::slot_type& slot_on_module_change) |
73 | void Manager::ConnectSlotModule(const SignalOnModuleChange::slot_type& slot_on_module_change) |
| 73 | { |
74 | { |
| 74 | this->signal_on_module_change_.connect(slot_on_module_change); |
75 | this->signal_on_module_change_.connect(slot_on_module_change); |
| 75 | } |
76 | } |
| 76 | 77 | ||
| 77 | void Manager::ConnectSlotModule(const SignalOnModuleMessage::slot_type& slot_on_module_message) |
78 | void Manager::ConnectSlotModule(const SignalOnModuleMessage::slot_type& slot_on_module_message) |
| 78 | { |
79 | { |
| 79 | this->signal_on_module_message_.connect(slot_on_module_message); |
80 | this->signal_on_module_message_.connect(slot_on_module_message); |
| 80 | } |
81 | } |
| 81 | 82 | ||
| 82 | void Manager::SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat) |
83 | void Manager::SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat) |
| 83 | { |
84 | { |
| 84 | if (timer_id != this->timer_id_) |
85 | if (timer_id != this->timer_id_) |
| 85 | { |
86 | { |
| 86 | return; |
87 | return; |
| 87 | } |
88 | } |
| 88 | 89 | ||
| 89 | for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++) |
90 | for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++) |
| 90 | { |
91 | { |
| 91 | if (!it->second->CheckTimeout()) |
92 | if (!it->second->CheckTimeout()) |
| 92 | { |
93 | { |
| 93 | LOG.Info("Node " +it->second->GetId() + " has not sent anything in a long time, setting offline."); |
94 | LOG.Info("Node " +it->second->GetId() + " has not sent anything in a long time, setting offline."); |
| 94 | this->RemoveModules(it->second->GetId()); |
95 | this->RemoveModules(it->second->GetId()); |
| 95 | 96 | ||
| 96 | storage::Manager::Instance()->FlushStore("NodeList"); |
97 | storage::Manager::Instance()->FlushStore("NodeList"); |
| 97 | storage::Manager::Instance()->FlushStore("ModuleList"); |
98 | storage::Manager::Instance()->FlushStore("ModuleList"); |
| 98 | } |
99 | } |
| 99 | } |
100 | } |
| 100 | } |
101 | } |
| 101 | 102 | ||
| 102 | void Manager::SlotOnMessageHandler(broker::Message::Pointer message) |
103 | void Manager::SlotOnMessageHandler(broker::Message::Pointer message) |
| 103 | { |
104 | { |
| 104 | if (message->GetType() == broker::Message::CAN_MESSAGE) |
105 | if (message->GetType() == broker::Message::CAN_MESSAGE) |
| 105 | { |
106 | { |
| 106 | //LOG.Debug("Message received"); |
107 | //LOG.Debug("Message received"); |
| 107 | can::Message* payload = static_cast<can::Message*>(message->GetPayload().get()); |
108 | can::Message* payload = static_cast<can::Message*>(message->GetPayload().get()); |
| 108 | Node::Pointer node; |
109 | Node::Pointer node; |
| 109 | 110 | ||
| 110 | if (payload->GetClassName() == "nmt") |
111 | if (payload->GetClassName() == "nmt") |
| 111 | { |
112 | { |
| 112 | if (payload->GetCommandName() == "Bios_Start") |
113 | if (payload->GetCommandName() == "Bios_Start") |
| 113 | { |
114 | { |
| 114 | node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"]))); |
115 | node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"]))); |
| 115 | node->Trigger(Node::EVENT_BIOS_START, payload->GetVariables()); |
116 | node->Trigger(Node::EVENT_BIOS_START, payload->GetVariables()); |
| 116 | } |
117 | } |
| 117 | else if (payload->GetCommandName() == "App_Start") |
118 | else if (payload->GetCommandName() == "App_Start") |
| 118 | { |
119 | { |
| 119 | node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"]))); |
120 | node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"]))); |
| 120 | node->Trigger(Node::EVENT_APP_START, payload->GetVariables()); |
121 | node->Trigger(Node::EVENT_APP_START, payload->GetVariables()); |
| 121 | } |
122 | } |
| 122 | else if (payload->GetCommandName() == "Heartbeat") |
123 | else if (payload->GetCommandName() == "Heartbeat") |
| 123 | { |
124 | { |
| 124 | node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"]))); |
125 | node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"]))); |
| 125 | node->Trigger(Node::EVENT_HEARTBEAT, payload->GetVariables()); |
126 | node->Trigger(Node::EVENT_HEARTBEAT, payload->GetVariables()); |
| 126 | } |
127 | } |
| 127 | else if (payload->GetCommandName() == "Pgm_Ack") |
128 | else if (payload->GetCommandName() == "Pgm_Ack") |
| 128 | { |
129 | { |
| 129 | node = this->GetNode(this->active_programming_node_id_); |
130 | node = this->GetNode(this->active_programming_node_id_); |
| 130 | node->Trigger(Node::EVENT_PGM_ACK, payload->GetVariables()); |
131 | node->Trigger(Node::EVENT_PGM_ACK, payload->GetVariables()); |
| 131 | } |
132 | } |
| 132 | else if (payload->GetCommandName() == "Pgm_Nack") |
133 | else if (payload->GetCommandName() == "Pgm_Nack") |
| 133 | { |
134 | { |
| 134 | node = this->GetNode(this->active_programming_node_id_); |
135 | node = this->GetNode(this->active_programming_node_id_); |
| 135 | node->Trigger(Node::EVENT_PGM_NACK, payload->GetVariables()); |
136 | node->Trigger(Node::EVENT_PGM_NACK, payload->GetVariables()); |
| 136 | } |
137 | } |
| 137 | } |
138 | } |
| 138 | else if (payload->GetDirectionName() == "From_Owner") |
139 | else if (payload->GetDirectionName() == "From_Owner") |
| 139 | { |
140 | { |
| 140 | Module::Pointer module = this->GetModule(boost::lexical_cast<unsigned int>(payload->GetId()), payload->GetModuleName(), payload->GetClassName()); |
141 | Module::Pointer module = this->GetModule(boost::lexical_cast<unsigned int>(payload->GetId()), payload->GetModuleName(), payload->GetClassName()); |
| 141 | 142 | ||
| 142 | if (payload->GetCommandName() == "List") |
143 | if (payload->GetCommandName() == "List") |
| 143 | { |
144 | { |
| 144 | node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"]))); |
145 | node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"]))); |
| 145 | node->ResetTimeout(); |
146 | node->ResetTimeout(); |
| 146 | 147 | ||
| 147 | module->SetNodeId(node->GetId()); |
148 | module->SetNodeId(node->GetId()); |
| 148 | 149 | ||
| 149 | if (this->GetNumberOfModules(node->GetId()) == boost::lexical_cast<unsigned int>(payload->GetVariables()["NumberOfModules"])) |
150 | if (this->GetNumberOfModules(node->GetId()) == boost::lexical_cast<unsigned int>(payload->GetVariables()["NumberOfModules"])) |
| 150 | { |
151 | { |
| 151 | node->Trigger(Node::EVENT_LIST_DONE, payload->GetVariables()); |
152 | node->Trigger(Node::EVENT_LIST_DONE, payload->GetVariables()); |
| 152 | } |
153 | } |
| 153 | 154 | ||
| 154 | LOG.Info("Module " + module->GetFullId() + " is available on node " + node->GetId() + "."); |
155 | LOG.Info("Module " + module->GetFullId() + " is available on node " + node->GetId() + "."); |
| 155 | this->signal_on_module_change_(module->GetFullId(), true); |
156 | this->signal_on_module_change_(module->GetFullId(), true); |
| 156 | } |
157 | } |
| 157 | else if (module->GetNodeId() != "") |
158 | else if (module->GetNodeId() != "") |
| 158 | { |
159 | { |
| 159 | node = this->GetNode(module->GetNodeId()); |
160 | node = this->GetNode(module->GetNodeId()); |
| 160 | node->ResetTimeout(); |
161 | node->ResetTimeout(); |
| 161 | 162 | ||
| 162 | this->signal_on_module_message_(module->GetFullId(), payload->GetCommandName(), payload->GetVariables()); |
163 | this->signal_on_module_message_(module->GetFullId(), payload->GetCommandName(), payload->GetVariables()); |
| 163 | } |
164 | } |
| 164 | } |
165 | } |
| 165 | } |
166 | } |
| 166 | } |
167 | } |
| 167 | 168 | ||
| 168 | void Manager::SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state) |
169 | void Manager::SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state) |
| 169 | { |
170 | { |
| 170 | if (target_state != Node::STATE_NORM_INITIALIZED) |
171 | if (target_state != Node::STATE_NORM_INITIALIZED) |
| 171 | { |
172 | { |
| 172 | this->RemoveModules(node_id); |
173 | this->RemoveModules(node_id); |
| 173 | } |
174 | } |
| 174 | 175 | ||
| 175 | if (current_state != target_state) |
176 | if (current_state != target_state) |
| 176 | { |
177 | { |
| 177 | this->signal_on_node_change_(node_id, (target_state == Node::STATE_NORM_INITIALIZED || target_state == Node::STATE_NORM_LIST || target_state == Node::STATE_NORM_ONLINE)); |
178 | this->signal_on_node_change_(node_id, (target_state == Node::STATE_NORM_INITIALIZED || target_state == Node::STATE_NORM_LIST || target_state == Node::STATE_NORM_ONLINE)); |
| 178 | } |
179 | } |
| 179 | 180 | ||
| 180 | if (target_state == Node::STATE_BPGM_OFFLINE || target_state == Node::STATE_APGM_OFFLINE) |
181 | if (target_state == Node::STATE_BPGM_OFFLINE || target_state == Node::STATE_APGM_OFFLINE) |
| 181 | { |
182 | { |
| 182 | this->active_programming_node_id_ = node_id; |
183 | this->active_programming_node_id_ = node_id; |
| 183 | } |
184 | } |
| 184 | else if (target_state == Node::STATE_NORM_OFFLINE) |
185 | else if (target_state == Node::STATE_NORM_OFFLINE) |
| 185 | { |
186 | { |
| 186 | this->active_programming_node_id_ = ""; |
187 | this->active_programming_node_id_ = ""; |
| 187 | } |
188 | } |
| 188 | } |
189 | } |
| 189 | 190 | ||
| 190 | void Manager::SendMessageHandler(std::string full_id, std::string command, common::StringMap variables) |
191 | void Manager::SendMessageHandler(std::string full_id, std::string command, common::StringMap variables) |
| 191 | { |
192 | { |
| 192 | ModuleList::iterator it = this->modules_.find(full_id); |
193 | ModuleList::iterator it = this->modules_.find(full_id); |
| 193 | 194 | ||
| 194 | if (it == this->modules_.end()) |
195 | if (it == this->modules_.end()) |
| 195 | { |
196 | { |
| 196 | LOG.Warning("Can not send message to " + full_id + ", it is not available"); |
197 | LOG.Warning("Can not send message to " + full_id + ", it is not available"); |
| 197 | return; |
198 | return; |
| 198 | } |
199 | } |
| 199 | 200 | ||
| 200 | try |
201 | try |
| 201 | { |
202 | { |
| 202 | can::Message* payload = new can::Message(it->second->GetClassName(), "To_Owner", it->second->GetName(), it->second->GetId(), command); |
203 | can::Message* payload = new can::Message(it->second->GetClassName(), "To_Owner", it->second->GetName(), it->second->GetId(), command); |
| 203 | payload->SetVariables(variables); |
204 | payload->SetVariables(variables); |
| 204 | 205 | ||
| 205 | broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this))); |
206 | 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()); |
207 | //LOG.Debug("Command " + command + " sent to " + it->second->GetName()); |
| 207 | } |
208 | } |
| 208 | catch (std::runtime_error& e) |
209 | catch (std::runtime_error& e) |
| 209 | { |
210 | { |
| 210 | LOG.Error("Failed to send message, " + std::string(e.what())); |
211 | LOG.Error("Failed to send message, " + std::string(e.what())); |
| 211 | } |
212 | } |
| 212 | } |
213 | } |
| 213 | 214 | ||
| 214 | void Manager::SendMessage(std::string full_id, std::string command, common::StringMap variables) |
215 | void Manager::SendMessage(std::string full_id, std::string command, common::StringMap variables) |
| 215 | { |
216 | { |
| 216 | this->io_service_.post(boost::bind(&Manager::SendMessageHandler, this, full_id, command, variables)); |
217 | this->io_service_.post(boost::bind(&Manager::SendMessageHandler, this, full_id, command, variables)); |
| 217 | } |
218 | } |
| 218 | 219 | ||
| 219 | common::StringList Manager::GetAvailableModules() |
220 | common::StringList Manager::GetAvailableModules() |
| 220 | { |
221 | { |
| 221 | common::StringList available_modules; |
222 | common::StringList available_modules; |
| 222 | 223 | ||
| 223 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
224 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
| 224 | { |
225 | { |
| 225 | available_modules.push_back(it->first); |
226 | available_modules.push_back(it->first); |
| 226 | } |
227 | } |
| 227 | 228 | ||
| 228 | return available_modules; |
229 | return available_modules; |
| 229 | } |
230 | } |
| 230 | 231 | ||
| 231 | common::StringList Manager::GetAvailableNodes() |
232 | common::StringList Manager::GetAvailableNodes() |
| 232 | { |
233 | { |
| 233 | common::StringList available_nodes; |
234 | common::StringList available_nodes; |
| 234 | 235 | ||
| 235 | for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++) |
236 | for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++) |
| 236 | { |
237 | { |
| 237 | std::string node = it->first; |
238 | std::string node = it->first; |
| 238 | 239 | ||
| 239 | for (ModuleList::iterator it2 = this->modules_.begin(); it2 != this->modules_.end(); it2++) |
240 | for (ModuleList::iterator it2 = this->modules_.begin(); it2 != this->modules_.end(); it2++) |
| 240 | { |
241 | { |
| 241 | if (it2->second->GetNodeId() == it->first) |
242 | if (it2->second->GetNodeId() == it->first) |
| 242 | { |
243 | { |
| 243 | node += "," + it2->first; |
244 | node += "," + it2->first; |
| 244 | } |
245 | } |
| 245 | } |
246 | } |
| 246 | 247 | ||
| 247 | available_nodes.push_back(node); |
248 | available_nodes.push_back(node); |
| 248 | } |
249 | } |
| 249 | 250 | ||
| 250 | return available_nodes; |
251 | return available_nodes; |
| 251 | } |
252 | } |
| 252 | 253 | ||
| 253 | bool Manager::ResetNode(Node::Id node_id) |
254 | bool Manager::ResetNode(Node::Id node_id) |
| 254 | { |
255 | { |
| 255 | NodeList::iterator it = this->nodes_.find(node_id); |
256 | NodeList::iterator it = this->nodes_.find(node_id); |
| 256 | 257 | ||
| 257 | if (it == this->nodes_.end()) |
258 | if (it == this->nodes_.end()) |
| 258 | { |
259 | { |
| 259 | LOG.Error("Could not find node " + node_id); |
260 | LOG.Error("Could not find node " + node_id); |
| 260 | return false; |
261 | return false; |
| 261 | } |
262 | } |
| 262 | 263 | ||
| 263 | it->second->Reset(); |
264 | it->second->Reset(); |
| 264 | return true; |
265 | return true; |
| 265 | } |
266 | } |
| 266 | 267 | ||
| 267 | bool Manager::ProgramNode(Node::Id node_id, bool is_bios, std::string filename) |
268 | bool Manager::ProgramNode(Node::Id node_id, bool is_bios, std::string filename) |
| 268 | { |
269 | { |
| 269 | NodeList::iterator it = this->nodes_.find(node_id); |
270 | NodeList::iterator it = this->nodes_.find(node_id); |
| 270 | 271 | ||
| 271 | if (it == this->nodes_.end()) |
272 | if (it == this->nodes_.end()) |
| 272 | { |
273 | { |
| 273 | LOG.Error("Could not find node " + node_id); |
274 | LOG.Error("Could not find node " + node_id); |
| 274 | return false; |
275 | return false; |
| 275 | } |
276 | } |
| 276 | 277 | ||
| 277 | Code::Pointer code = Code::Pointer(new Code()); |
278 | Code::Pointer code = Code::Pointer(new Code()); |
| 278 | if (!code->LoadIntelHexFile(filename)) |
279 | if (!code->LoadIntelHexFile(filename)) |
| 279 | { |
280 | { |
| 280 | LOG.Error("Failed to parse " + filename); |
281 | LOG.Error("Failed to parse " + filename); |
| 281 | return false; |
282 | return false; |
| 282 | } |
283 | } |
| 283 | 284 | ||
| 284 | if (is_bios) |
285 | if (is_bios) |
| 285 | { |
286 | { |
| 286 | LOG.Debug("is_bios true"); |
287 | LOG.Debug("is_bios true"); |
| 287 | it->second->ProgramBios(code); |
288 | it->second->ProgramBios(code); |
| 288 | } |
289 | } |
| 289 | else |
290 | else |
| 290 | { |
291 | { |
| 291 | LOG.Debug("is_bios false"); |
292 | LOG.Debug("is_bios false"); |
| 292 | it->second->ProgramApplication(code); |
293 | it->second->ProgramApplication(code); |
| 293 | } |
294 | } |
| 294 | 295 | ||
| 295 | return true; |
296 | return true; |
| 296 | } |
297 | } |
| 297 | 298 | ||
| 298 | /* Program node with hexdata as argument */ |
299 | /* Program node with hexdata as argument */ |
| 299 | bool Manager::ProgramNodeHex(Node::Id node_id, bool is_bios, std::string hex_data) |
300 | bool Manager::ProgramNodeHex(Node::Id node_id, bool is_bios, std::string hex_data) |
| 300 | { |
301 | { |
| 301 | NodeList::iterator it = this->nodes_.find(node_id); |
302 | NodeList::iterator it = this->nodes_.find(node_id); |
| 302 | 303 | ||
| 303 | if (it == this->nodes_.end()) |
304 | if (it == this->nodes_.end()) |
| 304 | { |
305 | { |
| 305 | LOG.Error("Could not find node " + node_id); |
306 | LOG.Error("Could not find node " + node_id); |
| 306 | return false; |
307 | return false; |
| 307 | } |
308 | } |
| 308 | 309 | ||
| 309 | Code::Pointer code = Code::Pointer(new Code()); |
310 | Code::Pointer code = Code::Pointer(new Code()); |
| 310 | if (!code->ParseIntelHex(hex_data)) |
311 | if (!code->ParseIntelHex(hex_data)) |
| 311 | { |
312 | { |
| 312 | LOG.Error("Failed to parse hexdata " + hex_data); |
313 | LOG.Error("Failed to parse hexdata " + hex_data); |
| 313 | return false; |
314 | return false; |
| 314 | } |
315 | } |
| 315 | 316 | ||
| 316 | if (is_bios) |
317 | if (is_bios) |
| 317 | { |
318 | { |
| 318 | LOG.Debug("is_bios true"); |
319 | LOG.Debug("is_bios true"); |
| 319 | it->second->ProgramBios(code); |
320 | it->second->ProgramBios(code); |
| 320 | } |
321 | } |
| 321 | else |
322 | else |
| 322 | { |
323 | { |
| 323 | LOG.Debug("is_bios false"); |
324 | LOG.Debug("is_bios false"); |
| 324 | it->second->ProgramApplication(code); |
325 | it->second->ProgramApplication(code); |
| 325 | } |
326 | } |
| 326 | 327 | ||
| 327 | return true; |
328 | return true; |
| 328 | } |
329 | } |
| 329 | 330 | ||
| 330 | Node::Information Manager::GetNodeInformation(Node::Id node_id) |
331 | Node::Information Manager::GetNodeInformation(Node::Id node_id) |
| 331 | { |
332 | { |
| 332 | NodeList::iterator it = this->nodes_.find(node_id); |
333 | NodeList::iterator it = this->nodes_.find(node_id); |
| 333 | 334 | ||
| 334 | if (it == this->nodes_.end()) |
335 | if (it == this->nodes_.end()) |
| 335 | { |
336 | { |
| 336 | throw std::runtime_error("No such node exists, " + node_id); |
337 | throw std::runtime_error("No such node exists, " + node_id); |
| 337 | } |
338 | } |
| 338 | 339 | ||
| 339 | return it->second->GetInformation(); |
340 | return it->second->GetInformation(); |
| 340 | } |
341 | } |
| 341 | 342 | ||
| 342 | Node::Pointer Manager::GetNode(Node::Id node_id) |
343 | Node::Pointer Manager::GetNode(Node::Id node_id) |
| 343 | { |
344 | { |
| 344 | Node::Pointer node; |
345 | Node::Pointer node; |
| 345 | NodeList::iterator it = this->nodes_.find(node_id); |
346 | NodeList::iterator it = this->nodes_.find(node_id); |
| 346 | 347 | ||
| 347 | if (it == this->nodes_.end()) |
348 | if (it == this->nodes_.end()) |
| 348 | { |
349 | { |
| 349 | node = Node::Pointer(new Node(node_id)); |
350 | node = Node::Pointer(new Node(node_id)); |
| 350 | node->ConnectSlots(Node::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, _2, _3).track(this->tracker_)); |
351 | node->ConnectSlots(Node::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, _2, _3).track(this->tracker_)); |
| 351 | this->nodes_[node_id] = node; |
352 | this->nodes_[node_id] = node; |
| 352 | } |
353 | } |
| 353 | else |
354 | else |
| 354 | { |
355 | { |
| 355 | node = it->second; |
356 | node = it->second; |
| 356 | } |
357 | } |
| 357 | 358 | ||
| 358 | return node; |
359 | return node; |
| 359 | } |
360 | } |
| 360 | 361 | ||
| 361 | Module::Pointer Manager::GetModule(Module::Id module_id, std::string module_name, std::string class_name) |
362 | Module::Pointer Manager::GetModule(Module::Id module_id, std::string module_name, std::string class_name) |
| 362 | { |
363 | { |
| 363 | Module::Pointer module; |
364 | Module::Pointer module; |
| 364 | ModuleList::iterator it = this->modules_.find(Module::MakeFullId(module_id, module_name)); |
365 | ModuleList::iterator it = this->modules_.find(Module::MakeFullId(module_id, module_name)); |
| 365 | 366 | ||
| 366 | if (it == this->modules_.end()) |
367 | if (it == this->modules_.end()) |
| 367 | { |
368 | { |
| 368 | module = Module::Pointer(new Module(module_id, module_name, class_name)); |
369 | module = Module::Pointer(new Module(module_id, module_name, class_name)); |
| 369 | this->modules_[module->GetFullId()] = module; |
370 | this->modules_[module->GetFullId()] = module; |
| 370 | } |
371 | } |
| 371 | else |
372 | else |
| 372 | { |
373 | { |
| 373 | module = it->second; |
374 | module = it->second; |
| 374 | } |
375 | } |
| 375 | 376 | ||
| 376 | return module; |
377 | return module; |
| 377 | } |
378 | } |
| 378 | 379 | ||
| 379 | void Manager::RemoveModules(Node::Id node_id) |
380 | void Manager::RemoveModules(Node::Id node_id) |
| 380 | { |
381 | { |
| 381 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
382 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
| 382 | { |
383 | { |
| 383 | if (it->second->GetNodeId() == node_id) |
384 | if (it->second->GetNodeId() == node_id) |
| 384 | { |
385 | { |
| 385 | LOG.Info("Module " + it->second->GetFullId() + " is unavailable."); |
386 | LOG.Info("Module " + it->second->GetFullId() + " is unavailable."); |
| 386 | this->signal_on_module_change_(it->second->GetFullId(), false); |
387 | this->signal_on_module_change_(it->second->GetFullId(), false); |
| 387 | 388 | ||
| 388 | this->modules_.erase(it); |
389 | this->modules_.erase(it); |
| 389 | } |
390 | } |
| 390 | } |
391 | } |
| 391 | } |
392 | } |
| 392 | 393 | ||
| 393 | unsigned int Manager::GetNumberOfModules(Node::Id node_id) |
394 | unsigned int Manager::GetNumberOfModules(Node::Id node_id) |
| 394 | { |
395 | { |
| 395 | unsigned int number_of_modules = 0; |
396 | unsigned int number_of_modules = 0; |
| 396 | 397 | ||
| 397 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
398 | for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++) |
| 398 | { |
399 | { |
| 399 | if (it->second->GetNodeId() == node_id) |
400 | if (it->second->GetNodeId() == node_id) |
| 400 | { |
401 | { |
| 401 | number_of_modules++; |
402 | number_of_modules++; |
| 402 | } |
403 | } |
| 403 | } |
404 | } |
| 404 | 405 | ||
| 405 | return number_of_modules; |
406 | return number_of_modules; |
| 406 | } |
407 | } |
| 407 | 408 | ||
| 408 | }; // namespace control |
409 | }; // namespace control |
| 409 | }; // namespace atom |
410 | }; // namespace atom |
| 410 | 411 | ||