servicemanager  2.4.3.28
 All Classes Namespaces Files Functions Variables Enumerations Enumerator
/home/opennao/work/master/core/servicemanager/servicemanager.h
Go to the documentation of this file.
1 #ifndef SERVICEMANAGER_MODULE_H
2 #define SERVICEMANAGER_MODULE_H
3 
4 #include <string>
5 #include <boost/scoped_ptr.hpp>
6 
8 #include <qi/messaging/autoservice.hpp>
9 
10 #include "processmanager.h"
11 
12 #include <qi/os.hpp>
13 #include <qi/log.hpp>
14 #include <qi/path.hpp>
15 #include <qi/session.hpp>
16 #include <qi/trackable.hpp>
17 
18 #include <qipackage/package_info.hpp>
19 #include <list>
20 #include <stdexcept>
21 
22 
23 namespace qi
24 {
35  class ServiceManager: public qi::Trackable<ServiceManager>
36  {
37  public:
43  ServiceManager(qi::SessionPtr session);
44 
50  ServiceManager(qi::SessionPtr session, const std::vector<std::string>& coreServices);
51 
58 
67  bool startService(const std::string &name);
68 
80  bool stopService(const std::string &name);
81 
89  bool restartService(const std::string &name);
90 
98  bool isServiceRunning(const std::string &name) const;
99 
103  std::vector<qi::ServiceProcessInfo> services();
104 
110  qi::ServiceProcessInfo service(const std::string &name);
111 
117  size_t serviceMemoryUsage(const std::string &name);
118 
124  qi::Signal<std::string, qi::ServiceEventReason> serviceStarted;
125 
132  qi::Signal<std::string, qi::ServiceEventReason> serviceStopped;
133 
137  qi::Signal<std::string> serviceAdded;
138 
142  qi::Signal<std::string> serviceRemoved;
143 
147  qi::Property<bool> enableLogging;
148 
149  private:
150  qi::SessionPtr _session;
151  std::vector<std::string> _coreServices;
152 
153  void stopAllServices();
154  void handleCrash(const std::string name, qi::ServiceEventReason reason);
155 
156  void advertiseServiceAdded(const qi::PackageInfo2& pkgInfo);
157  void advertiseServiceRemoved(const qi::PackageInfo2& pkgInfo);
158 
159  void startAutoRunServices(qi::PackageInfo2 pkgInfo);
160  void stopRemovedService(qi::PackageInfo2 pkgInfo);
161 
162  qi::AnyAutoService _packageManager;
163  void bootstrapPM();
164 
165  ProcessManager *_interface;
166  void *_pluginHandle;
167  void setBackend();
168  ProcessManager *loadPlugin(const std::string &pluginName);
169  void unloadPlugin();
170 
171  std::string replaceVar(const std::string &line);
172  void checkName(const std::string &name) const;
173  const qi::PackageService getService(const qi::PackageInfo2 &pkgInfo, const std::string &serviceName) const;
174  const qi::PackageInfo2 getPackageFromServiceName(const std::string &serviceName) const;
175  std::pair<qi::PackageInfo2, qi::PackageService> splitServiceName(const std::string &name) const;
176  };
177 }
178 
179 #endif // SERVICEMANAGER_MODULE_H
bool isServiceRunning(const std::string &name) const
Check that the service named name is started or not.
ServiceManager(qi::SessionPtr session)
Launch service manager.
qi::Signal< std::string > serviceAdded
Signal sent when a new service is handled by ServiceManager.
qi::Signal< std::string > serviceRemoved
Signal sent when a service is removed from serviceManager.
qi::ServiceProcessInfo service(const std::string &name)
Get information about one service named name.
qi::Property< bool > enableLogging
Enable or disable logging of services in QI_SERVICEMANAGER_LOGGING_PATH.
~ServiceManager()
Unload service manager.
ServiceManager Module.
std::vector< qi::ServiceProcessInfo > services()
Get the list of all services.
qi::Signal< std::string, qi::ServiceEventReason > serviceStopped
Sent when a service is stopped.
bool startService(const std::string &name)
Start a service with his name.
bool stopService(const std::string &name)
Stop service with his name.
qi::Signal< std::string, qi::ServiceEventReason > serviceStarted
Sent when a service is started.
size_t serviceMemoryUsage(const std::string &name)
Get the memory used by service named name.
bool restartService(const std::string &name)
Restart a service with his name.