Rev 1962 | Rev 1987 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1962 | Rev 1986 | ||
|---|---|---|---|
| Line 63... | Line 63... | ||
| 63 | LOG_DEBUG_ENTER; |
63 | LOG_DEBUG_ENTER; |
| 64 | 64 | ||
| 65 | Plugin::InitializeDone(); |
65 | Plugin::InitializeDone(); |
| 66 | 66 | ||
| 67 | this->ImportFunction("Socket_OnNewData"); |
67 | this->ImportFunction("Socket_OnNewData"); |
| - | 68 | this->ImportFunction("Socket_OnNewClient"); |
|
| 68 | this->ImportFunction("Socket_OnNewState"); |
69 | this->ImportFunction("Socket_OnNewState"); |
| 69 | 70 | ||
| 70 | net::Manager::Instance()->ConnectSlots(net::Manager::SignalOnNewState::slot_type(&Socket::SlotOnNewState, this, _1, |
71 | net::Manager::Instance()->ConnectSlots(net::Manager::SignalOnNewState::slot_type(&Socket::SlotOnNewState, this, _1, _2).track(this->tracker_), net::Manager::SignalOnNewClient::slot_type(&Socket::SlotOnNewClient, this, _1, _2).track(this->tracker_), net::Manager::SignalOnNewData::slot_type(&Socket::SlotOnNewData, this, _1, _2).track(this->tracker_)); |
| 71 | 72 | ||
| 72 | LOG_DEBUG_EXIT; |
73 | LOG_DEBUG_EXIT; |
| 73 | } |
74 | } |
| 74 | 75 | ||
| 75 | void Socket::CallOutput(unsigned int request_id, std::string output) |
76 | void Socket::CallOutput(unsigned int request_id, std::string output) |
| Line 79... | Line 80... | ||
| 79 | log::Info(log_module_, output); |
80 | log::Info(log_module_, output); |
| 80 | 81 | ||
| 81 | //LOG_DEBUG_EXIT; |
82 | //LOG_DEBUG_EXIT; |
| 82 | } |
83 | } |
| 83 | 84 | ||
| 84 | void Socket::SlotOnNewData(net::SocketId |
85 | void Socket::SlotOnNewData(net::SocketId id, common::Byteset data) |
| 85 | { |
86 | { |
| 86 | LOG_DEBUG_ENTER; |
87 | LOG_DEBUG_ENTER; |
| 87 | 88 | ||
| 88 | this->io_service_.post(boost::bind(&Socket::SlotOnNewDataHandler, this, |
89 | this->io_service_.post(boost::bind(&Socket::SlotOnNewDataHandler, this, id, data)); |
| 89 | 90 | ||
| 90 | LOG_DEBUG_EXIT; |
91 | LOG_DEBUG_EXIT; |
| 91 | } |
92 | } |
| 92 | 93 | ||
| 93 | void Socket:: |
94 | void Socket::SlotOnNewClient(net::SocketId id, net::SocketId server_id) |
| 94 | { |
95 | { |
| 95 | LOG_DEBUG_ENTER; |
96 | LOG_DEBUG_ENTER; |
| 96 | 97 | ||
| 97 | this->io_service_.post(boost::bind(&Socket:: |
98 | this->io_service_.post(boost::bind(&Socket::SlotOnNewClientHandler, this, id, server_id)); |
| 98 | 99 | ||
| 99 | LOG_DEBUG_EXIT; |
100 | LOG_DEBUG_EXIT; |
| 100 | } |
101 | } |
| 101 | 102 | ||
| 102 | void Socket:: |
103 | void Socket::SlotOnNewState(net::SocketId id, net::ClientState client_state) |
| 103 | { |
104 | { |
| 104 | LOG_DEBUG_ENTER; |
105 | LOG_DEBUG_ENTER; |
| - | 106 | ||
| - | 107 | this->io_service_.post(boost::bind(&Socket::SlotOnNewStateHandler, this, id, client_state)); |
|
| - | 108 | ||
| - | 109 | LOG_DEBUG_EXIT; |
|
| - | 110 | } |
|
| - | 111 | ||
| - | 112 | void Socket::SlotOnNewDataHandler(net::SocketId id, common::Byteset data) |
|
| - | 113 | { |
|
| - | 114 | LOG_DEBUG_ENTER; |
|
| 105 | ATOM_VM_PLUGIN_SCOPE; |
115 | ATOM_VM_PLUGIN_SCOPE; |
| 106 | 116 | ||
| 107 | try |
117 | try |
| 108 | { |
118 | { |
| 109 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
119 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
| 110 | 120 | ||
| 111 | if (data.GetSize() == 0) |
121 | if (data.GetSize() == 0) |
| 112 | { |
122 | { |
| 113 | atom::log::Error(log_module_, "Got empty data!"); |
123 | atom::log::Error(log_module_, "Got empty data!"); |
| 114 | return; |
124 | return; |
| 115 | } |
125 | } |
| 116 | 126 | ||
| 117 | arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>( |
127 | arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(id))); |
| - | 128 | arguments->push_back(v8::String::New(data.ToCharString().c_str())); |
|
| - | 129 | ||
| - | 130 | if (!this->Call(id, "Socket_OnNewData", arguments)) |
|
| - | 131 | { |
|
| - | 132 | atom::log::Error(log_module_, "%s failed!", __FUNCTION__); |
|
| - | 133 | } |
|
| - | 134 | } |
|
| - | 135 | catch (std::exception& exception) |
|
| - | 136 | { |
|
| - | 137 | atom::log::Exception(log_module_, exception); |
|
| - | 138 | } |
|
| - | 139 | ||
| - | 140 | LOG_DEBUG_EXIT; |
|
| - | 141 | } |
|
| - | 142 | ||
| - | 143 | void Socket::SlotOnNewClientHandler(net::SocketId id, net::SocketId server_id) |
|
| - | 144 | { |
|
| - | 145 | LOG_DEBUG_ENTER; |
|
| - | 146 | ATOM_VM_PLUGIN_SCOPE; |
|
| - | 147 | ||
| - | 148 | try |
|
| - | 149 | { |
|
| - | 150 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
|
| - | 151 | ||
| 118 | arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>( |
152 | arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(id))); |
| 119 | arguments->push_back(v8:: |
153 | arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(server_id))); |
| 120 | 154 | ||
| 121 | if (!this->Call( |
155 | if (!this->Call(id, "Socket_OnNewClient", arguments)) |
| 122 | { |
156 | { |
| 123 | atom::log::Error(log_module_, "%s failed!", __FUNCTION__); |
157 | atom::log::Error(log_module_, "%s failed!", __FUNCTION__); |
| 124 | } |
158 | } |
| 125 | } |
159 | } |
| 126 | catch (std::exception& exception) |
160 | catch (std::exception& exception) |
| 127 | { |
161 | { |
| 128 | atom::log::Exception(log_module_, exception); |
162 | atom::log::Exception(log_module_, exception); |
| 129 | } |
163 | } |
| 130 | 164 | ||
| 131 | LOG_DEBUG_EXIT; |
165 | LOG_DEBUG_EXIT; |
| 132 | } |
166 | } |
| - | 167 | ||
| 133 | 168 | ||
| 134 | void Socket::SlotOnNewStateHandler(net::SocketId |
169 | void Socket::SlotOnNewStateHandler(net::SocketId id, net::ClientState client_state) |
| 135 | { |
170 | { |
| 136 | LOG_DEBUG_ENTER; |
171 | LOG_DEBUG_ENTER; |
| 137 | ATOM_VM_PLUGIN_SCOPE; |
172 | ATOM_VM_PLUGIN_SCOPE; |
| 138 | 173 | ||
| 139 | try |
174 | try |
| 140 | { |
175 | { |
| 141 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
176 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
| 142 | 177 | ||
| 143 | arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(socket_id))); |
- | |
| 144 | arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>( |
178 | arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(id))); |
| 145 | arguments->push_back(v8::Uint32::New((unsigned int)client_state)); |
179 | arguments->push_back(v8::Uint32::New((unsigned int)client_state)); |
| 146 | 180 | ||
| 147 | if (!this->Call( |
181 | if (!this->Call(id, "Socket_OnNewState", arguments)) |
| 148 | { |
182 | { |
| 149 | atom::log::Error(log_module_, "%s failed!", __FUNCTION__); |
183 | atom::log::Error(log_module_, "%s failed!", __FUNCTION__); |
| 150 | } |
184 | } |
| 151 | } |
185 | } |
| 152 | catch (std::exception& exception) |
186 | catch (std::exception& exception) |
| 153 | { |
- | |
| 154 | atom::log::Exception(log_module_, exception); |
- | |
| 155 | } |
- | |
| 156 | - | ||
| 157 | LOG_DEBUG_EXIT; |
- | |
| 158 | } |
- | |
| 159 | - | ||
| 160 | Value Socket::Export_StartServer(const v8::Arguments& args) |
- | |
| 161 | { |
- | |
| 162 | LOG_DEBUG_ENTER |
- | |
| 163 | ATOM_VM_PLUGIN_SCOPE; |
- | |
| 164 | - | ||
| 165 | net::SocketId socket_id = 0; |
- | |
| 166 | - | ||
| 167 | try |
- | |
| 168 | { |
- | |
| 169 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
- | |
| 170 | - | ||
| 171 | if (args.Length() < 1) |
- | |
| 172 | { |
187 | { |
| - | 188 | atom::log::Exception(log_module_, exception); |
|
| - | 189 | } |
|
| - | 190 | ||
| - | 191 | LOG_DEBUG_EXIT; |
|
| - | 192 | } |
|
| - | 193 | ||
| - | 194 | Value Socket::Export_StartServer(const v8::Arguments& args) |
|
| - | 195 | { |
|
| - | 196 | LOG_DEBUG_ENTER |
|
| - | 197 | ATOM_VM_PLUGIN_SCOPE; |
|
| - | 198 | ||
| - | 199 | net::SocketId socket_id = 0; |
|
| - | 200 | ||
| - | 201 | try |
|
| - | 202 | { |
|
| - | 203 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
|
| - | 204 | ||
| - | 205 | if (args.Length() < 1) |
|
| - | 206 | { |
|
| 173 | throw atom::exception::missing_in_param(); |
207 | throw atom::exception::missing_in_param(); |
| 174 | } |
208 | } |
| 175 | 209 | ||
| 176 | socket_id = net::Manager::Instance()->StartServer(net::PROTOCOL_TCP, args[0]->Uint32Value()); |
210 | socket_id = net::Manager::Instance()->StartServer(net::PROTOCOL_TCP, args[0]->Uint32Value()); |
| 177 | } |
211 | } |
| 178 | catch (std::exception& exception) |
212 | catch (std::exception& exception) |
| Line 190... | Line 224... | ||
| 190 | LOG_DEBUG_ENTER; |
224 | LOG_DEBUG_ENTER; |
| 191 | ATOM_VM_PLUGIN_SCOPE; |
225 | ATOM_VM_PLUGIN_SCOPE; |
| 192 | 226 | ||
| 193 | net::SocketId socket_id = 0; |
227 | net::SocketId socket_id = 0; |
| 194 | 228 | ||
| 195 | try |
229 | try |
| 196 | { |
230 | { |
| 197 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
231 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
| 198 | 232 | ||
| 199 | if (args.Length() < 2) |
233 | if (args.Length() < 2) |
| 200 | { |
234 | { |
| 201 | throw atom::exception::missing_in_param(); |
235 | throw atom::exception::missing_in_param(); |
| 202 | } |
236 | } |
| 203 | 237 | ||
| 204 | v8::String::AsciiValue address(args[0]); |
238 | v8::String::AsciiValue address(args[0]); |
| 205 | 239 | ||
| 206 | socket_id = net::Manager::Instance()->Connect(net::PROTOCOL_TCP, std::string(*address), args[1]->Uint32Value()); |
240 | socket_id = net::Manager::Instance()->Connect(net::PROTOCOL_TCP, std::string(*address), args[1]->Uint32Value()); |
| 207 | } |
241 | } |
| 208 | catch (std::exception& exception) |
242 | catch (std::exception& exception) |
| 209 | { |
243 | { |
| 210 | atom::log::Exception(log_module_, exception); |
244 | atom::log::Exception(log_module_, exception); |
| 211 | return handle_scope.Close(v8::Boolean::New(false)); |
245 | return handle_scope.Close(v8::Boolean::New(false)); |
| 212 | } |
246 | } |
| 213 | 247 | ||
| 214 | LOG_DEBUG_EXIT; |
248 | LOG_DEBUG_EXIT; |
| 215 | return handle_scope.Close(v8::Integer::New(socket_id)); |
249 | return handle_scope.Close(v8::Integer::New(socket_id)); |
| 216 | } |
250 | } |
| 217 | 251 | ||
| 218 | Value Socket::Export_StopServer(const v8::Arguments& args) |
252 | Value Socket::Export_StopServer(const v8::Arguments& args) |
| 219 | { |
253 | { |
| 220 | LOG_DEBUG_EXIT; |
254 | LOG_DEBUG_EXIT; |
| 221 | ATOM_VM_PLUGIN_SCOPE; |
255 | ATOM_VM_PLUGIN_SCOPE; |
| 222 | 256 | ||
| 223 | try |
257 | try |
| 224 | { |
258 | { |
| 225 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
259 | ArgumentListPointer arguments = ArgumentListPointer(new ArgumentList); |
| 226 | 260 | ||
| 227 | if (args.Length() < 1) |
261 | if (args.Length() < 1) |
| 228 | { |
262 | { |
| 229 | throw atom::exception::missing_in_param(); |
263 | throw atom::exception::missing_in_param(); |
| 230 | } |
264 | } |
| 231 | 265 | ||
| 232 | net::Manager::Instance()->StopServer(args[0]->Uint32Value()); |
266 | net::Manager::Instance()->StopServer(args[0]->Uint32Value()); |
| 233 | } |
267 | } |
| 234 | catch (std::exception& exception) |
268 | catch (std::exception& exception) |
| 235 | { |
269 | { |
| 236 | atom::log::Exception(log_module_, exception); |
270 | atom::log::Exception(log_module_, exception); |
| 237 | return handle_scope.Close(v8::Boolean::New(false)); |
271 | return handle_scope.Close(v8::Boolean::New(false)); |
| 238 | } |
272 | } |
| 239 | 273 | ||
| 240 | LOG_DEBUG_EXIT; |
274 | LOG_DEBUG_EXIT; |
| 241 | return handle_scope.Close(v8::Boolean::New(true)); |
275 | return handle_scope.Close(v8::Boolean::New(true)); |
| 242 | } |
276 | } |
| 243 | 277 | ||
| 244 | Value Socket::Export_Disconnect(const v8::Arguments& args) |
278 | Value Socket::Export_Disconnect(const v8::Arguments& args) |
| 245 | { |
279 | { |
| 246 | LOG_DEBUG_EXIT; |
280 | LOG_DEBUG_EXIT; |
| Line 280... | Line 314... | ||
| 280 | { |
314 | { |
| 281 | throw atom::exception::missing_in_param(); |
315 | throw atom::exception::missing_in_param(); |
| 282 | } |
316 | } |
| 283 | 317 | ||
| 284 | v8::String::AsciiValue data(args[1]); |
318 | v8::String::AsciiValue data(args[1]); |
| - | 319 | ||
| - | 320 | atom::log::Debug(log_module_, "Socket %u send %s", args[0]->Uint32Value(), *data); |
|
| 285 | 321 | ||
| 286 | net::Manager::Instance()->SendTo(args[0]->Uint32Value(), std::string(*data)); |
322 | net::Manager::Instance()->SendTo(args[0]->Uint32Value(), std::string(*data)); |
| 287 | } |
323 | } |
| 288 | catch (std::exception& exception) |
324 | catch (std::exception& exception) |
| 289 | { |
325 | { |