fw4spl
Bundles/core/preferences/src/preferences/Plugin.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2014-2018.
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 "preferences/Plugin.hpp"
8 
9 #include "preferences/SPreferences.hpp"
10 
11 #include <fwData/String.hpp>
12 
13 #include <fwPreferences/helper.hpp>
14 
15 #include <fwRuntime/EConfigurationElement.hpp>
16 #include <fwRuntime/profile/Profile.hpp>
17 #include <fwRuntime/utils/GenericExecutableFactoryRegistrar.hpp>
18 
19 #include <fwServices/macros.hpp>
20 #include <fwServices/op/Add.hpp>
21 #include <fwServices/op/Get.hpp>
22 
23 #include <fwTools/Os.hpp>
24 
25 namespace preferences
26 {
27 
28 const std::string Plugin::s_PREF_SERVICE_UID = "PREF_SERVICE_UID";
29 
30 static ::fwRuntime::utils::GenericExecutableFactoryRegistrar<Plugin> registrar("preferences::Plugin");
31 
32 //-----------------------------------------------------------------------------
33 
35 {
36  m_preferences = ::fwData::Composite::New();
37 
38  ::fwServices::IService::sptr prefSrv;
39  prefSrv = ::fwServices::add("::preferences::SPreferences", s_PREF_SERVICE_UID);
40  prefSrv->registerInOut(m_preferences, fwPreferences::s_PREFERENCES_KEY);
41 
42  try
43  {
44  ::fwRuntime::EConfigurationElement::sptr prefConfig = ::fwRuntime::EConfigurationElement::New( "filename" );
45  ::boost::filesystem::path prefFile = ::fwPreferences::getPreferencesFile();
46  prefConfig->setValue(prefFile.string());
47 
48  prefSrv->setConfiguration(prefConfig);
49  prefSrv->configure();
50  prefSrv->start();
51 
52  if ( m_preferences->find( "PREFERENCES_VERSION" ) == m_preferences->end() )
53  {
54  ::fwData::String::sptr version = ::fwData::String::New( PREFERENCES_VER );
55  (*m_preferences)[ "PREFERENCES_VERSION" ] = version;
56  }
57  }
58  catch(::fwCore::Exception& e)
59  {
60  OSLM_ERROR("Preferences service not started. " << e.what());
61  }
62 }
63 
64 //-----------------------------------------------------------------------------
65 
66 void Plugin::stop() noexcept
67 {
68  if(::fwTools::fwID::exist(s_PREF_SERVICE_UID))
69  {
70  ::fwServices::IService::sptr prefSrv = ::fwServices::get(s_PREF_SERVICE_UID);
71  prefSrv->stop();
72  ::fwServices::OSR::unregisterService(prefSrv);
73  }
74  m_preferences.reset();
75 }
76 
77 //-----------------------------------------------------------------------------
78 
79 } // namespace preferences
static FWTOOLS_API bool exist(IDType _id)
Definition: fwID.cpp:33
#define OSLM_ERROR(message)
Definition: spyLog.hpp:274
The namespace preferences contains the service to manage the application&#39;s preferences (window size/p...
void stop() noexcept
Notifies the plugin about its stop.
void start()
Notifies the plugin about its start.