fw4spl
Stopper.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-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 "fwRuntime/profile/Stopper.hpp"
8 
9 #include "fwRuntime/Bundle.hpp"
10 #include "fwRuntime/Runtime.hpp"
11 
12 #include <fwCore/base.hpp>
13 
14 #include <iostream>
15 #include <sstream>
16 
17 namespace fwRuntime
18 {
19 
20 namespace profile
21 {
22 
23 //------------------------------------------------------------------------------
24 
25 Stopper::Stopper( const std::string& identifier, const Version& version) :
26  m_identifier( identifier ),
27  m_version( version )
28 {
29 }
30 
31 //------------------------------------------------------------------------------
32 
34 {
35  std::shared_ptr< Bundle > bundle = Runtime::getDefault()->findEnabledBundle(m_identifier, m_version);
36  SLM_FATAL_IF("Unable to stop bundle " + Bundle::getBundleStr(m_identifier, m_version) + ". Not found.",
37  bundle == 0);
38  try
39  {
40  SLM_INFO("Stopping bundle : " + Bundle::getBundleStr(m_identifier, m_version));
41  bundle->stop();
42  }
43  catch( const std::exception& e )
44  {
45  SLM_ERROR("Unable to stop bundle " + Bundle::getBundleStr(m_identifier, m_version) + ". " + e.what());
46  }
47 }
48 
49 //------------------------------------------------------------------------------
50 
51 } // namespace profile
52 
53 } // namespace fwRuntime
static FWRUNTIME_API Runtime * getDefault()
Retrieves the default runtime instance.
Definition: Runtime.cpp:286
FWRUNTIME_API std::shared_ptr< Bundle > findEnabledBundle(const std::string &identifier, const Version &version=Version()) const
Retrieves the enabled bundle for the specified idenfier.
Definition: Runtime.cpp:270
void apply()
Applies the Stopper on the system.
Definition: Stopper.cpp:33
The namespace fwRuntime contains classes to manage bundle, configuration element, extension point in ...
#define SLM_ERROR(message)
Definition: spyLog.hpp:272
FWRUNTIME_API Stopper(const std::string &_identifier, const Version &version=Version())
Constructor.
Definition: Stopper.cpp:25
#define SLM_FATAL_IF(message, cond)
Definition: spyLog.hpp:287
#define SLM_INFO(message)
Definition: spyLog.hpp:250
Holds version information for libraries and bundles.