Subversion Repositories HomeAutomation

Rev

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

Rev 1740 Rev 1741
Line 106... Line 106...
106
 
106
 
107
void Console::SlotOnNewDataHandler(net::ClientId client_id, net::ServerId server_id, common::Byteset data)
107
void Console::SlotOnNewDataHandler(net::ClientId client_id, net::ServerId server_id, common::Byteset data)
108
{
108
{
109
    v8::Locker lock;
109
    v8::Locker lock;
110
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
110
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
111
    v8::HandleScope handle_scope;
111
 
112
 
112
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
113
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
-
 
114
 
-
 
115
    if (data.GetSize() == 0)
-
 
116
    {
-
 
117
        LOG.Error(std::string(__FUNCTION__) + " got empty data!");
-
 
118
        return;
-
 
119
    }
113
 
120
   
114
    std::string s(data.ToCharString());
121
    std::string s(data.ToCharString());
-
 
122
   
-
 
123
    if (s.length() < 8)
-
 
124
    {
-
 
125
        LOG.Error(std::string(__FUNCTION__) + " got a packet which is to short, less then 8 bytes: \"" + s + "\"");
-
 
126
        return;
-
 
127
    }
115
   
128
   
116
    std::string command = s.substr(0, 4);
129
    std::string command = s.substr(0, 4);
-
 
130
   
-
 
131
    LOG.Debug(std::string(__FUNCTION__) + " parsed command: \"" + command + "\"");
-
 
132
   
-
 
133
    // TODO: Check cast exception!
117
    unsigned int payload_length = boost::lexical_cast<unsigned int>(s.substr(4, 4));
134
    unsigned int payload_length = boost::lexical_cast<unsigned int>(s.substr(4, 4));
-
 
135
 
-
 
136
    LOG.Debug(std::string(__FUNCTION__) + " parsed payload_length: \"" + boost::lexical_cast<std::string>(payload_length) + "\"");
-
 
137
 
118
 
138
   
119
    Console::current_client_id_ = client_id;
139
    Console::current_client_id_ = client_id;
120
   
140
   
121
    if (command == "COMP")
141
    if (command == "COMP")
122
    {
142
    {
123
        ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList);
143
        ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList);
124
       
144
       
125
        call_arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(client_id)));
145
        call_arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(client_id)));
126
        call_arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(s.substr(8, 4))));
146
        call_arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(s.substr(8, 4))));
127
        call_arguments->push_back(v8::String::New(s.substr(12).data()));
147
        call_arguments->push_back(v8::String::New(s.substr(12).data()));
128
       
148
       
129
        if (!this->Call(client_id, "Console_AutocompleteRequest", call_arguments))
149
        if (!this->Call(client_id, "Console_AutocompleteRequest", call_arguments))
130
        {
150
        {
131
            LOG.Error("Console_AutocompleteRequest failed, we are now in an undefined state!");
151
            LOG.Error("Console_AutocompleteRequest failed, we are now in an undefined state!");
132
        }
152
        }
133
    }
153
    }
134
    else if (command == "RESP")
154
    else if (command == "RESP")
135
    {
155
    {
-
 
156
        LOG.Debug(std::string(__FUNCTION__) + " parsed data: \"" + s.substr(8).data() + "\"");
-
 
157
       
136
        ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList);
158
        ArgumentListPointer call_arguments = ArgumentListPointer(new ArgumentList);
137
       
159
       
138
        call_arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(client_id)));
160
        call_arguments->push_back(v8::Integer::New(boost::lexical_cast<unsigned int>(client_id)));
139
        call_arguments->push_back(v8::String::New(s.substr(8).data()));
161
        call_arguments->push_back(v8::String::New(s.substr(8).data()));
140
       
162
       
Line 153... Line 175...
153
 
175
 
