Subversion Repositories HomeAutomation

Rev

Rev 1665 | Rev 1887 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1665 Rev 1666
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
 
32
 
33
namespace atom {
33
namespace atom {
34
namespace control {
34
namespace control {
35
   
35
   
36
Manager::Pointer Manager::instance_;
36
Manager::Pointer Manager::instance_;
37
 
37
 
38
Manager::Manager() : broker::Subscriber(false), LOG("control::Manager")
38
Manager::Manager() : broker::Subscriber(false), LOG("control::Manager")
39
{
39
{
40
    Node::SetupStateMachine();
40
    Node::SetupStateMachine();
41
   
41
   
42
    this->active_programming_node_id_ = "";
42
    this->active_programming_node_id_ = "";
43
   
43
   
44
    // Nyquist–Shannon sampling theorem state that we need to double the time, modules send every 10 seconds
44
    // 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);
45
    this->timer_id_ = timer::Manager::Instance()->SetTimer(20000, true);
46
}
46
}
47
 
47
 
48
Manager::~Manager()
48
Manager::~Manager()
49
{
49
{
50
}
50
}
51
 
51
 
52
Manager::Pointer Manager::Instance()
52
Manager::Pointer Manager::Instance()
53
{
53
{
54
    return Manager::instance_;
54
    return Manager::instance_;
55
}
55
}
56
 
56
 
57
void Manager::Create()
57
void Manager::Create()
58
{
58
{
59
    Manager::instance_ = Manager::Pointer(new Manager());
59
    Manager::instance_ = Manager::Pointer(new Manager());
60
}
60
}
61
 
61
 
62
void Manager::Delete()
62
void Manager::Delete()
63
{
63
{
64
    Manager::instance_.reset();
64
    Manager::instance_.reset();
65
}
65
}
66
 
66
 
67
void Manager::ConnectSlotNode(const SignalOnNodeChange::slot_type& signal_on_node_change_)
67
void Manager::ConnectSlotNode(const SignalOnNodeChange::slot_type& signal_on_node_change_)
68
{
68
{
69
    this->signal_on_node_change_.connect(signal_on_node_change_);
69
    this->signal_on_node_change_.connect(signal_on_node_change_);
70
}
70
}
71
 
71
 
72
void Manager::ConnectSlotModule(const SignalOnModuleChange::slot_type& slot_on_module_change)
72
void Manager::ConnectSlotModule(const SignalOnModuleChange::slot_type& slot_on_module_change)
73
{
73
{
74
    this->signal_on_module_change_.connect(slot_on_module_change);
74
    this->signal_on_module_change_.connect(slot_on_module_change);
75
}
75
}
76
 
76
 
77
void Manager::ConnectSlotModule(const SignalOnModuleMessage::slot_type& slot_on_module_message)
77
void Manager::ConnectSlotModule(const SignalOnModuleMessage::slot_type& slot_on_module_message)
78
{
78
{
79
    this->signal_on_module_message_.connect(slot_on_module_message);
79
    this->signal_on_module_message_.connect(slot_on_module_message);
80
}
80
}
81
 
81
 
82
void Manager::SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat)
82
void Manager::SlotOnTimeoutHandler(timer::TimerId timer_id, bool repeat)
83
{
83
{
84
    if (timer_id != this->timer_id_)
84
    if (timer_id != this->timer_id_)
85
    {
85
    {
86
        return;
86
        return;
87
    }
87
    }
88
   
88
   
89
    for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++)
89
    for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++)
90
    {
90
    {
91
        if (!it->second->CheckTimeout())
91
        if (!it->second->CheckTimeout())
92
        {
92
        {
93
            LOG.Info("Node " +it->second->GetId() + " has not sent anything in a long time, setting offline.");
93
            LOG.Info("Node " +it->second->GetId() + " has not sent anything in a long time, setting offline.");
94
            this->RemoveModules(it->second->GetId());
94
            this->RemoveModules(it->second->GetId());
95
           
95
           
96
            storage::Manager::Instance()->FlushStore("NodeList");
96
            storage::Manager::Instance()->FlushStore("NodeList");
97
            storage::Manager::Instance()->FlushStore("ModuleList");
97
            storage::Manager::Instance()->FlushStore("ModuleList");
98
        }
98
        }
99
    }
99
    }
100
}
100
}
101
 
101
 
102
void Manager::SlotOnMessageHandler(broker::Message::Pointer message)
102
void Manager::SlotOnMessageHandler(broker::Message::Pointer message)
103
{
103
{
104
    if (message->GetType() == broker::Message::CAN_MESSAGE)
104
    if (message->GetType() == broker::Message::CAN_MESSAGE)
105
    {
105
    {
106
        //LOG.Debug("Message received");
106
        //LOG.Debug("Message received");
107
        can::Message* payload = static_cast<can::Message*>(message->GetPayload().get());
107
        can::Message* payload = static_cast<can::Message*>(message->GetPayload().get());
108
        Node::Pointer node;
108
        Node::Pointer node;
109
       
109
       
110
        if (payload->GetClassName() == "nmt")
110
        if (payload->GetClassName() == "nmt")
111
        {
111
        {
112
            if (payload->GetCommandName() == "Bios_Start")
112
            if (payload->GetCommandName() == "Bios_Start")
113
            {
113
            {
114
                node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])));
114
                node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])));
115
                node->Trigger(Node::EVENT_BIOS_START, payload->GetVariables());
115
                node->Trigger(Node::EVENT_BIOS_START, payload->GetVariables());
116
            }
