43 #include <boost/bind.hpp> 51 const std::string& response_md5sum,
const M_string& header_values)
52 : service_name_(service_name)
53 , persistent_(persistent)
54 , request_md5sum_(request_md5sum)
55 , response_md5sum_(response_md5sum)
56 , extra_outgoing_header_values_(header_values)
57 , header_written_(false)
74 boost::mutex::scoped_lock lock(local->finished_mutex_);
75 local->finished_ =
true;
76 local->finished_condition_.notify_all();
79 if (boost::this_thread::get_id() != info->caller_thread_id_)
81 while (!local->call_finished_)
83 boost::this_thread::yield();
142 if (!header.
getValue(
"md5sum", md5sum))
144 ROS_ERROR(
"TCPROS header from service server did not have required element: md5sum");
196 uint8_t
ok = buffer[0];
197 uint32_t len = *((uint32_t*)(buffer.get() + 1));
199 if (len > 1000000000)
201 ROS_ERROR(
"a message of over a gigabyte was " \
202 "predicted in tcpros. that seems highly " \
203 "unlikely, so I'll assume protocol " \
204 "synchronization is lost.");
246 current_call_->exception_string_ = std::string(reinterpret_cast<char*>(buffer.get()), size);
259 boost::mutex::scoped_lock finished_lock(
current_call_->finished_mutex_);
272 self = shared_from_this();
334 info->success_ =
false;
335 info->finished_ =
false;
336 info->call_finished_ =
false;
337 info->caller_thread_id_ = boost::this_thread::get_id();
341 bool immediate =
false;
348 info->call_finished_ =
true;
366 boost::mutex::scoped_lock lock(info->finished_mutex_);
368 while (!info->finished_)
370 info->finished_condition_.wait(lock);
374 info->call_finished_ =
true;
376 if (info->exception_string_.length() > 0)
378 ROS_ERROR(
"Service call failed: service [%s] responded with an error: %s",
service_name_.c_str(), info->exception_string_.c_str());
381 return info->success_;
bool isValid() const
Returns whether this client is still valid, ie. its connection has not been dropped.
bool call(const SerializedMessage &req, SerializedMessage &resp)
Blocking call the service this client is connected to.
void onRequestWritten(const ConnectionPtr &conn)
void onConnectionDropped(const ConnectionPtr &conn)
void clearCalls()
Clear all calls, notifying them that they've failed.
ROSCPP_DECL const std::string & getName()
Returns the name of the current node.
ConnectionPtr connection_
std::map< std::string, std::string > M_string
CallInfoPtr current_call_
static const ServiceManagerPtr & instance()
boost::shared_ptr< CallInfo > CallInfoPtr
std::string service_name_
void cancelCall(const CallInfoPtr &info)
Cancel a queued call, notifying it that it has failed.
#define ROS_DEBUG_NAMED(name,...)
std::string request_md5sum_
#define ROSCPP_LOG_DEBUG(...)
ServiceServerLink(const std::string &service_name, bool persistent, const std::string &request_md5sum, const std::string &response_md5sum, const M_string &header_values)
boost::mutex call_queue_mutex_
void callFinished()
Called when the currently queued call has finished. Clears out the current call, notifying it that it...
ROSCPP_DECL bool ok()
Check whether it's time to exit.
M_string extra_outgoing_header_values_
void onResponseOkAndLength(const ConnectionPtr &conn, const boost::shared_array< uint8_t > &buffer, uint32_t size, bool success)
void processNextCall()
Pops the next call off the queue if one is available. If this is a non-persistent connection and the ...
bool initialize(const ConnectionPtr &connection)
boost::shared_array< uint8_t > buf
void onHeaderWritten(const ConnectionPtr &conn)
virtual ~ServiceServerLink()
void onResponse(const ConnectionPtr &conn, const boost::shared_array< uint8_t > &buffer, uint32_t size, bool success)
bool onHeaderReceived(const ConnectionPtr &conn, const Header &header)