154
void Console::SlotOnNewStateHandler(net::ClientId client_id, net::ServerId server_id, net::ClientState client_state)
176
void Console::SlotOnNewStateHandler(net::ClientId client_id, net::ServerId server_id, net::ClientState client_state)
155
{
177
{
156
    v8::Locker lock;
178
    v8::Locker lock;
157
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
179
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
180
    v8::HandleScope handle_scope;
158
 
181
 
159
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
182
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
160
   
183
   
161
    if (client_state == net::CLIENT_STATE_DISCONNECTED)
184
    if (client_state == net::CLIENT_STATE_DISCONNECTED)
162
    {
185
    {
Line 187... Line 210...
187
 
210
 
188
Value Console::Export_PromptRequest(const v8::Arguments& args)
211
Value Console::Export_PromptRequest(const v8::Arguments& args)
189
{
212
{
190
    v8::Locker lock;
213
    v8::Locker lock;
191
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
214
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
215
    v8::HandleScope handle_scope;
192
   
216
   
193
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
217
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
194
   
218
   
195
    if (args.Length() < 2)
219
    if (args.Length() < 2)
196
    {
220
    {
197
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
221
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
198
        return v8::Boolean::New(false);
222
        return handle_scope.Close(v8::Boolean::New(false));
199
    }
223
    }
200
   
224
   
201
    v8::String::AsciiValue prompt(args[1]);
225
    v8::String::AsciiValue prompt(args[1]);
202
   
226
   
203
    std::string packet = "PROM";
227
    std::string packet = "PROM";
204
    packet += common::PadNumber(prompt.length() + 1, 4);
228
    packet += common::PadNumber(prompt.length() + 1, 4);
205
    packet += *prompt;
229
    packet += *prompt;
206
   
230
   
207
    net::Manager::Instance()->SendTo(args[0]->Uint32Value(), packet);
231
    net::Manager::Instance()->SendTo(args[0]->Uint32Value(), packet);
208
    return v8::Boolean::New(true);
232
    return handle_scope.Close(v8::Boolean::New(true));
209
}
233
}
210
 
234
 
211
Value Console::Export_AutoCompleteResponse(const v8::Arguments& args)
235
Value Console::Export_AutoCompleteResponse(const v8::Arguments& args)
212
{
236
{
213
    v8::Locker lock;
237
    v8::Locker lock;
214
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
238
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
239
    v8::HandleScope handle_scope;
215
   
240
   
216
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
241
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
217
   
242
   
218
    if (args.Length() < 2)
243
    if (args.Length() < 2)
219
    {
244
    {
220
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
245
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
221
        return v8::Boolean::New(false);
246
        return handle_scope.Close(v8::Boolean::New(false));
222
    }
247
    }
223
   
248
   
224
    v8::String::AsciiValue result(args[1]);
249
    v8::String::AsciiValue result(args[1]);
225
   
250
   
226
    std::string packet = "COMP";
251
    std::string packet = "COMP";
227
    packet += common::PadNumber(result.length() + 1, 4);
252
    packet += common::PadNumber(result.length() + 1, 4);
228
    packet += *result;
253
    packet += *result;
229
   
254
   
230
    net::Manager::Instance()->SendTo(args[0]->Uint32Value(), packet);
255
    net::Manager::Instance()->SendTo(args[0]->Uint32Value(), packet);
231
    return v8::Boolean::New(true);
256
    return handle_scope.Close(v8::Boolean::New(true));
232
}
257
}
233
 
258
 
234
Value Console::Export_LogToClient(const v8::Arguments& args)
259
Value Console::Export_LogToClient(const v8::Arguments& args)
235
{
260
{
236
    v8::Locker lock;
261
    v8::Locker lock;
237
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
262
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
263
    v8::HandleScope handle_scope;
238
   
264
   
239
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
265
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
240
   
266
   
241
    if (args.Length() < 2)
267
    if (args.Length() < 2)
242
    {
268
    {
243
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
269
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
244
        return v8::Boolean::New(false);
270
        return handle_scope.Close(v8::Boolean::New(false));
245
    }
271
    }
246
   
272
   
247
    v8::String::AsciiValue text(args[1]);
273
    v8::String::AsciiValue text(args[1]);
248
   
274
   
249
    std::string line = *text;
275
    std::string line = *text;
Line 251... Line 277...
251
    std::string packet = "TEXT";
277
    std::string packet = "TEXT";
252
    packet += common::PadNumber(line.length() + 1, 4);
278
    packet += common::PadNumber(line.length() + 1, 4);
253
    packet += line;
279
    packet += line;
254
   
280
   
255
    net::Manager::Instance()->SendTo(args[0]->Uint32Value(), packet);
281
    net::Manager::Instance()->SendTo(args[0]->Uint32Value(), packet);
256
    return v8::Boolean::New(true);
282
    return handle_scope.Close(v8::Boolean::New(true));
257
}
283
}
258
 
284
 
259
Value Console::Export_DisconnectClient(const v8::Arguments& args)
285
Value Console::Export_DisconnectClient(const v8::Arguments& args)
260
{
286
{
261
    v8::Locker lock;
287
    v8::Locker lock;
262
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
288
    v8::Context::Scope context_scope(vm::Manager::Instance()->GetContext());
-
 
289
    v8::HandleScope handle_scope;
263
   
290
   
264
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
291
    //LOG.Debug(std::string(__FUNCTION__) + " called!");
265
   
292
   
266
    if (args.Length() < 1)
293
    if (args.Length() < 1)
267
    {
294
    {
268
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
295
        LOG.Error(std::string(__FUNCTION__) + ": To few arguments.");
269
        return v8::Boolean::New(false);
296
        return handle_scope.Close(v8::Boolean::New(false));
270
    }
297
    }
271
    net::Manager::Instance()->Disconnect(args[0]->Uint32Value());
298
    net::Manager::Instance()->Disconnect(args[0]->Uint32Value());
272
    return v8::Boolean::New(true);
299
    return handle_scope.Close(v8::Boolean::New(true));
273
}
300
}
274
 
301
 
275
}; // namespace plugin
302
}; // namespace plugin
276
}; // namespace vm
303
}; // namespace vm
277
}; // namespace atom
304
}; // namespace atom