38 for(
int i = 0; i <
apps_.size(); i++) {
39 apps_[i]->app_ptr_.reset();
55 std::vector<AppInstance*>::iterator app_it;
56 for(app_it =
apps_.begin(); app_it !=
apps_.end(); app_it++) {
57 if((*app_it)->app_name_ == app_name) {
59 (*app_it)->running_ =
false;
60 (*app_it)->app_ptr_.reset();
62 app_it =
apps_.erase(app_it);
75 std::vector<AppInstance*>::iterator app_it;
76 for(app_it =
apps_.begin(); app_it !=
apps_.end(); app_it++) {
77 if((*app_it)->app_name_ == app_name) {
89 std::vector<AppInstance*>::iterator app_it;
90 for(app_it =
apps_.begin(); app_it !=
apps_.end(); app_it++) {
91 if(!(*app_it)->running_) {
92 (*app_it)->app_ptr_->init();
93 (*app_it)->app_ptr_->start();
94 (*app_it)->running_ =
true;
138 std::map<std::string, int>::iterator it;
140 std::string topic_name =
"runtime_core_destroy_" + it->first;
142 app_loader::RTDestroy srv;
143 srv.request.code = 1;
145 if (client.
call(srv)) {
155 int worker_id = it->second;
157 if(instance != NULL) {
160 std::string app_type = instance->
app_type_;
171 std::cout<<
"[AppManager]: all Apps were unloaded successfully."<<std::endl;
177 std::cout<<
"[AppManager]: destroy all the worker successfully."<<std::endl;
184 std::map<std::string, int>::iterator it =
apps_record_.find(name);
195 apps_record_.insert(std::pair<std::string, int>(name, worker_id));
217 std::map<std::string, int>::iterator it;
229 std::map<std::string, int>::iterator it;
233 if(it->second == 0) {
241 std::map<std::string, int>::iterator it;
252 std::string app_name = req.name;
253 std::string app_type = req.type;
257 ROS_WARN(
"[AppManager]: App %s was already existed.", app_name.c_str());
259 resp.success =
false;
268 ROS_ERROR(
"[AppManager]: App %s failed to load for some reason. Error: %s", app_name.c_str(), ex.what());
272 app_instance->app_name_ = app_name;
273 app_instance->app_type_ = app_type;
274 app_instance->app_ptr_ = app;
275 app_instance->running_ =
false;
282 ROS_INFO(
"[AppManager]: App %s was loaded successfully.", app_name.c_str());
291 std::string app_name = req.name;
292 std::string app_type = req.type;
297 if(instance == NULL) {
298 ROS_WARN(
"[AppManager]: Get App instance %s failed.", app_name.c_str());
300 resp.success =
false;
311 ROS_INFO(
"[AppManager]: App %s was unloaded successfully.", app_name.c_str());
316 ROS_WARN(
"[AppManager]: App %s does not exist.", app_name.c_str());
318 resp.success =
false;
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void insertOrUpdatePluginUseCount(const std::string &type)
std::vector< Worker * > worker_table_
void addRecord(const std::string &name, int worker_id)
pluginlib::ClassLoader< micros_swarm::Application > app_loader_
std::vector< AppInstance * > apps_
bool call(MReq &req, MRes &res)
bool unloadService(app_loader::AppUnload::Request &req, app_loader::AppUnload::Response &resp)
int getPluginUseCount(const std::string &type)
AppInstance * getAppInstance(const std::string &app_name)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
std::map< std::string, int > apps_record_
void decreasePluginUseCount(const std::string &type)
void addApp(AppInstance *app)
std::vector< uint16_t > load_table_
boost::shared_ptr< Application > app_ptr_
void removeRecord(const std::string &name)
void removeApp(const std::string &app_name)
bool loadService(app_loader::AppLoad::Request &req, app_loader::AppLoad::Response &resp)
ros::ServiceServer app_load_srv_
ros::ServiceServer app_unload_srv_
bool recordExist(const std::string &name)
std::map< std::string, int > plugin_use_count_