Subversion Repositories HomeAutomation

Rev

Rev 1602 | Rev 1607 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1602 Rev 1604
Line 83... Line 83...
83
 
83
 
84
void Manager::SlotOnMessageHandler(broker::Message::Pointer message)
84
void Manager::SlotOnMessageHandler(broker::Message::Pointer message)
85
{
85
{
86
    if (message->GetType() == broker::Message::CAN_MESSAGE)
86
    if (message->GetType() == broker::Message::CAN_MESSAGE)
87
    {
87
    {
-
 
88
        //LOG.Debug("Message received");
88
        Message* payload = static_cast<Message*>(message->GetPayload().get());
89
        Message* payload = static_cast<Message*>(message->GetPayload().get());
89
        Node::Pointer node;
90
        Node::Pointer node;
90
       
91
       
91
        if (payload->GetClassName() == "nmt")
92
        if (payload->GetClassName() == "nmt")
92
        {
93
        {
Line 164... Line 165...
164
            }
165
            }
165
        }
166
        }
166
    }
167
    }
167
}
168
}
168
 
169
 
169
void Manager::SendMessage(std::string full_id, std::string command, type::StringMap variables)
170
void Manager::SendMessageHandler(std::string full_id, std::string command, type::StringMap variables)
170
{
171
{
171
    ModuleList::iterator it = this->modules_.find(full_id);
172
    ModuleList::iterator it = this->modules_.find(full_id);
172
   
173
   
173
    if (it == this->modules_.end())
174
    if (it == this->modules_.end())
174
    {
175
    {
175
        LOG.Warning("Can not send message to " + full_id + ", it is not available");
176
        LOG.Warning("Can not send message to " + full_id + ", it is not available");
176
        return;
177
        return;
177
    }
178
    }
178
   
179
   
179
    try
180
    try
180
    {
181
    {
181
        Message* payload = new Message(it->second->GetClassName(), "To_Owner", it->second->GetName(), it->second->GetId(), command);
182
        Message* payload = new Message(it->second->GetClassName(), "To_Owner", it->second->GetName(), it->second->GetId(), command);
182
        payload->SetVariables(variables);
183
        payload->SetVariables(variables);
183
       
184
       
184
        broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this)));
185
        broker::Manager::Instance()->Post(broker::Message::Pointer(new broker::Message(broker::Message::CAN_MESSAGE, broker::Message::PayloadPointer(payload), this)));
-
 
186
        LOG.Debug("Message sent!");
185
    }
187
    }
186
    catch (std::runtime_error& e)
188
    catch (std::runtime_error& e)
187
    {
189
    {
188
        LOG.Error("Failed to send message, " + std::string(e.what()));
190
        LOG.Error("Failed to send message, " + std::string(e.what()));
189
    }
191
    }
-
 
192
}
-
 
193
 
-
 
194
void Manager::SendMessage(std::string full_id, std::string command, type::StringMap variables)
-
 
195
{
-
 
196
    this->io_service_.post(boost::bind(&Manager::SendMessageHandler, this, full_id, command, variables));
-
 
197
}
-
 
198
 
-
 
199
bool Manager::IsModuleAvailable(std::string full_id)
-
 
200
{
-
 
201
    return this->modules_.find(full_id) != this->modules_.end();
190
}
202
}
191
 
203
 
192
Node::Pointer Manager::GetNode(Node::Id node_id)
204
Node::Pointer Manager::GetNode(Node::Id node_id)
193
{
205
{
194
    Node::Pointer node;
206
    Node::Pointer node;