app_loader.cpp
Go to the documentation of this file.
1 
23 #include "app_loader/app_loader.h"
24 
25 namespace app_loader{
26 
28  {
29  ros::NodeHandle private_nh("~");
30  ros::NodeHandle nh;
31 
32  rtp_manager_destroy_ = false;
33 
34  //get app name and type
35  private_nh.param("app_name", app_name_, std::string("app_demo"));
36  private_nh.param("app_type", app_type_, std::string("micros_swarm/AppDemo"));
37 
38  ros::ServiceClient client = nh.serviceClient<app_loader::AppLoad>("app_loader_load_app");
39  app_loader::AppLoad srv;
40  srv.request.name = app_name_;
41  srv.request.type = app_type_;
42  if (client.call(srv))
43  {
44  ROS_INFO("[AppLoader]: App %s loaded successfully.", app_name_.c_str());
45  }
46  else
47  {
48  ROS_ERROR("[AppLoader]: Failed to load App %s.", app_name_.c_str());
49  }
50 
51  //when the rtp manager was destroyed, automatically unload the apps
52  std::string topic_name = "runtime_core_destroy_" + app_name_;
54  }
55 
57  {
60  ros::NodeHandle nh;
61  ros::ServiceClient client = nh.serviceClient<app_loader::AppUnload>("app_loader_unload_app");
62  app_loader::AppUnload srv;
63  srv.request.name = app_name_;
64  srv.request.type = app_type_;
65 
66  if (client.call(srv)) {
67  ROS_INFO("[AppLoader]: App %s was unloaded successfully.", app_name_.c_str());
68  } else {
69  ROS_ERROR("[AppLoader]: Failed to unload App %s.", app_name_.c_str());
70  }
71  }
72  else{
73  ROS_INFO("RTPManager was destroyed before the AppLoader.");
74  }
75  }
76 
77  bool AppLoader::rtpManagerDestroyCB(app_loader::RTDestroy::Request &req, app_loader::RTDestroy::Response &resp)
78  {
79  resp.success = false;
80  if(req.code == 1) {
81  rtp_manager_destroy_ = true;
82  resp.success = true;
83  }
84 
85  ros::shutdown();
86  return true;
87  }
88 
90  {
91  return !rtp_manager_destroy_;
92  }
93 };
94 
95 
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
bool call(MReq &req, MRes &res)
std::string app_name_
Definition: app_loader.h:42
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool rtpManagerDestroyCB(app_loader::RTDestroy::Request &req, app_loader::RTDestroy::Response &resp)
Definition: app_loader.cpp:77
ros::ServiceServer rtp_manager_destroy_srv_
Definition: app_loader.h:45
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
std::string app_type_
Definition: app_loader.h:43
ROSCPP_DECL void shutdown()
#define ROS_ERROR(...)


app_loader
Author(s):
autogenerated on Mon Jun 10 2019 14:02:01