00001 #include "GlobalService.hpp" 00002 #include "../plugin/PluginLoader.hpp" 00003 00004 #include "../os/StartStopManager.hpp" 00005 00006 namespace RTT 00007 { 00008 00009 // Cleanup the GlobalService on termination of the process 00010 // This is important if global services have ports that need to be disconnected. 00011 namespace { 00012 os::CleanupFunction release_global_service(&internal::GlobalService::Release); 00013 } 00014 00015 namespace internal 00016 { 00017 static Service::shared_ptr mserv; 00018 00019 GlobalService::GlobalService() 00020 : Service( "GlobalService" ) 00021 { 00022 addOperation("require", &GlobalService::require, this) 00023 .doc("Require that a certain service is loaded in the global service.") 00024 .arg("service_name","The name of the service to load globally."); 00025 } 00026 00027 GlobalService::~GlobalService() 00028 { 00029 } 00030 00031 Service::shared_ptr GlobalService::Instance() { 00032 if ( !mserv ) { 00033 mserv.reset( new GlobalService() ); 00034 } 00035 return mserv; 00036 } 00037 void GlobalService::Release() { 00038 mserv.reset(); 00039 } 00040 00041 bool GlobalService::require(const std::string servicename) { 00042 return hasService(servicename) || plugin::PluginLoader::Instance()->loadService(servicename, 0); // load globally. 00043 } 00044 } 00045 00046 }