116
            }
117
            else if (payload->GetCommandName() == "App_Start")
117
            else if (payload->GetCommandName() == "App_Start")
118
            {
118
            {
119
                node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])));
119
                node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])));
120
                node->Trigger(Node::EVENT_APP_START, payload->GetVariables());
120
                node->Trigger(Node::EVENT_APP_START, payload->GetVariables());
121
            }
121
            }
122
            else if (payload->GetCommandName() == "Heartbeat")
122
            else if (payload->GetCommandName() == "Heartbeat")
123
            {
123
            {
124
                node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])));
124
                node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])));
125
                node->Trigger(Node::EVENT_HEARTBEAT, payload->GetVariables());
125
                node->Trigger(Node::EVENT_HEARTBEAT, payload->GetVariables());
126
            }
126
            }
127
            else if (payload->GetCommandName() == "Pgm_Ack")
127
            else if (payload->GetCommandName() == "Pgm_Ack")
128
            {
128
            {
129
                node = this->GetNode(this->active_programming_node_id_);
129
                node = this->GetNode(this->active_programming_node_id_);
130
                node->Trigger(Node::EVENT_PGM_ACK, payload->GetVariables());
130
                node->Trigger(Node::EVENT_PGM_ACK, payload->GetVariables());
131
            }
131
            }
132
            else if (payload->GetCommandName() == "Pgm_Nack")
132
            else if (payload->GetCommandName() == "Pgm_Nack")
133
            {
133
            {
134
                node = this->GetNode(this->active_programming_node_id_);
134
                node = this->GetNode(this->active_programming_node_id_);
135
                node->Trigger(Node::EVENT_PGM_NACK, payload->GetVariables());
135
                node->Trigger(Node::EVENT_PGM_NACK, payload->GetVariables());
136
            }
136
            }
137
        }
137
        }
138
        else if (payload->GetDirectionName() == "From_Owner")
138
        else if (payload->GetDirectionName() == "From_Owner")
139
        {
139
        {
140
            Module::Pointer module = this->GetModule(boost::lexical_cast<unsigned int>(payload->GetId()), payload->GetModuleName(), payload->GetClassName());
140
            Module::Pointer module = this->GetModule(boost::lexical_cast<unsigned int>(payload->GetId()), payload->GetModuleName(), payload->GetClassName());
141
           
141
           
142
            if (payload->GetCommandName() == "List")
142
            if (payload->GetCommandName() == "List")
143
            {
143
            {
144
                node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])));
144
                node = this->GetNode(common::ToHex(boost::lexical_cast<unsigned int>(payload->GetVariables()["HardwareId"])));
145
                node->ResetTimeout();
145
                node->ResetTimeout();
146
               
146
               
147
                module->SetNodeId(node->GetId());
147
                module->SetNodeId(node->GetId());
148
               
148
               
149
                if (this->GetNumberOfModules(node->GetId()) == boost::lexical_cast<unsigned int>(payload->GetVariables()["NumberOfModules"]))
149
                if (this->GetNumberOfModules(node->GetId()) == boost::lexical_cast<unsigned int>(payload->GetVariables()["NumberOfModules"]))
150
                {
150
                {
151
                    node->Trigger(Node::EVENT_LIST_DONE, payload->GetVariables());
151
                    node->Trigger(Node::EVENT_LIST_DONE, payload->GetVariables());
152
                }
152
                }
153
               
153
               
154
                LOG.Info("Module " + module->GetFullId() + " is available on node " + node->GetId() + ".");
154
                LOG.Info("Module " + module->GetFullId() + " is available on node " + node->GetId() + ".");
