Rev 1620 | Rev 1627 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1620 | Rev 1625 | ||
|---|---|---|---|
| Line 23... | Line 23... | ||
| 23 | #include <boost/lexical_cast.hpp> |
23 | #include <boost/lexical_cast.hpp> |
| 24 | #include <boost/algorithm/string/trim.hpp> |
24 | #include <boost/algorithm/string/trim.hpp> |
| 25 | #include <boost/algorithm/string/split.hpp> |
25 | #include <boost/algorithm/string/split.hpp> |
| 26 | 26 | ||
| 27 | #include "net/Manager.h" |
27 | #include "net/Manager.h" |
| - | 28 | #include "vm/Manager.h" |
|
| 28 | 29 | ||
| 29 | namespace atom { |
30 | namespace atom { |
| 30 | namespace vm { |
31 | namespace vm { |
| 31 | namespace plugin { |
32 | namespace plugin { |
| 32 | 33 | ||
| 33 | logging::Logger Console::LOG("vm::plugin::Console"); |
34 | logging::Logger Console::LOG("vm::plugin::Console"); |
| 34 | type::StringList Console::commands_; |
35 | type::StringList Console::commands_; |
| 35 | 36 | ||
| 36 | Console::Console(unsigned |
37 | Console::Console(boost::asio::io_service& io_service, unsigned int port) : Plugin(io_service) |
| 37 | { |
38 | { |
| 38 | this->name_ = "console"; |
39 | this->name_ = "console"; |
| 39 | 40 | ||
| 40 | net::Manager::Instance()->ConnectSlots(net::Manager::SignalOnNewState::slot_type(&Console::SlotOnNewState, this, _1, _2, _3).track(this->tracker_), |
41 | net::Manager::Instance()->ConnectSlots(net::Manager::SignalOnNewState::slot_type(&Console::SlotOnNewState, this, _1, _2, _3).track(this->tracker_), |
| 41 | net::Manager::SignalOnNewData::slot_type(&Console::SlotOnNewData, this, _1, _2, _3).track(this->tracker_)); |
42 | net::Manager::SignalOnNewData::slot_type(&Console::SlotOnNewData, this, _1, _2, _3).track(this->tracker_)); |
| Line 72... | Line 73... | ||
| 72 | { |
73 | { |
| 73 | if (server_id != this->server_id_) |
74 | if (server_id != this->server_id_) |
| 74 | { |
75 | { |
| 75 | return; |
76 | return; |
| 76 | } |
77 | } |
| - | 78 | ||
| - | 79 | this->io_service_.post(boost::bind(&Console::SlotOnNewDataHandler, this, client_id, server_id, data)); |
|
| - | 80 | } |
|
| - | 81 | ||
| - | 82 | void Console::SlotOnNewState(net::ClientId client_id, net::ServerId server_id, net::ClientState client_state) |
|
| - | 83 | { |
|
| - | 84 | if (server_id != this->server_id_) |
|
| - | 85 | { |
|
| - | 86 | return; |
|
| - | 87 | } |
|
| - | 88 | ||
| - | 89 | this->io_service_.post(boost::bind(&Console::SlotOnNewStateHandler, this, client_id, server_id, client_state)); |
|
| - | 90 | } |
|
| - | 91 | ||
| - | 92 | void Console::SlotOnNewDataHandler(net::ClientId client_id, net::ServerId server_id, type::Byteset data) |
|
| - | 93 | { |
|
| - | 94 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
|
| - | 95 | ||
| - | 96 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
|
| 77 | 97 | ||
| 78 | std::string str(data.ToCharString()); |
98 | std::string str(data.ToCharString()); |
| 79 | 99 | ||
| 80 | boost::algorithm::trim_right_if(str, boost::is_any_of("\r\n")); |
100 | boost::algorithm::trim_right_if(str, boost::is_any_of("\r\n")); |
| 81 | 101 | ||
| Line 98... | Line 118... | ||
| 98 | { |
118 | { |
| 99 | //LOG.Debug(this->commands_[n]); |
119 | //LOG.Debug(this->commands_[n]); |
| 100 | result += this->commands_[n] + "\n"; |
120 | result += this->commands_[n] + "\n"; |
| 101 | } |
121 | } |
| 102 | 122 | ||
| 103 | net::Manager::Instance()->SendTo(client_id, result); |
123 | net::Manager::Instance()->SendTo(client_id, result); |
| 104 | } |
124 | } |
| 105 | else |
125 | else |
| 106 | { |
126 | { |
| 107 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
127 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
| 108 | type::StringList arguments; |
128 | type::StringList arguments; |
| 109 | 129 | ||
| 110 | boost::algorithm::split(arguments, parts[2], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
130 | boost::algorithm::split(arguments, parts[2], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
| 111 | 131 | ||
| 112 | for (unsigned int n = 0; n < arguments.size() && n <= arg_index; n++) |
132 | for (unsigned int n = 0; n < arguments.size() && n <= arg_index; n++) |
| 113 | { |
133 | { |
| 114 | call_arguments->push_back(v8::String::New(arguments[n].data())); |
134 | call_arguments->push_back(v8::String::New(arguments[n].data())); |
| 115 | } |
135 | } |
| 116 | 136 | ||
| 117 | this->Call(client_id, "Console_DoAutocomplete", call_arguments); |
137 | this->Call(client_id, "Console_DoAutocomplete", call_arguments); |
| 118 | } |
138 | } |
| 119 | } |
139 | } |
| 120 | else if (parts[0] == "E") |
140 | else if (parts[0] == "E") |
| 121 | { |
141 | { |
| 122 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
142 | ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList); |
| 123 | type::StringList arguments; |
143 | type::StringList arguments; |
| 124 | 144 | ||
| 125 | boost::algorithm::split(arguments, parts[1], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
145 | boost::algorithm::split(arguments, parts[1], boost::is_any_of(" "), boost::algorithm::token_compress_on); |
| 126 | 146 | ||
| 127 | std::string command = arguments[0]; |
147 | std::string command = arguments[0]; |
| 128 | 148 | ||
| 129 | for (unsigned int n = 1; n < arguments.size(); n++) |
149 | for (unsigned int n = 1; n < arguments.size(); n++) |
| 130 | { |
150 | { |
| 131 | call_arguments->push_back(v8::String::New(arguments[n].data())); |
151 | call_arguments->push_back(v8::String::New(arguments[n].data())); |
| Line 140... | Line 160... | ||
| 140 | call_arguments->push_back(v8::String::New(parts[1].data())); |
160 | call_arguments->push_back(v8::String::New(parts[1].data())); |
| 141 | call_arguments->push_back(v8::String::New(parts[2].data())); |
161 | call_arguments->push_back(v8::String::New(parts[2].data())); |
| 142 | 162 | ||
| 143 | this->Call(client_id, "Console_PromptResponse", call_arguments); |
163 | this->Call(client_id, "Console_PromptResponse", call_arguments); |
| 144 | } |
164 | } |
| 145 | } |
165 | } |
| 146 | 166 | ||
| 147 | void Console:: |
167 | void Console::SlotOnNewStateHandler(net::ClientId client_id, net::ServerId server_id, net::ClientState client_state) |
| 148 | { |
168 | { |
| 149 |
|
169 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
| 150 |
|
170 | |
| 151 |
|
171 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
| 152 | } |
- | |
| 153 | 172 | ||
| 154 | if (client_state == net::CLIENT_STATE_DISCONNECTED) |
173 | if (client_state == net::CLIENT_STATE_DISCONNECTED) |
| 155 | { |
174 | { |
| 156 | LOG.Info("Client " + boost::lexical_cast<std::string>(client_id) + " has disconnected."); |
175 | LOG.Info("Client " + boost::lexical_cast<std::string>(client_id) + " has disconnected."); |
| 157 | } |
176 | } |
| Line 165... | Line 184... | ||
| 165 | } |
184 | } |
| 166 | } |
185 | } |
| 167 | 186 | ||
| 168 | void Console::ExecutionResult(std::string response, unsigned int request_id) |
187 | void Console::ExecutionResult(std::string response, unsigned int request_id) |
| 169 | { |
188 | { |
| - | 189 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
|
| - | 190 | ||
| 170 |
|
191 | LOG.Debug("ExecutionResult: response=" + response + ", request_id=" + boost::lexical_cast<std::string>(request_id)); |
| - | 192 | ||
| 171 | net::Manager::Instance()->SendTo(request_id, response); |
193 | net::Manager::Instance()->SendTo(request_id, response); |
| 172 | } |
194 | } |
| 173 | 195 | ||
| 174 | Value Console::Export_RegisterConsoleCommand(const v8::Arguments& args) |
196 | Value Console::Export_RegisterConsoleCommand(const v8::Arguments& args) |
| 175 | { |
197 | { |
| - | 198 | v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext()); |
|
| - | 199 | ||
| - | 200 | LOG.Debug(std::string(__FUNCTION__) + " called!"); |
|
| - | 201 | ||
| 176 | if (args.Length() < 1) |
202 | if (args.Length() < 1) |
| 177 | { |
203 | { |
| 178 | LOG.Error("To few arguments."); |
204 | LOG.Error("To few arguments."); |
| 179 | } |
205 | } |
| 180 | 206 | ||