app_manager.h
Go to the documentation of this file.
1 
23 #ifndef APP_MANAGER_H_
24 #define APP_MANAGER_H_
25 
26 #include <iostream>
27 #include <vector>
28 #include <map>
29 #include <boost/bind.hpp>
30 #include <boost/thread.hpp>
31 #include <boost/function.hpp>
32 #include <boost/shared_ptr.hpp>
33 #include <boost/noncopyable.hpp>
34 #include <ros/ros.h>
36 #include <pluginlib/class_loader.h>
38 
40 #include "app_loader/AppLoad.h"
41 #include "app_loader/AppUnload.h"
42 #include "app_loader/RTDestroy.h"
43 
44 namespace micros_swarm{
45  struct AppInstance{
46  std::string app_name_;
47  std::string app_type_;
49  bool running_;
50  uint8_t status_;
51  };
52 
53  struct Worker{
54  public:
55  Worker(int id);
56  ~Worker();
57  void addApp(AppInstance* app);
58  void removeApp(const std::string& app_name);
59  int getAppNum();
60  AppInstance* getAppInstance(const std::string& app_name);
61  private:
62  void workFunc();
63  int id_;
64  volatile bool run_;
65  boost::thread* thread_;
66  std::vector<AppInstance*> apps_;
67  };
68 
69  class AppManager
70  {
71  public:
72  AppManager();
73  AppManager(int worker_num);
74  ~AppManager();
75  void stop();
76  private:
77  bool recordExist(const std::string& name);
78  void addRecord(const std::string& name, int worker_id);
79  void removeRecord(const std::string& name);
80  int allocateWorker();
81  void insertOrUpdatePluginUseCount(const std::string& type);
82  void decreasePluginUseCount(const std::string& type);
83  int getPluginUseCount(const std::string& type);
84  bool loadService(app_loader::AppLoad::Request &req, app_loader::AppLoad::Response &resp);
85  bool unloadService(app_loader::AppUnload::Request &req, app_loader::AppUnload::Response &resp);
90  std::vector<Worker*> worker_table_;
91  std::vector<uint16_t> load_table_;
92  std::map<std::string, int> apps_record_;
93  std::map<std::string, int> plugin_use_count_;
94  };
95 };
96 
97 #endif
ros::ServiceClient client_
Definition: app_manager.h:88
std::vector< Worker * > worker_table_
Definition: app_manager.h:90
pluginlib::ClassLoader< micros_swarm::Application > app_loader_
Definition: app_manager.h:86
std::vector< AppInstance * > apps_
Definition: app_manager.h:66
std::map< std::string, int > apps_record_
Definition: app_manager.h:92
std::vector< uint16_t > load_table_
Definition: app_manager.h:91
boost::shared_ptr< Application > app_ptr_
Definition: app_manager.h:48
ros::ServiceServer app_unload_srv_
Definition: app_manager.h:87
boost::thread * thread_
Definition: app_manager.h:65
volatile bool run_
Definition: app_manager.h:64
std::map< std::string, int > plugin_use_count_
Definition: app_manager.h:93


micros_swarm
Author(s):
autogenerated on Mon Jun 10 2019 14:02:06