155
                this->signal_on_module_change_(module->GetFullId(), true);
155
                this->signal_on_module_change_(module->GetFullId(), true);
156
            }
156
            }
157
            else if (module->GetNodeId() != "")
157
            else if (module->GetNodeId() != "")
158
            {
158
            {
159
                node = this->GetNode(module->GetNodeId());
159
                node = this->GetNode(module->GetNodeId());
160
                node->ResetTimeout();
160
                node->ResetTimeout();
161
               
161
               
162
                this->signal_on_module_message_(module->GetFullId(), payload->GetCommandName(), payload->GetVariables());
162
                this->signal_on_module_message_(module->GetFullId(), payload->GetCommandName(), payload->GetVariables());
163
            }
163
            }
164
        }
164
        }
165
    }
165
    }
166
}
166
}
167
 
167
 
168
void Manager::SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state)
168
void Manager::SlotOnNewState(Node::Id node_id, Node::State current_state, Node::State target_state)
169
{
169
{
170
    if (target_state != Node::STATE_NORM_INITIALIZED)
170
    if (target_state != Node::STATE_NORM_INITIALIZED)
171
    {
171
    {
172
        this->RemoveModules(node_id);
172
        this->RemoveModules(node_id);
-
 
173
    }
173
 
174
   
174
        if (current_state != target_state)
175
    if (current_state != target_state)
175
        {
176
    {
176
            this->signal_on_node_change_(node_id, false);
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));
177
        }
-
 
178
    }
-
 
179
    else
-
 
180
    {
-
 
181
        if (current_state != target_state)
-
 
182
        {
-
 
183
            this->signal_on_node_change_(node_id, true);
-
 
184
        }
-
 
185
    }
178
    }
186
   
179
   
187
    if (target_state == Node::STATE_BPGM_OFFLINE || target_state == Node::STATE_APGM_OFFLINE)
180
    if (target_state == Node::STATE_BPGM_OFFLINE || target_state == Node::STATE_APGM_OFFLINE)
188
    {
181
    {
189
        this->active_programming_node_id_ = node_id;
182
        this->active_programming_node_id_ = node_id;
190
    }
183
    }
191
    else if (target_state == Node::STATE_NORM_OFFLINE)
184
    else if (target_state == Node::STATE_NORM_OFFLINE)
192
    {
185
    {
193
        this->active_programming_node_id_ = "";
186
        this->active_programming_node_id_ = "";
194
    }
187
    }
195
}
188
}
196
 
189
 
197
void Manager::SendMessageHandler(std::string full_id, std::string command, common::StringMap variables)
190
void Manager::SendMessageHandler(std::string full_id, std::string command, common::StringMap variables)
198
{
191
{
199
    ModuleList::iterator it = this->modules_.find(full_id);
192
    ModuleList::iterator it = this->modules_.find(full_id);
200
   
193
   
201
    if (it == this->modules_.end())
194
    if (it == this->modules_.end())
202
    {
195
    {
203
        LOG.Warning("Can not send message to " + full_id + ", it is not available");
196
        LOG.Warning("Can not send message to " + full_id + ", it is not available");
204
        return;
197
        return;
205
    }
198
    }
206
   
199
   
207
    try
200
    try
208
    {
201
    {
209
        can::Message* payload = new can::Message(it->second->GetClassName(), "To_Owner", it->second->GetName(), it->second->GetId(), command);
202
        can::Message* payload = new can::Message(it->second->GetClassName(), "To_Owner", it->second->GetName(), it->second->GetId(), command);
210
        payload->SetVariables(variables);
203
        payload->SetVariables(variables);
211
       
204
       
212
        broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this)));
205
        broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this)));
213
        //LOG.Debug("Command " + command + " sent to " + it->second->GetName());
206
        //LOG.Debug("Command " + command + " sent to " + it->second->GetName());
214
    }
207
    }
215
    catch (std::runtime_error& e)
208
    catch (std::runtime_error& e)
216
    {
209
    {
217
        LOG.Error("Failed to send message, " + std::string(e.what()));
210
        LOG.Error("Failed to send message, " + std::string(e.what()));
218
    }
211
    }
219
}
212
}
220
 
213
 
221
void Manager::SendMessage(std::string full_id, std::string command, common::StringMap variables)
214
void Manager::SendMessage(std::string full_id, std::string command, common::StringMap variables)
222
{
215
{
223
    this->io_service_.post(boost::bind(&Manager::SendMessageHandler, this, full_id, command, variables));
216
    this->io_service_.post(boost::bind(&Manager::SendMessageHandler, this, full_id, command, variables));
224
}
217
}
225
 
