29 #ifndef SWRI_ROSCPP_SERVICE_SERVER_IMPL_H_ 30 #define SWRI_ROSCPP_SERVICE_SERVER_IMPL_H_ 54 total_stats_.
merge(success, runtime);
55 if (instrument_per_client_) {
56 client_stats_[caller_name].merge(success, runtime);
63 unmapped_service_(
"uninitialized"),
64 mapped_service_(
"initialized"),
65 instrument_per_client_(false),
78 client_stats_.clear();
88 instrument_per_client_ = enable;
89 if (!instrument_per_client_) {
90 client_stats_.clear();
98 std::vector<std::string> names;
99 names.reserve(client_stats_.size());
101 std::map<std::string, ServiceServerStatistics>::const_iterator it;
102 for (it = client_stats_.begin(); it != client_stats_.end(); it++) {
103 names.push_back(it->first);
109 const std::string &
name)
const 111 std::map<std::string, ServiceServerStatistics>::const_iterator it;
112 it = client_stats_.find(name);
113 if (it == client_stats_.end()) {
128 template<
class MReq,
class MRes,
class T>
132 bool (T::*callback_plain_)(MReq &, MRes &);
134 bool (T::*callback_with_name_)(
const std::string &,
const MReq &, MRes &);
137 const std::string &service)
145 ROS_INFO(
"Serving to '%s' at '%s'.",
158 ROS_INFO(
"Service '%s' called by '%s'",
160 event.getCallerName().c_str());
167 if (callback_plain_) {
168 result = (obj_->*callback_plain_)(
170 }
else if (callback_with_name_) {
171 result = (obj_->*callback_with_name_)(
172 event.
getCallerName(),
event.getRequest(),
event.getResponse());
174 result = (obj_->*callback_with_event_)(event);
189 callback_plain_(NULL),
190 callback_with_event_(NULL),
191 callback_with_name_(NULL)
196 const std::string &service,
197 bool(T::*srv_func)(MReq &, MRes &),
201 callback_plain_ = srv_func;
202 callback_with_event_ = NULL;
203 callback_with_name_ = NULL;
208 const std::string &service,
213 callback_plain_ = NULL;
214 callback_with_event_ = srv_func;
215 callback_with_name_ = NULL;
220 const std::string &service,
221 bool(T::*srv_func)(
const std::string &,
const MReq &, MRes &),
225 callback_plain_ = NULL;
226 callback_with_event_ = NULL;
227 callback_with_name_ = srv_func;
232 #endif // SWRI_ROSCPP_SERVICE_SERVER_IMPL_H_ bool instrument_per_client_
const ServiceServerStatistics & totalStats() const
ServiceServerStatistics total_stats_
void setLogCalls(bool enable)
std::string mapped_service_
const std::string & getCallerName() const
ROSCONSOLE_DECL void initialize()
void setInstrumentPerClient(bool enable)
TypedServiceServerImpl(ros::NodeHandle &nh, const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
ros::ServiceServer server_
void processServing(const std::string caller_name, bool success, const ros::WallDuration &runtime)
std::map< std::string, ServiceServerStatistics > client_stats_
void initialize(ros::NodeHandle &nh, const std::string &service)
const std::string & mappedService() const
TypedServiceServerImpl(ros::NodeHandle &nh, const std::string &service, bool(T::*srv_func)(ros::ServiceEvent< MReq, MRes > &), T *obj)
bool instrumentPerClient() const
void merge(bool success, const ros::WallDuration &runtime)
std::string resolveName(const std::string &name, bool remap=true) const
const RequestType & getRequest() const
ResponseType & getResponse() const
TypedServiceServerImpl(ros::NodeHandle &nh, const std::string &service, bool(T::*srv_func)(const std::string &, const MReq &, MRes &), T *obj)
const std::string & unmappedService() const
std::vector< std::string > clientNames() const
bool handleService(ros::ServiceEvent< MReq, MRes > &event)
std::string unmapped_service_
ServiceServerStatistics clientStatistics(const std::string &name) const
virtual ~ServiceServerImpl()