Rev 1619 | Rev 1642 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1619 | Rev 1625 | ||
|---|---|---|---|
| Line 29... | Line 29... | ||
| 29 | namespace vm { |
29 | namespace vm { |
| 30 | namespace plugin { |
30 | namespace plugin { |
| 31 | 31 | ||
| 32 | logging::Logger Module::LOG("vm::plugin::module"); |
32 | logging::Logger Module::LOG("vm::plugin::module"); |
| 33 | 33 | ||
| 34 | Module::Module() |
34 | Module::Module(boost::asio::io_service& io_service) : Plugin(io_service) |
| 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); |
| Line 56... | Line 56... | ||
| 56 | can::Manager::SignalOnModuleMessage::slot_type(&Module::SlotOnModuleMessage, this, _1, _2, _3).track(this->tracker_)); |
56 | can::Manager::SignalOnModuleMessage::slot_type(&Module::SlotOnModuleMessage, this, _1, _2, _3).track(this->tracker_)); |
| 57 | } |
57 | } |
| 58 | 58 | ||
| 59 | void Module::SlotOnNodeChange(unsigned int node_id, bool available) |
59 | void Module::SlotOnNodeChange(unsigned int node_id, bool available) |
| 60 | { |
60 | { |
| 61 | - | ||
| - | 61 | this->io_service_.post(boost::bind(&Module::SlotOnNodeChangeHandler, this, node_id, available)); |
|
| 62 | } |
62 | } |
| 63 | 63 | ||
| 64 | void Module::SlotOnModuleChange(std::string full_id, bool available) |
64 | void Module::SlotOnModuleChange(std::string full_id, bool available) |
| 65 | { |
65 | { |
| - | 66 | this->io_service_.post(boost::bind(&Module::SlotOnModuleChangeHandler, this, full_id, available)); |
|
| - | 67 | } |
|
| - | 68 | ||
| - | 69 | void Module::SlotOnModuleMessage(std::string full_id, std::string command, type::StringMap variables) |
|
| - | 70 | { |
|
| - | 71 | this->io_service_.post(boost::bind(&Module::SlotOnModuleMessageHandler, this, full_id, command, variables)); |
|
| - | 72 | } |
|
| - | 73 | ||
| - | 74 | void Module::SlotOnNodeChangeHandler(unsigned int node_id, bool available) |
|
| - | 75 | { |
|
| - | 76 | ||
| - | 77 | } |
|
| - | 78 | ||
| - | 79 | void Module::SlotOnModuleChangeHandler(std::string full_id, bool available) |
|
| - | 80 | { |
|
| - | 81 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
|
| - | 82 | ||
| - | 83 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
|
| - | 84 | ||
| 66 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
85 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
| 67 | arguments->push_back(v8::String::New(full_id.data())); |
86 | arguments->push_back(v8::String::New(full_id.data())); |
| 68 | arguments->push_back(v8::Boolean::New(available)); |
87 | arguments->push_back(v8::Boolean::New(available)); |
| 69 | 88 | ||
| 70 | this->Call(0, "Module_OnChange", arguments); |
89 | this->Call(0, "Module_OnChange", arguments); |
| 71 | } |
90 | } |
| 72 | 91 | ||
| 73 | void Module:: |
92 | void Module::SlotOnModuleMessageHandler(std::string full_id, std::string command, type::StringMap variables) |
| 74 | { |
93 | { |
| 75 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
94 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
| 76 | 95 | ||
| 77 |
|
96 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
| 78 | 97 | ||
| 79 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
98 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
| 80 | 99 | ||
| 81 | arguments->push_back(v8::String::New(full_id.data())); |
100 | arguments->push_back(v8::String::New(full_id.data())); |
| 82 | arguments->push_back(v8::String::New(command.data())); |
101 | arguments->push_back(v8::String::New(command.data())); |
| 83 | 102 | ||
| Line 89... | Line 108... | ||
| 89 | } |
108 | } |
| 90 | 109 | ||
| 91 | arguments->push_back(vars); |
110 | arguments->push_back(vars); |
| 92 | 111 | ||
| 93 | this->Call(0, "Module_OnMessage", arguments); |
112 | this->Call(0, "Module_OnMessage", arguments); |
| 94 | } |
113 | } |
| 95 | 114 | ||
| 96 | Value Module::Export_SendModuleMessage(const v8::Arguments& args) |
115 | Value Module::Export_SendModuleMessage(const v8::Arguments& args) |
| 97 | { |
116 | { |
| - | 117 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
|
| - | 118 | ||
| 98 |
|
119 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
| 99 | 120 | ||
| 100 | if (args.Length() < 3) |
121 | if (args.Length() < 3) |
| 101 | { |
122 | { |
| 102 | LOG.Error("To few arguments."); |
123 | LOG.Error("To few arguments."); |
| 103 | } |
124 | } |
| 104 | 125 | ||
| 105 | type::StringMap variables; |
126 | type::StringMap variables; |
| 106 | 127 | ||
| 107 | v8::String::AsciiValue full_id(args[0]); |
128 | v8::String::AsciiValue full_id(args[0]); |
| 108 | v8::String::AsciiValue command(args[1]); |
129 | v8::String::AsciiValue command(args[1]); |
| Line 114... | Line 135... | ||
| 114 | v8::String::AsciiValue value(args[n + 1]); |
135 | v8::String::AsciiValue value(args[n + 1]); |
| 115 | 136 | ||
| 116 | //LOG.Debug(std::string(*name) + "====" + std::string(*value)); |
137 | //LOG.Debug(std::string(*name) + "====" + std::string(*value)); |
| 117 | 138 | ||
| 118 | variables[std::string(*name)] = std::string(*value); |
139 | variables[std::string(*name)] = std::string(*value); |
| 119 | } |
140 | } |
| 120 | 141 | ||
| 121 | can::Manager::Instance()->SendMessage(std::string(*full_id), std::string(*command), variables); |
142 | can::Manager::Instance()->SendMessage(std::string(*full_id), std::string(*command), variables); |
| 122 | 143 | ||
| 123 | return v8::Undefined(); |
144 | return v8::Undefined(); |
| 124 | } |
145 | } |
| 125 | 146 | ||
| 126 | Value Module::Export_IsModuleAvailable(const v8::Arguments& args) |
147 | Value Module::Export_IsModuleAvailable(const v8::Arguments& args) |
| 127 | { |
148 | { |
| - | 149 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
|
| - | 150 | ||
| 128 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
151 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
| 129 | 152 | ||
| 130 | if (args.Length() < 1) |
153 | if (args.Length() < 1) |
| 131 | { |
154 | { |
| 132 | LOG.Error("To few arguments."); |
155 | LOG.Error("To few arguments."); |