218
 
226
common::StringList Manager::GetAvailableModules()
219
common::StringList Manager::GetAvailableModules()
227
{
220
{
228
    common::StringList available_modules;
221
    common::StringList available_modules;
229
   
222
   
230
    for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++)
223
    for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++)
231
    {
224
    {
232
        available_modules.push_back(it->first);
225
        available_modules.push_back(it->first);
233
    }
226
    }
234
   
227
   
235
    return available_modules;
228
    return available_modules;
236
}
229
}
237
 
230
 
238
common::StringList Manager::GetAvailableNodes()
231
common::StringList Manager::GetAvailableNodes()
239
{
232
{
240
    common::StringList available_nodes;
233
    common::StringList available_nodes;
241
   
234
   
242
    for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++)
235
    for (NodeList::iterator it = this->nodes_.begin(); it != this->nodes_.end(); it++)
243
    {
236
    {
244
        std::string node = it->first;
237
        std::string node = it->first;
245
 
238
 
246
        for (ModuleList::iterator it2 = this->modules_.begin(); it2 != this->modules_.end(); it2++)
239
        for (ModuleList::iterator it2 = this->modules_.begin(); it2 != this->modules_.end(); it2++)
247
        {
240
        {
248
            if (it2->second->GetNodeId() == it->first)
241
            if (it2->second->GetNodeId() == it->first)
249
            {
242
            {
250
                node += "," + it2->first;
243
                node += "," + it2->first;
251
            }
244
            }
252
        }
245
        }
253
       
246
       
254
        available_nodes.push_back(node);
247
        available_nodes.push_back(node);
255
    }
248
    }
256
   
249
   
257
    return available_nodes;
250
    return available_nodes;
258
}
251
}
259
 
252
 
260
bool Manager::ResetNode(Node::Id node_id)
253
bool Manager::ResetNode(Node::Id node_id)
261
{
254
{
262
    NodeList::iterator it = this->nodes_.find(node_id);
255
    NodeList::iterator it = this->nodes_.find(node_id);
263
   
256
   
264
    if (it == this->nodes_.end())
257
    if (it == this->nodes_.end())
265
    {
258
    {
266
        LOG.Error("Could not find node " +  node_id);
259
        LOG.Error("Could not find node " +  node_id);
267
        return false;
260
        return false;
268
    }
261
    }
269
   
262
   
270
    it->second->Reset();
263
    it->second->Reset();
271
    return true;
264
    return true;
272
}
265
}
273
 
266
 
274
bool Manager::ProgramNode(Node::Id node_id, bool is_bios, std::string filename)
267
bool Manager::ProgramNode(Node::Id node_id, bool is_bios, std::string filename)
275
{
268
{
276
    NodeList::iterator it = this->nodes_.find(node_id);
269
    NodeList::iterator it = this->nodes_.find(node_id);
277
   
270
   
278
    if (it == this->nodes_.end())
271
    if (it == this->nodes_.end())
279
    {
272
    {
280
        LOG.Error("Could not find node " +  node_id);
273
        LOG.Error("Could not find node " +  node_id);
281
        return false;
274
        return false;
282
    }
275
    }
283
   
276
   
284
    Code::Pointer code = Code::Pointer(new Code());
277
    Code::Pointer code = Code::Pointer(new Code());
285
    if (!code->LoadIntelHexFile(filename))
278
    if (!code->LoadIntelHexFile(filename))
286
    {
279
    {
287
        LOG.Error("Failed to parse " + filename);
280
        LOG.Error("Failed to parse " + filename);
288
        return false;
281
        return false;
289
    }
282
    }
290
   
283
   
291
    if (is_bios)
284
    if (is_bios)
292
    {
285
    {
293
        LOG.Debug("is_bios true");
286
        LOG.Debug("is_bios true");
294
        it->second->ProgramBios(code);
287
        it->second->ProgramBios(code);
295
    }
288
    }
296
    else
289
    else
297
    {
290
    {
298
        LOG.Debug("is_bios false");
291
        LOG.Debug("is_bios false");
299
        it->second->ProgramApplication(code);
292
        it->second->ProgramApplication(code);
300
    }
293
    }
301
   
294
   
302
    return true;
295
    return true;
303
}
296
}
304
 
297
 
