fw4spl
Bundles/ui/console/src/console/Plugin.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "console/Plugin.hpp"
8 
9 #include <fwRuntime/profile/Profile.hpp>
10 #include <fwRuntime/utils/GenericExecutableFactoryRegistrar.hpp>
11 
12 #include <fwServices/registry/ActiveWorkers.hpp>
13 
14 namespace console
15 {
16 //-----------------------------------------------------------------------------
17 
18 static ::fwRuntime::utils::GenericExecutableFactoryRegistrar<Plugin> registrar("::console::Plugin");
19 
20 //-----------------------------------------------------------------------------
21 
22 Plugin::~Plugin() noexcept
23 {
24 }
25 
26 //-----------------------------------------------------------------------------
27 
29 {
30  m_worker = ::fwThread::Worker::New();
32 
33  ::fwRuntime::profile::getCurrentProfile()->setRunCallback(std::bind(&Plugin::run, this));
34 }
35 
36 //-----------------------------------------------------------------------------
37 
38 void Plugin::stop() noexcept
39 {
40  if(m_worker)
41  {
42  m_worker->stop();
43  }
44 }
45 
46 //-----------------------------------------------------------------------------
47 
48 int Plugin::run() noexcept
49 {
50  m_worker->post( []() {::fwRuntime::profile::getCurrentProfile()->setup(); } );
51  m_worker->getFuture().wait(); // This is required to start WorkerAsio loop
52 
53  ::fwRuntime::profile::getCurrentProfile()->cleanup();
54  const std::uint64_t result = ::boost::any_cast<std::uint64_t>(m_worker->getFuture().get());
55 
57  m_worker.reset();
58 
59  return result;
60 }
61 
62 //-----------------------------------------------------------------------------
63 
64 } // namespace console
CONSOLE_API int run() noexcept
Run callback.
static FWSERVICES_API void setDefaultWorker(::fwThread::Worker::sptr worker)
Register the default active worker.
static FWSERVICES_API ActiveWorkers::sptr getDefault()
Returns an instance of ActiveWorkers.
CONSOLE_API void stop() noexcept
The namespace console contains no service. It is only used to launch a main loop for console applicat...
CONSOLE_API ~Plugin() noexcept
Destructor.