From e7db6d8028fca5ecfa215ee9adcebdb7879f39de Mon Sep 17 00:00:00 2001 From: Benoit Foucher Date: Thu, 20 Dec 2018 15:44:30 +0100 Subject: Minor simplifications of C++ test controllers --- cpp/test/uwp/controller/ControllerView.xaml.cpp | 82 +++++++++++-------------- 1 file changed, 37 insertions(+), 45 deletions(-) (limited to 'cpp/test/uwp/controller/ControllerView.xaml.cpp') diff --git a/cpp/test/uwp/controller/ControllerView.xaml.cpp b/cpp/test/uwp/controller/ControllerView.xaml.cpp index 6d8951d7b1b..4d17ef2960b 100644 --- a/cpp/test/uwp/controller/ControllerView.xaml.cpp +++ b/cpp/test/uwp/controller/ControllerView.xaml.cpp @@ -47,21 +47,20 @@ public: ControllerHelperI(const string&, const StringSeq&); - virtual bool redirect() const; - - virtual std::string getOutput() const; virtual std::string loggerPrefix() const; - virtual void join(); virtual void print(const std::string&); virtual void serverReady(); - virtual void shutdown(); - - virtual int waitSuccess(int) const; - virtual void waitReady(int) const; + virtual void communicatorInitialized(const shared_ptr&); void run(); void completed(int); + int waitSuccess(int) const; + void waitReady(int) const; + std::string getOutput() const; + void join(); + void shutdown(); + private: string _dll; @@ -79,7 +78,7 @@ private: static std::map _dlls; HINSTANCE loadDll(const string&); - unique_ptr _helper; + shared_ptr _communicator; }; std::map ControllerHelperI::_dlls; @@ -88,7 +87,7 @@ class ProcessI : public Process { public: - ProcessI(const Test::ControllerHelperPtr&); + ProcessI(const shared_ptr&); void waitReady(int, const Ice::Current&); int waitSuccess(int, const Ice::Current&); @@ -96,7 +95,7 @@ public: private: - Test::ControllerHelperPtr _controllerHelper; + shared_ptr _controllerHelper; }; class ProcessControllerI : public ProcessController @@ -122,7 +121,7 @@ public: void registerProcessController(ControllerView^, - const Ice::ObjectAdapterPtr&, + const shared_ptr&, const shared_ptr&, const shared_ptr&); @@ -143,6 +142,18 @@ ControllerHelperI::ControllerHelperI(const string& dll, const StringSeq& args) : { } +string +ControllerHelperI::loggerPrefix() const +{ + return _dll; +} + +void +ControllerHelperI::print(const std::string& msg) +{ + _out << msg; +} + void ControllerHelperI::serverReady() { @@ -151,17 +162,11 @@ ControllerHelperI::serverReady() _condition.notify_all(); } -bool -ControllerHelperI::redirect() const -{ - return _dll.find("client") != string::npos || _dll.find("collocated") != string::npos; -} - void - -ControllerHelperI::print(const std::string& msg) +ControllerHelperI::communicatorInitialized(const shared_ptr& communicator) { - _out << msg; + unique_lock lock(_mutex); + _communicator = communicator; } void @@ -196,10 +201,11 @@ ControllerHelperI::run() argv[_args.size()] = 0; try { - StreamHelper streamHelper(this, redirect()); - _helper.reset(createHelper()); - _helper->setControllerHelper(this); - _helper->run(static_cast(_args.size()), argv); + StreamHelper streamHelper(this, + _dll.find("client") != string::npos || _dll.find("collocated") != string::npos); + auto helper = unique_ptr(createHelper()); + helper->setControllerHelper(this); + helper->run(static_cast(_args.size()), argv); completed(0); } catch(const std::exception& ex) @@ -229,6 +235,7 @@ ControllerHelperI::completed(int status) unique_lock lock(_mutex); _completed = true; _status = status; + _communicator = nullptr; _condition.notify_all(); } @@ -270,28 +277,13 @@ ControllerHelperI::getOutput() const return _out.str(); } -string -ControllerHelperI::loggerPrefix() const -{ - return _dll; -} - void ControllerHelperI::shutdown() { unique_lock lock(_mutex); - if(_completed) - { - return; - } - - if(_helper) + if(_communicator) { - Ice::CommunicatorPtr communicator = _helper->communicator(); - if(communicator) - { - communicator->shutdown(); - } + _communicator->shutdown(); } } @@ -308,7 +300,7 @@ ControllerHelperI::loadDll(const string& name) return p->second; } -ProcessI::ProcessI(const ControllerHelperPtr& controllerHelper) : +ProcessI::ProcessI(const shared_ptr& controllerHelper) : _controllerHelper(controllerHelper) { } @@ -374,7 +366,7 @@ ControllerI::ControllerI(ControllerView^ controller) auto registry = Ice::uncheckedCast( _communicator->stringToProxy("Util/ProcessControllerRegistry:tcp -h 127.0.0.1 -p 15001")); - Ice::ObjectAdapterPtr adapter = _communicator->createObjectAdapterWithEndpoints("ControllerAdapter", ""); + shared_ptr adapter = _communicator->createObjectAdapterWithEndpoints("ControllerAdapter", ""); Ice::Identity ident = { "ProcessController", "UWP"}; auto processController = Ice::uncheckedCast(adapter->add(make_shared(controller), ident)); @@ -385,7 +377,7 @@ ControllerI::ControllerI(ControllerView^ controller) void ControllerI::registerProcessController(ControllerView^ controller, - const Ice::ObjectAdapterPtr& adapter, + const shared_ptr& adapter, const shared_ptr& registry, const shared_ptr& processController) { -- cgit v1.2.3