Mercurial > hg > orthanc
comparison OrthancServer/LuaScripting.cpp @ 2651:1da5a052c777 jobs
testing value serialization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 04 Jun 2018 11:53:12 +0200 |
parents | 193ef9c1b731 |
children | 389d050a2e66 |
comparison
equal
deleted
inserted
replaced
2650:5f2dd8b6ee2f | 2651:1da5a052c777 |
---|---|
514 } | 514 } |
515 | 515 |
516 | 516 |
517 LuaScripting::LuaScripting(ServerContext& context) : | 517 LuaScripting::LuaScripting(ServerContext& context) : |
518 context_(context), | 518 context_(context), |
519 continue_(true) | 519 state_(State_Setup) |
520 { | 520 { |
521 lua_.SetGlobalVariable("_ServerContext", &context); | 521 lua_.SetGlobalVariable("_ServerContext", &context); |
522 lua_.RegisterFunction("RestApiGet", RestApiGet); | 522 lua_.RegisterFunction("RestApiGet", RestApiGet); |
523 lua_.RegisterFunction("RestApiPost", RestApiPost); | 523 lua_.RegisterFunction("RestApiPost", RestApiPost); |
524 lua_.RegisterFunction("RestApiPut", RestApiPut); | 524 lua_.RegisterFunction("RestApiPut", RestApiPut); |
527 } | 527 } |
528 | 528 |
529 | 529 |
530 LuaScripting::~LuaScripting() | 530 LuaScripting::~LuaScripting() |
531 { | 531 { |
532 if (continue_) | 532 if (state_ == State_Running) |
533 { | 533 { |
534 LOG(ERROR) << "INTERNAL ERROR: LuaScripting::Stop() should be invoked manually to avoid mess in the destruction order!"; | 534 LOG(ERROR) << "INTERNAL ERROR: LuaScripting::Stop() should be invoked manually to avoid mess in the destruction order!"; |
535 Stop(); | 535 Stop(); |
536 } | 536 } |
537 } | 537 } |
546 if (event.get() == NULL) | 546 if (event.get() == NULL) |
547 { | 547 { |
548 // The event queue is empty, check whether we should stop | 548 // The event queue is empty, check whether we should stop |
549 boost::recursive_mutex::scoped_lock lock(that->mutex_); | 549 boost::recursive_mutex::scoped_lock lock(that->mutex_); |
550 | 550 |
551 if (!that->continue_) | 551 if (that->state_ != State_Running) |
552 { | 552 { |
553 return; | 553 return; |
554 } | 554 } |
555 } | 555 } |
556 else | 556 else |
570 | 570 |
571 void LuaScripting::Start() | 571 void LuaScripting::Start() |
572 { | 572 { |
573 boost::recursive_mutex::scoped_lock lock(mutex_); | 573 boost::recursive_mutex::scoped_lock lock(mutex_); |
574 | 574 |
575 if (!continue_ || | 575 if (state_ != State_Setup || |
576 eventThread_.joinable() /* already started */) | 576 eventThread_.joinable() /* already started */) |
577 { | 577 { |
578 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 578 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
579 } | 579 } |
580 else | 580 else |
588 void LuaScripting::Stop() | 588 void LuaScripting::Stop() |
589 { | 589 { |
590 { | 590 { |
591 boost::recursive_mutex::scoped_lock lock(mutex_); | 591 boost::recursive_mutex::scoped_lock lock(mutex_); |
592 | 592 |
593 if (!continue_) | 593 if (state_ != State_Running) |
594 { | 594 { |
595 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 595 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
596 } | 596 } |
597 | 597 |
598 continue_ = false; | 598 state_ = State_Done; |
599 } | 599 } |
600 | 600 |
601 jobManager_.AwakeTrailingSleep(); | 601 jobManager_.AwakeTrailingSleep(); |
602 | 602 |
603 if (eventThread_.joinable()) | 603 if (eventThread_.joinable()) |