305
Node::Information Manager::GetNodeInformation(Node::Id node_id)
298
Node::Information Manager::GetNodeInformation(Node::Id node_id)
306
{
299
{
307
    NodeList::iterator it = this->nodes_.find(node_id);
300
    NodeList::iterator it = this->nodes_.find(node_id);
308
   
301
   
309
    if (it == this->nodes_.end())
302
    if (it == this->nodes_.end())
310
    {
303
    {
311
        throw std::runtime_error("No such node exists, " + node_id);
304
        throw std::runtime_error("No such node exists, " + node_id);
312
    }
305
    }
313
       
306
       
314
    return it->second->GetInformation();
307
    return it->second->GetInformation();
315
}
308
}
316
 
309
 
317
Node::Pointer Manager::GetNode(Node::Id node_id)
310
Node::Pointer Manager::GetNode(Node::Id node_id)
318
{
311
{
319
    Node::Pointer node;
312
    Node::Pointer node;
320
    NodeList::iterator it = this->nodes_.find(node_id);
313
    NodeList::iterator it = this->nodes_.find(node_id);
321
   
314
   
322
    if (it == this->nodes_.end())
315
    if (it == this->nodes_.end())
323
    {
316
    {
324
        node = Node::Pointer(new Node(node_id));
317
        node = Node::Pointer(new Node(node_id));
325
        node->ConnectSlots(Node::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, _2, _3).track(this->tracker_));
318
        node->ConnectSlots(Node::SignalOnNewState::slot_type(&Manager::SlotOnNewState, this, _1, _2, _3).track(this->tracker_));
326
        this->nodes_[node_id] = node;
319
        this->nodes_[node_id] = node;
327
    }
320
    }
328
    else
321
    else
329
    {
322
    {
330
        node = it->second;
323
        node = it->second;
331
    }
324
    }
332
   
325
   
333
    return node;
326
    return node;
334
}
327
}
335
 
328
 
336
Module::Pointer Manager::GetModule(Module::Id module_id, std::string module_name, std::string class_name)
329
Module::Pointer Manager::GetModule(Module::Id module_id, std::string module_name, std::string class_name)
337
{
330
{
338
    Module::Pointer module;
331
    Module::Pointer module;
339
    ModuleList::iterator it = this->modules_.find(Module::MakeFullId(module_id, module_name));
332
    ModuleList::iterator it = this->modules_.find(Module::MakeFullId(module_id, module_name));
340
   
333
   
341
    if (it == this->modules_.end())
334
    if (it == this->modules_.end())
342
    {
335
    {
343
        module = Module::Pointer(new Module(module_id, module_name, class_name));
336
        module = Module::Pointer(new Module(module_id, module_name, class_name));
344
        this->modules_[module->GetFullId()] = module;
337
        this->modules_[module->GetFullId()] = module;
345
    }
338
    }
346
    else
339
    else
347
    {
340
    {
348
        module = it->second;
341
        module = it->second;
349
    }
342
    }
350
   
343
   
351
    return module;
344
    return module;
352
}
345
}
353
 
346
 
354
void Manager::RemoveModules(Node::Id node_id)
347
void Manager::RemoveModules(Node::Id node_id)
355
{
348
{
356
    for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++)
349
    for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++)
357
    {
350
    {
358
        if (it->second->GetNodeId() == node_id)
351
        if (it->second->GetNodeId() == node_id)
359
        {
352
        {
360
            LOG.Info("Module " + it->second->GetFullId() + " is unavailable.");
353
            LOG.Info("Module " + it->second->GetFullId() + " is unavailable.");
361
            this->signal_on_module_change_(it->second->GetFullId(), false);
354
            this->signal_on_module_change_(it->second->GetFullId(), false);
362
           
355
           
363
            this->modules_.erase(it);
356
            this->modules_.erase(it);
364
        }
357
        }
365
    }
358
    }
366
}
359
}
367
 
360
 
368
unsigned int Manager::GetNumberOfModules(Node::Id node_id)
361
unsigned int Manager::GetNumberOfModules(Node::Id node_id)
369
{
362
{
370
    unsigned int number_of_modules = 0;
363
    unsigned int number_of_modules = 0;
371
   
364
   
372
    for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++)
365
    for (ModuleList::iterator it = this->modules_.begin(); it != this->modules_.end(); it++)
373
    {
366
    {
374
        if (it->second->GetNodeId() == node_id)
367
        if (it->second->GetNodeId() == node_id)
375
        {
368
        {
376
            number_of_modules++;
369
            number_of_modules++;
377
        }
370
        }
378
    }
371
    }
379
   
372
   
380
    return number_of_modules;
373
    return number_of_modules;
381
}
374
}
382
 
375
 
383
}; // namespace control
376
}; // namespace control
384
}; // namespace atom
377
}; // namespace atom
385
 
378