Subversion Repositories HomeAutomation

Rev

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

Rev 1650 Rev 1657
Line 35... Line 35...
35
{
35
{
36
    this->name_ = "module";
36
    this->name_ = "module";
37
   
37
   
38
    this->ExportFunction("ModuleExport_SendMessage",         Module::Export_SendModuleMessage);
38
    this->ExportFunction("ModuleExport_SendMessage",         Module::Export_SendModuleMessage);
39
    this->ExportFunction("ModuleExport_GetAvailableModules", Module::Export_GetAvailableModules);
39
    this->ExportFunction("ModuleExport_GetAvailableModules", Module::Export_GetAvailableModules);
40
    this->ExportFunction("ModuleExport_ProgramNode",         Module::Export_ProgramNode);
-
 
41
}
40
}
42
 
41
 
43
Module::~Module()
42
Module::~Module()
44
{
43
{
45
    this->tracker_.reset();
44
    this->tracker_.reset();
Line 50... Line 49...
50
    Plugin::InitializeDone();
49
    Plugin::InitializeDone();
51
   
50
   
52
    this->ImportFunction("Module_OnChange");
51
    this->ImportFunction("Module_OnChange");
53
    this->ImportFunction("Module_OnMessage");
52
    this->ImportFunction("Module_OnMessage");
54
   
53
   
55
    control::Manager::Instance()->ConnectSlots(control::Manager::SignalOnNodeChange::slot_type(&Module::SlotOnNodeChange, this, _1, _2).track(this->tracker_),
54
    control::Manager::Instance()->ConnectSlotModule(control::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_),
-
 
57
                                               control::Manager::SignalOnModuleMessage::slot_type(&Module::SlotOnModuleMessage, this, _1, _2, _3).track(this->tracker_));
55
    control::Manager::Instance()->ConnectSlotModule(control::Manager::SignalOnModuleMessage::slot_type(&Module::SlotOnModuleMessage, this, _1, _2, _3).track(this->tracker_));
58
}
56
}
59
 
57
 
60
void Module::CallOutput(unsigned int request_id, std::string output)
58
void Module::CallOutput(unsigned int request_id, std::string output)
61
{
59
{
62
    LOG.Info(output);
60
    LOG.Info(output);
63
}
61
}
64
 
62
 
65
void Module::SlotOnNodeChange(unsigned int node_id, bool available)
-
 
66
{
-
 
67
    this->io_service_.post(boost::bind(&Module::SlotOnNodeChangeHandler, this, node_id, available));
-
 
68
}
-
 
69
 
-
 
70
void Module::SlotOnModuleChange(std::string full_id, bool available)
63
void Module::SlotOnModuleChange(std::string full_id, bool available)
71
{
64
{
72
    this->io_service_.post(boost::bind(&Module::SlotOnModuleChangeHandler, this, full_id, available));
65
    this->io_service_.post(boost::bind(&Module::SlotOnModuleChangeHandler, this, full_id, available));
73
}
66
}
74
 
67
 
75
void Module::SlotOnModuleMessage(std::string full_id, std::string command, common::StringMap variables)
68
void Module::SlotOnModuleMessage(std::string full_id, std::string command, common::StringMap variables)
76
{
69
{
77
    this->io_service_.post(boost::bind(&Module::SlotOnModuleMessageHandler, this, full_id, command, variables));
70
    this->io_service_.post(boost::bind(&Module::SlotOnModuleMessageHandler, this, full_id, command, variables));
78
}
-
 
79
 
-
 
80
void Module::SlotOnNodeChangeHandler(unsigned int node_id, bool available)
-
 
81
{
-
 
82
 
-
 
83
}
71
}
84
 
72
 
85
void Module::SlotOnModuleChangeHandler(std::string full_id, bool available)
73
void Module::SlotOnModuleChangeHandler(std::string full_id, bool available)
86
{
74
{
87
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
75
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
88
   
76
   
89
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
77
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
90
   
78
   
91
    ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList);
79
    ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList);
Line 105... Line 93...
105
   
93
   
106
    arguments->push_back(v8::String::New(full_id.data()));
94
    arguments->push_back(v8::String::New(full_id.data()));
107
    arguments->push_back(v8::String::New(command.data()));
