Subversion Repositories HomeAutomation

Rev

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

Rev 1625 Rev 1642
Line 20... Line 20...
20
 
20
 
21
#include "Module.h"
21
#include "Module.h"
22
 
22
 
23
#include <boost/lexical_cast.hpp>
23
#include <boost/lexical_cast.hpp>
24
 
24
 
25
#include "can/Manager.h"
25
#include "control/Manager.h"
26
#include "vm/Manager.h"
26
#include "vm/Manager.h"
27
 
27
 
28
namespace atom {
28
namespace atom {
29
namespace vm {
29
namespace vm {
30
namespace plugin {
30
namespace plugin {
Line 35... Line 35...
35
{
35
{
36
    this->name_ = "module";
36
    this->name_ = "module";
37
   
37
   
38
    this->ExportFunction("Module_SendMessage", Module::Export_SendModuleMessage);
38
    this->ExportFunction("Module_SendMessage", Module::Export_SendModuleMessage);
39
    this->ExportFunction("Module_IsModuleAvailable", Module::Export_IsModuleAvailable);
39
    this->ExportFunction("Module_IsModuleAvailable", Module::Export_IsModuleAvailable);
-
 
40
    this->ExportFunction("Module_ProgramNode", Module::Export_ProgramNode);
40
}
41
}
41
 
42
 
42
Module::~Module()
43
Module::~Module()
43
{
44
{
44
    this->tracker_.reset();
45
    this->tracker_.reset();
Line 49... Line 50...
49
    Plugin::InitializeDone();
50
    Plugin::InitializeDone();
50
   
51
   
51
    this->ImportFunction("Module_OnChange");
52
    this->ImportFunction("Module_OnChange");
52
    this->ImportFunction("Module_OnMessage");
53
    this->ImportFunction("Module_OnMessage");
53
   
54
   
54
    can::Manager::Instance()->ConnectSlots(can::Manager::SignalOnNodeChange::slot_type(&Module::SlotOnNodeChange, this, _1, _2).track(this->tracker_),
55
    control::Manager::Instance()->ConnectSlots(control::Manager::SignalOnNodeChange::slot_type(&Module::SlotOnNodeChange, this, _1, _2).track(this->tracker_),
55
                                           can::Manager::SignalOnModuleChange::slot_type(&Module::SlotOnModuleChange, this, _1, _2).track(this->tracker_),
56
                                               control::Manager::SignalOnModuleChange::slot_type(&Module::SlotOnModuleChange, this, _1, _2).track(this->tracker_),
56
                                           can::Manager::SignalOnModuleMessage::slot_type(&Module::SlotOnModuleMessage, this, _1, _2, _3).track(this->tracker_));
57
                                               control::Manager::SignalOnModuleMessage::slot_type(&Module::SlotOnModuleMessage, this, _1, _2, _3).track(this->tracker_));
57
}
58
}
58
 
59
 
59
void Module::SlotOnNodeChange(unsigned int node_id, bool available)
60
void Module::SlotOnNodeChange(unsigned int node_id, bool available)
60
{
61
{
61
    this->io_service_.post(boost::bind(&Module::SlotOnNodeChangeHandler, this, node_id, available));
62
    this->io_service_.post(boost::bind(&Module::SlotOnNodeChangeHandler, this, node_id, available));
Line 64... Line 65...
64
void Module::SlotOnModuleChange(std::string full_id, bool available)
65
void Module::SlotOnModuleChange(std::string full_id, bool available)
65
{
66
{
66
    this->io_service_.post(boost::bind(&Module::SlotOnModuleChangeHandler, this, full_id, available));
67
    this->io_service_.post(boost::bind(&Module::SlotOnModuleChangeHandler, this, full_id, available));
67
}
68
}
68
 
69
 
69
void Module::SlotOnModuleMessage(std::string full_id, std::string command, type::StringMap variables)
70
void Module::SlotOnModuleMessage(std::string full_id, std::string command, common::StringMap variables)
70
{
71
{
71
    this->io_service_.post(boost::bind(&Module::SlotOnModuleMessageHandler, this, full_id, command, variables));
72
    this->io_service_.post(boost::bind(&Module::SlotOnModuleMessageHandler, this, full_id, command, variables));
72
}
73
}
73
 
74
 
74
void Module::SlotOnNodeChangeHandler(unsigned int node_id, bool available)
75
void Module::SlotOnNodeChangeHandler(unsigned int node_id, bool available)
Line 78... Line 79...
78
 
79
 
79
void Module::SlotOnModuleChangeHandler(std::string full_id, bool available)
80
void Module::SlotOnModuleChangeHandler(std::string full_id, bool available)
80
{
81
{
81
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
82
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
82
   
83
   
83
    LOG.Debug(std::string(__FUNCTION__) + " called!");
84
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
84
   
85
   
85
    ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList);
86
    ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList);
86
    arguments->push_back(v8::String::New(full_id.data()));
87
    arguments->push_back(v8::String::New(full_id.data()));
87
    arguments->push_back(v8::Boolean::New(available));
88
    arguments->push_back(v8::Boolean::New(available));
88
   
89
   
89
    this->Call(0, "Module_OnChange", arguments);
90
    this->Call(0, "Module_OnChange", arguments);
90
}
91
}
91
 
92
 
92
void Module::SlotOnModuleMessageHandler(std::string full_id, std::string command, type::StringMap variables)
93
void Module::SlotOnModuleMessageHandler(std::string full_id, std::string command, common::StringMap variables)
93
{
94
{
94
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
95
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
95
   
96
   
96
    LOG.Debug(std::string(__FUNCTION__) + " called!");
97
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
97
   
98
   
98
    ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList);
99
    ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList);
99
   
100
   
100
    arguments->push_back(v8::String::New(full_id.data()));
101
    arguments->push_back(v8::String::New(full_id.data()));
101
    arguments->push_back(v8::String::New(command.data()));
102
    arguments->push_back(v8::String::New(command.data()));
102
   
103
   
103
    v8::Local<v8::Array> vars = v8::Array::New(variables.size());
104
    v8::Local<v8::Array> vars = v8::Array::New(variables.size());
104
   
105
   
105
    for (type::StringMap::iterator it = variables.begin(); it != variables.end(); it++)
106
    for (common::StringMap::iterator it = variables.begin(); it != variables.end(); it++)
106
    {
107
    {
107
        vars->Set(v8::String::New(it->first.data()), v8::String::New(it->second.data()));
108
        vars->Set(v8::String::New(it->first.data()), v8::String::New(it->second.data()));
108
    }
109
    }
109
   
110
   
110
    arguments->push_back(vars);
111
    arguments->push_back(vars);
Line 114... Line 115...
114
 
115
 
115
Value Module::Export_SendModuleMessage(const v8::Arguments& args)
116
Value Module::Export_SendModuleMessage(const v8::Arguments& args)
116
{
117
{
117
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
118
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
118
   
119
   
119
    LOG.Debug(std::string(__FUNCTION__) + " called!");
120
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
120
   
121
   
121
    if (args.Length() < 3)
122
    if (args.Length() < 3)
122
    {
123
    {
123
        LOG.Error("To few arguments.");
124
        LOG.Error("To few arguments.");
124
    }
125
    }
125
   
126
   
126
    type::StringMap variables;
127
    common::StringMap variables;
127
   
128
   
128
    v8::String::AsciiValue full_id(args[0]);
129
    v8::String::AsciiValue full_id(args[0]);
129
    v8::String::AsciiValue command(args[1]);
130
    v8::String::AsciiValue command(args[1]);
130
    unsigned int length = args[2]->Uint32Value();
131
    unsigned int length = args[2]->Uint32Value();
131
   
132
   
Line 137... Line 138...
137
        //LOG.Debug(std::string(*name) + "====" + std::string(*value));
138
        //LOG.Debug(std::string(*name) + "====" + std::string(*value));
138
       
139
       
139
        variables[std::string(*name)] = std::string(*value);
140
        variables[std::string(*name)] = std::string(*value);
140
    }
141
    }
141
   
142
   
142
    can::Manager::Instance()->SendMessage(std::string(*full_id), std::string(*command), variables);
143
    control::Manager::Instance()->SendMessage(std::string(*full_id), std::string(*command), variables);
143
   
144
   
144
    return v8::Undefined();
145
    return v8::Undefined();
145
}
146
}
146
 
147
 
147
Value Module::Export_IsModuleAvailable(const v8::Arguments& args)
148
Value Module::Export_IsModuleAvailable(const v8::Arguments& args)
148
{
149
{
149
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
150
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
150
   
151
   
151
    LOG.Debug(std::string(__FUNCTION__) + " called!");
152
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
152
   
153
   
153
    if (args.Length() < 1)
154
    if (args.Length() < 1)
154
    {
155
    {
155
        LOG.Error("To few arguments.");
156
        LOG.Error("To few arguments.");
156
    }
157
    }
157
   
158
   
158
    v8::String::AsciiValue full_id(args[0]);
159
    v8::String::AsciiValue full_id(args[0]);
159
   
160
   
160
    return v8::Boolean::New(can::Manager::Instance()->IsModuleAvailable(std::string(*full_id)));
161
    return v8::Boolean::New(control::Manager::Instance()->IsModuleAvailable(std::string(*full_id)));
-
 
162
}
-
 
163
 
-
 
164
 
-
 
165
Value Module::Export_ProgramNode(const v8::Arguments& args)
-
 
166
{
-
 
167
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
168
   
-
 
169
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
-
 
170
   
-
 
171
    if (args.Length() < 3)
-
 
172
    {
-
 
173
        LOG.Error("To few arguments.");
-
 
174
    }
-
 
175
   
-
 
176
    v8::String::AsciiValue filename(args[2]);
-
 
177
   
-
 
178
    return v8::Boolean::New(control::Manager::Instance()->ProgramNode(args[0]->Uint32Value(), args[1]->BooleanValue(), std::string(*filename)));
161
}
179
}
162
   
180
   
163
}; // namespace plugin
181
}; // namespace plugin
164
}; // namespace vm
182
}; // namespace vm
165
}; // namespace atom
183
}; // namespace atom