servicemanager  2.8.7.4
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
/home/opennao/work/release-2.8/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 #include <boost/circular_buffer.hpp>
7 
9 #include <qi/messaging/autoservice.hpp>
10 
11 #include "processmanager.h"
12 
13 #include <qi/os.hpp>
14 #include <qi/log.hpp>
15 #include <qi/path.hpp>
16 #include <qi/clock.hpp>
17 #include <qi/macro.hpp>
18 #include <qi/session.hpp>
19 #include <qi/trackable.hpp>
20 
21 #include <qipackage/package_info.hpp>
22 #include <list>
23 #include <stdexcept>
24 
25 
26 namespace qi
27 {
38  class ServiceManager: public qi::Trackable<ServiceManager>
39  {
40  public:
46  ServiceManager(qi::SessionPtr session);
47 
53  ServiceManager(qi::SessionPtr session, const std::vector<std::string>& coreServices);
54 
61 
69  qi::Future<void> start(const std::string &name);
70 
82  qi::Future<void> stop(const std::string &name);
83 
95  qi::Future<void> stopAllServices();
96 
104  qi::Future<void> restart(const std::string &name);
105 
113  qi::Future<bool> isServiceRunning(const std::string &name) const;
114 
118  std::vector<qi::ServiceProcessInfo> services();
119 
125  qi::ServiceProcessInfo service(const std::string &name);
126 
132  qi::Future<size_t> serviceMemoryUsage(const std::string &name);
133 
141  QI_API_DEPRECATED_MSG(Use 'start' instead)
142  qi::Future<bool> startService(const std::string &name);
143 
156  QI_API_DEPRECATED_MSG(Use 'stop' instead)
157  qi::Future<bool> stopService(const std::string &name);
158 
167  QI_API_DEPRECATED_MSG(Use 'restart' instead)
168  qi::Future<bool> restartService(const std::string &name);
169 
175  qi::Signal<std::string, qi::ServiceEventReason> serviceStarted;
176 
183  qi::Signal<std::string, qi::ServiceEventReason> serviceStopped;
184 
188  qi::Signal<std::string> serviceAdded;
189 
193  qi::Signal<std::string> serviceRemoved;
194 
195  private:
196  qi::SessionPtr _session;
197  std::vector<std::string> _coreServices;
198 
199  void handleCrash(const std::string& name, qi::ServiceEventReason reason);
200  void restartAutoService();
201 
202  void advertiseServiceAdded(const qi::PackageInfo2& pkgInfo);
203  void advertiseServiceRemoved(const qi::PackageInfo2& pkgInfo);
204 
205  void startAutoRunServices(qi::PackageInfo2 pkgInfo);
206  void stopRemovedService(qi::PackageInfo2 pkgInfo);
207 
208  qi::AnyObject _packageManager;
209  void bootstrapPM();
210 
211  ProcessManager *_interface;
212  void *_pluginHandle;
213  void setBackend();
214  ProcessManager *loadPlugin(const std::string &pluginName);
215  void unloadPlugin();
216 
217  std::string replaceVar(const std::string &line);
218  void checkName(const std::string &name) const;
219  const qi::PackageService getService(const qi::PackageInfo2 &pkgInfo, const std::string &serviceName) const;
220  const qi::PackageInfo2 getPackageFromServiceName(const std::string &serviceName) const;
221  std::pair<qi::PackageInfo2, qi::PackageService> splitServiceName(const std::string &name) const;
222  std::map<std::string, boost::circular_buffer<qi::SteadyClock::time_point>> _timeTable;
223  bool processRestartFrequency(const std::string &name);
224  };
225 }
226 
227 #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.