95
    arguments->push_back(v8::String::New(command.data()));
108
   
96
   
109
    v8::Local<v8::Array> vars = v8::Array::New(variables.size());
97
    v8::Local<v8::Array> vars = v8::Array::New(variables.size());
110
   
98
   
111
    for (common::StringMap::iterator it = variables.begin(); it != variables.end(); it++)
99
    for (common::StringMap::iterator it = variables.begin(); it != variables.end(); it++)
112
    {
100
    {
113
        vars->Set(v8::String::New(it->first.data()), v8::String::New(it->second.data()));
101
        vars->Set(v8::String::New(it->first.data()), v8::String::New(it->second.data()));
114
    }
102
    }
115
   
103
   
116
    arguments->push_back(vars);
104
    arguments->push_back(vars);
117
   
105
   
118
    this->Call(0, "Module_OnMessage", arguments);
106
    this->Call(0, "Module_OnMessage", arguments);
119
}
107
}
120
 
108
 
121
Value Module::Export_SendModuleMessage(const v8::Arguments& args)
109
Value Module::Export_SendModuleMessage(const v8::Arguments& args)
122
{
110
{
123
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
111
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
124
   
112
   
125
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
113
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
126
   
114
   
127
    if (args.Length() < 3)
115
    if (args.Length() < 3)
128
    {
116
    {
129
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
117
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
130
        return v8::Boolean::New(false);
118
        return v8::Boolean::New(false);
131
    }
119
    }
132
   
120
   
133
    common::StringMap variables;
121
    common::StringMap variables;
134
   
122
   
135
    v8::String::AsciiValue full_id(args[0]);
123
    v8::String::AsciiValue full_id(args[0]);
136
    v8::String::AsciiValue command(args[1]);
124
    v8::String::AsciiValue command(args[1]);
137
    unsigned int length = args[2]->Uint32Value();
125
    unsigned int length = args[2]->Uint32Value();
138
   
126
   
139
    for (unsigned int n = 3; n < length * 2 + 3; n += 2)
127
    for (unsigned int n = 3; n < length * 2 + 3; n += 2)
Line 150... Line 138...
150
   
138
   
151
    return v8::Boolean::New(true);
139
    return v8::Boolean::New(true);
152
}
140
}
153
 
141
 
154
Value Module::Export_GetAvailableModules(const v8::Arguments& args)
142
Value Module::Export_GetAvailableModules(const v8::Arguments& args)
155
{
143
{
156
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
144
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
157
   
145
   
158
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
146
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
159
   
147
   
160
    common::StringList available_modules = control::Manager::Instance()->GetAvailableModules();
148
    common::StringList available_modules = control::Manager::Instance()->GetAvailableModules();
161
   
149
   
162
    v8::Local<v8::Array> result = v8::Array::New(available_modules.size());
150
    v8::Local<v8::Array> result = v8::Array::New(available_modules.size());
163
   
151
   
164
    for (unsigned int n = 0; n < available_modules.size(); n++)
152
    for (unsigned int n = 0; n < available_modules.size(); n++)
165
    {
153
    {
166
        result->Set(n, v8::String::New(available_modules[n].data()));
154
        result->Set(n, v8::String::New(available_modules[n].data()));
167
    }
155
    }
168
   
156
   
169
    return result;
157
    return result;
170
}
-
 
171
 
-
 
172
Value Module::Export_ProgramNode(const v8::Arguments& args)
-
 
173
{
-
 
174
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
175
   
-
 
176
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
-
 
177
   
-
 
178
    if (args.Length() < 3)
-
 
179
    {
-
 
180
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
-
 
181
        return v8::Boolean::New(false);
-
 
182
    }
-
 
183
   
-
 
184
    v8::String::AsciiValue filename(args[2]);
-
 
185
   
-
 
186
    return v8::Boolean::New(control::Manager::Instance()->ProgramNode(args[0]->Uint32Value(), args[1]->BooleanValue(), std::string(*filename)));
-
 
187
}
158
}
188
   
159
 
189
}; // namespace plugin
160
}; // namespace plugin
190
}; // namespace vm
161
}; // namespace vm
191
}; // namespace atom
162
}; // namespace atom