servicemanager  release-2.5.3-2016-11-18
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
/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/macro.hpp>
16 #include <qi/session.hpp>
17 #include <qi/trackable.hpp>
18 
19 #include <qipackage/package_info.hpp>
20 #include <list>
21 #include <stdexcept>
22 
23 
24 namespace qi
25 {
36  class ServiceManager: public qi::Trackable<ServiceManager>
37  {
38  public:
44  ServiceManager(qi::SessionPtr session);
45 
51  ServiceManager(qi::SessionPtr session, const std::vector<std::string>& coreServices);
52 
59 
67  qi::Future<void> start(const std::string &name);
68 
80  qi::Future<void> stop(const std::string &name);
81 
93  qi::Future<void> stopAllServices();
94 
102  qi::Future<void> restart(const std::string &name);
103 
111  qi::Future<bool> isServiceRunning(const std::string &name) const;
112 
116  std::vector<qi::ServiceProcessInfo> services();
117 
123  qi::ServiceProcessInfo service(const std::string &name);
124 
130  qi::Future<size_t> serviceMemoryUsage(const std::string &name);
131 
139  QI_API_DEPRECATED_MSG(Use 'start' instead)
140  qi::Future<bool> startService(const std::string &name);
141 
154  QI_API_DEPRECATED_MSG(Use 'stop' instead)
155  qi::Future<bool> stopService(const std::string &name);
156 
165  QI_API_DEPRECATED_MSG(Use 'restart' instead)
166  qi::Future<bool> restartService(const std::string &name);
167 
173  qi::Signal<std::string, qi::ServiceEventReason> serviceStarted;
174 
181  qi::Signal<std::string, qi::ServiceEventReason> serviceStopped;
182 
186  qi::Signal<std::string> serviceAdded;
187 
191  qi::Signal<std::string> serviceRemoved;
192 
193  private:
194  qi::SessionPtr _session;
195  std::vector<std::string> _coreServices;
196 
197  void handleCrash(const std::string& name, qi::ServiceEventReason reason);
198  void restartAutoService();
199 
200  void advertiseServiceAdded(const qi::PackageInfo2& pkgInfo);
201  void advertiseServiceRemoved(const qi::PackageInfo2& pkgInfo);
202 
203  void startAutoRunServices(qi::PackageInfo2 pkgInfo);
204  void stopRemovedService(qi::PackageInfo2 pkgInfo);
205 
206  qi::AnyObject _packageManager;
207  void bootstrapPM();
208 
209  ProcessManager *_interface;
210  void *_pluginHandle;
211  void setBackend();
212  ProcessManager *loadPlugin(const std::string &pluginName);
213  void unloadPlugin();
214 
215  std::string replaceVar(const std::string &line);
216  void checkName(const std::string &name) const;
217  const qi::PackageService getService(const qi::PackageInfo2 &pkgInfo, const std::string &serviceName) const;
218  const qi::PackageInfo2 getPackageFromServiceName(const std::string &serviceName) const;
219  std::pair<qi::PackageInfo2, qi::PackageService> splitServiceName(const std::string &name) const;
220  };
221 }
222 
223 #endif // SERVICEMANAGER_MODULE_H
qi::Future< void > restart(const std::string &name)
Restart a service with his name.
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::Future< size_t > serviceMemoryUsage(const std::string &name)
Get the memory used by service named name.
qi::Future< bool > isServiceRunning(const std::string &name) const
Check that the service named name is started or not.
qi::ServiceProcessInfo service(const std::string &name)
Get information about one service named name.
qi::Future< bool > startService(const std::string &name)
Start a service with his name.
qi::Future< bool > restartService(const std::string &name)
Restart a service with his name.
qi::Future< void > stop(const std::string &name)
Stop service with his name.
~ServiceManager()
Unload service manager.
ServiceManager Module.
qi::Future< bool > stopService(const std::string &name)
Stop service with his name.
std::vector< qi::ServiceProcessInfo > services()
Get the list of all services.
qi::Future< void > stopAllServices()
Stop all services.
qi::Signal< std::string, qi::ServiceEventReason > serviceStopped
Sent when a service is stopped.
qi::Future< void > start(const std::string &name)
Start a service with his name.
qi::Signal< std::string, qi::ServiceEventReason > serviceStarted
Sent when a service is started.