Rev 1026 | Rev 1060 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1026 | Rev 1042 | ||
|---|---|---|---|
| Line 81... | Line 81... | ||
| 81 | myGlobal->Set(String::New("sendCanMessage"), FunctionTemplate::New(VirtualMachine::_sendCanMessage)); |
81 | myGlobal->Set(String::New("sendCanMessage"), FunctionTemplate::New(VirtualMachine::_sendCanMessage)); |
| 82 | myGlobal->Set(String::New("sendCanNMTMessage"), FunctionTemplate::New(VirtualMachine::_sendCanNMTMessage)); |
82 | myGlobal->Set(String::New("sendCanNMTMessage"), FunctionTemplate::New(VirtualMachine::_sendCanNMTMessage)); |
| 83 | myGlobal->Set(String::New("loadScript"), FunctionTemplate::New(VirtualMachine::_loadScript)); |
83 | myGlobal->Set(String::New("loadScript"), FunctionTemplate::New(VirtualMachine::_loadScript)); |
| 84 | myGlobal->Set(String::New("startIntervalThread"), FunctionTemplate::New(VirtualMachine::_startIntervalThread)); |
84 | myGlobal->Set(String::New("startIntervalThread"), FunctionTemplate::New(VirtualMachine::_startIntervalThread)); |
| 85 | myGlobal->Set(String::New("stopIntervalThread"), FunctionTemplate::New(VirtualMachine::_stopIntervalThread)); |
85 | myGlobal->Set(String::New("stopIntervalThread"), FunctionTemplate::New(VirtualMachine::_stopIntervalThread)); |
| - | 86 | myGlobal->Set(String::New("setIntervalThreadTimeout"), FunctionTemplate::New(VirtualMachine::_setIntervalThreadTimeout)); |
|
| 86 | myGlobal->Set(String::New("startSocketThread"), FunctionTemplate::New(VirtualMachine::_startSocketThread)); |
87 | myGlobal->Set(String::New("startSocketThread"), FunctionTemplate::New(VirtualMachine::_startSocketThread)); |
| 87 | myGlobal->Set(String::New("stopSocketThread"), FunctionTemplate::New(VirtualMachine::_stopSocketThread)); |
88 | myGlobal->Set(String::New("stopSocketThread"), FunctionTemplate::New(VirtualMachine::_stopSocketThread)); |
| 88 | myGlobal->Set(String::New("sendToSocketThread"), FunctionTemplate::New(VirtualMachine::_sendToSocketThread)); |
89 | myGlobal->Set(String::New("sendToSocketThread"), FunctionTemplate::New(VirtualMachine::_sendToSocketThread)); |
| 89 | myGlobal->Set(String::New("loadDataStore"), FunctionTemplate::New(VirtualMachine::_loadDataStore)); |
90 | myGlobal->Set(String::New("loadDataStore"), FunctionTemplate::New(VirtualMachine::_loadDataStore)); |
| 90 | myGlobal->Set(String::New("getFileContents"), FunctionTemplate::New(VirtualMachine::_getFileContents)); |
91 | myGlobal->Set(String::New("getFileContents"), FunctionTemplate::New(VirtualMachine::_getFileContents)); |
| Line 293... | Line 294... | ||
| 293 | 294 | ||
| 294 | bool VirtualMachine::stopIntervalThread(unsigned int id) |
295 | bool VirtualMachine::stopIntervalThread(unsigned int id) |
| 295 | { |
296 | { |
| 296 | if (myIntervalThreads.find(id) != myIntervalThreads.end()) |
297 | if (myIntervalThreads.find(id) != myIntervalThreads.end()) |
| 297 | { |
298 | { |
| - | 299 | myIntervalThreads[id]->stop(); |
|
| 298 | delete myIntervalThreads[id]; |
300 | delete myIntervalThreads[id]; |
| 299 | myIntervalThreads.erase(id); |
301 | myIntervalThreads.erase(id); |
| - | 302 | ||
| 300 | return true; |
303 | return true; |
| - | 304 | } |
|
| - | 305 | ||
| - | 306 | return false; |
|
| - | 307 | } |
|
| - | 308 | ||
| - | 309 | bool VirtualMachine::setIntervalThreadTimeout(unsigned int id, unsigned int timeout) |
|
| - | 310 | { |
|
| - | 311 | if (myIntervalThreads.find(id) != myIntervalThreads.end()) |
|
| - | 312 | { |
|
| - | 313 | myIntervalThreads[id]->setTimeout(timeout); |
|
| - | 314 | return true; |
|
| 301 | } |
315 | } |
| 302 | 316 | ||
| 303 | return false; |
317 | return false; |
| 304 | } |
318 | } |
| 305 | 319 | ||
| 306 | unsigned int VirtualMachine::startSocketThread(string address, int port, unsigned int reconnectTimeout) |
320 | unsigned int VirtualMachine::startSocketThread(string address, int port, unsigned int reconnectTimeout) |
| 307 | { |
321 | { |
| 308 | SocketThread *socketThread = new SocketThread(address, port, reconnectTimeout); |
322 | SocketThread *socketThread = new SocketThread(address, port, reconnectTimeout); |
| 309 | mySocketThreads[socketThread->getId()] = socketThread; |
323 | mySocketThreads[socketThread->getId()] = socketThread; |
| 310 | mySocketThreads[socketThread->getId()]->start(); |
324 | mySocketThreads[socketThread->getId()]->start(); |
| 311 | 325 | ||
| 312 | return socketThread->getId(); |
326 | return socketThread->getId(); |
| 313 | } |
327 | } |
| 314 | 328 | ||
| 315 | bool VirtualMachine::stopSocketThread(unsigned int id) |
329 | bool VirtualMachine::stopSocketThread(unsigned int id) |
| 316 | { |
330 | { |
| 317 | if (mySocketThreads.find(id) != mySocketThreads.end()) |
331 | if (mySocketThreads.find(id) != mySocketThreads.end()) |
| 318 | { |
332 | { |
| 319 | delete mySocketThreads[id]; |
333 | delete mySocketThreads[id]; |
| Line 323... | Line 337... | ||
| 323 | 337 | ||
| 324 | return false; |
338 | return false; |
| 325 | } |
339 | } |
| 326 | 340 | ||
| 327 | void VirtualMachine::sendToSocketThread(unsigned int id, string data) |
341 | void VirtualMachine::sendToSocketThread(unsigned int id, string data) |
| 328 | { |
342 | { |
| 329 | if (mySocketThreads.find(id) != mySocketThreads.end()) |
343 | if (mySocketThreads.find(id) != mySocketThreads.end()) |
| 330 | { |
344 | { |
| 331 | mySocketThreads[id]->send(data); |
345 | mySocketThreads[id]->send(data); |
| 332 | } |
346 | } |
| 333 | } |
347 | } |
| 334 | 348 | ||
| 335 | void VirtualMachine::disconnectCommandClient(unsigned int id) |
349 | void VirtualMachine::disconnectCommandClient(unsigned int id) |
| 336 | { |
350 | { |
| 337 | myCommandThread.disconnectClient(id); |
351 | myCommandThread.disconnectClient(id); |
| 338 | } |
352 | } |
| 339 | 353 | ||
| 340 | void VirtualMachine::sendToCommandClient(unsigned int id, string data) |
354 | void VirtualMachine::sendToCommandClient(unsigned int id, string data) |
| 341 | { |
355 | { |
| 342 | myCommandThread.sendTo(id, data); |
356 | myCommandThread.sendTo(id, data); |
| 343 | } |
357 | } |
| 344 | 358 | ||
| 345 | void VirtualMachine::print(unsigned int id, string data) |
359 | void VirtualMachine::print(unsigned int id, string data) |
| 346 | { |
360 | { |
| 347 | if (id == 0) |
361 | if (id == 0) |
| 348 | { |
362 | { |
| 349 | Logger &log = Logger::getInstance(); |
363 | Logger &log = Logger::getInstance(); |
| 350 | log.add(data); |
364 | log.add(data); |
| 351 | } |
365 | } |
| 352 | else |
366 | else |
| 353 | { |
367 | { |
| 354 | VirtualMachine &vm = VirtualMachine::getInstance(); |
368 | VirtualMachine &vm = VirtualMachine::getInstance(); |
| 355 | vm.sendToCommandClient(id, data); |
369 | vm.sendToCommandClient(id, data); |
| 356 | } |
370 | } |
| 357 | } |
371 | } |
| 358 | 372 | ||
| 359 | bool VirtualMachine::runExpression(Expression expression) |
373 | bool VirtualMachine::runExpression(Expression expression) |
| 360 | { |
374 | { |
| 361 | string scriptName = "runExpression"; |
375 | string scriptName = "runExpression"; |
| 362 | 376 | ||
| Line 381... | Line 395... | ||
| 381 | else |
395 | else |
| 382 | { |
396 | { |
| 383 | Handle<Value> result = script->Run(); |
397 | Handle<Value> result = script->Run(); |
| 384 | 398 | ||
| 385 | if (result.IsEmpty()) |
399 | if (result.IsEmpty()) |
| 386 | { |
400 | { |
| 387 | print(expression.getTargetId(), formatException(&tryCatch)); |
401 | print(expression.getTargetId(), formatException(&tryCatch)); |
| 388 | return false; |
402 | return false; |
| 389 | } |
403 | } |
| 390 | else if (expression.getTargetId() != 0) |
404 | else if (expression.getTargetId() != 0) |
| 391 | { |
405 | { |
| 392 | String::AsciiValue ascii(result); |
406 | String::AsciiValue ascii(result); |
| 393 | string resultString = *ascii; |
407 | string resultString = *ascii; |
| 394 | 408 | ||
| 395 | if (resultString != "undefined") |
409 | if (resultString != "undefined") |
| 396 | { |
410 | { |
| 397 | print(expression.getTargetId(), resultString + "\n"); |
411 | print(expression.getTargetId(), resultString + "\n"); |
| 398 | } |
412 | } |
| 399 | } |
413 | } |
| 400 | } |
414 | } |
| 401 | 415 | ||
| 402 | return true; |
416 | return true; |
| 403 | } |
417 | } |
| 404 | 418 | ||
| 405 | 419 | ||
| 406 | Handle<Value> VirtualMachine::_quit(const Arguments& args) |
420 | Handle<Value> VirtualMachine::_quit(const Arguments& args) |
| 407 | { |
421 | { |
| 408 | VirtualMachine &vm = VirtualMachine::getInstance(); |
422 | VirtualMachine &vm = VirtualMachine::getInstance(); |
| 409 | 423 | ||
| 410 | vm.disconnectCommandClient(args[0]->Uint32Value()); |
424 | vm.disconnectCommandClient(args[0]->Uint32Value()); |
| 411 | 425 | ||
| 412 | return Undefined(); |
426 | return Undefined(); |
| 413 | } |
427 | } |
| 414 | 428 | ||
| 415 | Handle<Value> VirtualMachine::_log(const Arguments& args) |
429 | Handle<Value> VirtualMachine::_log(const Arguments& args) |
| 416 | { |
430 | { |
| 417 | Logger &log = Logger::getInstance(); |
431 | Logger &log = Logger::getInstance(); |
| 418 | 432 | ||
| 419 | String::AsciiValue str(args[0]); |
433 | String::AsciiValue str(args[0]); |
| 420 | 434 | ||
| 421 | log.add(*str); |
435 | log.add(*str); |
| 422 | 436 | ||
| 423 | return Undefined(); |
437 | return Undefined(); |
| 424 | } |
438 | } |
| 425 | 439 | ||
| 426 | Handle<Value> VirtualMachine::_print(const Arguments& args) |
440 | Handle<Value> VirtualMachine::_print(const Arguments& args) |
| 427 | { |
441 | { |
| 428 | VirtualMachine &vm = VirtualMachine::getInstance(); |
442 | VirtualMachine &vm = VirtualMachine::getInstance(); |
| 429 | 443 | ||
| 430 | String::AsciiValue str(args[1]); |
444 | String::AsciiValue str(args[1]); |
| 431 | 445 | ||
| 432 | vm.print(args[0]->Uint32Value(), *str); |
446 | vm.print(args[0]->Uint32Value(), *str); |
| 433 | 447 | ||
| 434 | return Undefined(); |
448 | return Undefined(); |
| 435 | } |
449 | } |
| 436 | 450 | ||
| 437 | Handle<Value> VirtualMachine::_sendCanMessage(const Arguments& args) |
451 | Handle<Value> VirtualMachine::_sendCanMessage(const Arguments& args) |
| 438 | { |
452 | { |
| 439 | CanNetManager &canMan = CanNetManager::getInstance(); |
453 | CanNetManager &canMan = CanNetManager::getInstance(); |
| 440 | 454 | ||
| 441 | CanMessage canMessage; |
455 | CanMessage canMessage; |
| 442 | 456 | ||
| 443 | String::AsciiValue className(args[0]); |
457 | String::AsciiValue className(args[0]); |
| 444 | canMessage.setClassName(*className); |
458 | canMessage.setClassName(*className); |
| 445 | String::AsciiValue directionFlag(args[1]); |
459 | String::AsciiValue directionFlag(args[1]); |
| 446 | canMessage.setDirectionFlag(*directionFlag); |
460 | canMessage.setDirectionFlag(*directionFlag); |
| 447 | String::AsciiValue moduleName(args[2]); |
461 | String::AsciiValue moduleName(args[2]); |
| 448 | canMessage.setModuleName(*moduleName); |
462 | canMessage.setModuleName(*moduleName); |
| Line 495... | Line 509... | ||
| 495 | canMessage.setData(data); |
509 | canMessage.setData(data); |
| 496 | 510 | ||
| 497 | canMan.sendMessage(canMessage); |
511 | canMan.sendMessage(canMessage); |
| 498 | 512 | ||
| 499 | return Undefined(); |
513 | return Undefined(); |
| 500 | } |
514 | } |
| 501 | 515 | ||
| 502 | Handle<Value> VirtualMachine::_loadScript(const Arguments& args) |
516 | Handle<Value> VirtualMachine::_loadScript(const Arguments& args) |
| 503 | { |
517 | { |
| 504 | VirtualMachine &vm = VirtualMachine::getInstance(); |
518 | VirtualMachine &vm = VirtualMachine::getInstance(); |
| 505 | 519 | ||
| 506 | String::AsciiValue str(args[0]); |
520 | String::AsciiValue str(args[0]); |
| 507 | 521 | ||
| 508 | return Boolean::New(vm.loadScript(*str)); |
522 | return Boolean::New(vm.loadScript(*str)); |
| 509 | } |
523 | } |
| 510 | 524 | ||
| 511 | Handle<Value> VirtualMachine::_loadDataStore(const Arguments& args) |
525 | Handle<Value> VirtualMachine::_loadDataStore(const Arguments& args) |
| 512 | { |
526 | { |
| 513 | VirtualMachine &vm = VirtualMachine::getInstance(); |
527 | VirtualMachine &vm = VirtualMachine::getInstance(); |
| 514 | 528 | ||
| 515 | String::AsciiValue str(args[0]); |
529 | String::AsciiValue str(args[0]); |
| 516 | 530 | ||
| 517 | return Boolean::New(vm.loadDataStore(*str)); |
531 | return Boolean::New(vm.loadDataStore(*str)); |
| 518 | } |
532 | } |
| 519 | 533 | ||
| 520 | Handle<Value> VirtualMachine::_startIntervalThread(const Arguments& args) |
534 | Handle<Value> VirtualMachine::_startIntervalThread(const Arguments& args) |
| 521 | { |
535 | { |
| 522 | VirtualMachine &vm = VirtualMachine::getInstance(); |
536 | VirtualMachine &vm = VirtualMachine::getInstance(); |
| 523 | return Integer::New(vm.startIntervalThread(args[0]->Uint32Value())); |
537 | return Integer::New(vm.startIntervalThread(args[0]->Uint32Value())); |
| 524 | } |
538 | } |
| 525 | 539 | ||
| 526 | Handle<Value> VirtualMachine::_stopIntervalThread(const Arguments& args) |
540 | Handle<Value> VirtualMachine::_stopIntervalThread(const Arguments& args) |
| - | 541 | { |
|
| - | 542 | VirtualMachine &vm = VirtualMachine::getInstance(); |
|
| - | 543 | return Boolean::New(vm.stopIntervalThread(args[0]->Uint32Value())); |
|
| - | 544 | } |
|
| - | 545 | ||
| - | 546 | Handle<Value> VirtualMachine::_setIntervalThreadTimeout(const Arguments& args) |
|
| 527 | { |
547 | { |
| 528 | VirtualMachine &vm = VirtualMachine::getInstance(); |
548 | VirtualMachine &vm = VirtualMachine::getInstance(); |
| 529 | return |
549 | return Integer::New(vm.setIntervalThreadTimeout(args[0]->Uint32Value(), args[1]->Uint32Value())); |
| 530 | } |
550 | } |
| 531 | 551 | ||
| 532 | Handle<Value> VirtualMachine::_startSocketThread(const Arguments& args) |
552 | Handle<Value> VirtualMachine::_startSocketThread(const Arguments& args) |
| 533 | { |
553 | { |
| 534 | VirtualMachine &vm = VirtualMachine::getInstance(); |
554 | VirtualMachine &vm = VirtualMachine::getInstance(); |