service_server_link.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2008, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00035 #ifndef ROSCPP_SERVICE_SERVER_LINK_H
00036 #define ROSCPP_SERVICE_SERVER_LINK_H
00037 
00038 #include "ros/common.h"
00039 
00040 #include <boost/thread/mutex.hpp>
00041 #include <boost/shared_array.hpp>
00042 #include <boost/enable_shared_from_this.hpp>
00043 #include <boost/thread.hpp>
00044 
00045 #include <queue>
00046 
00047 namespace ros
00048 {
00049 class Header;
00050 class Message;
00051 class Connection;
00052 typedef boost::shared_ptr<Connection> ConnectionPtr;
00053 
00058 class ROSCPP_DECL ServiceServerLink : public boost::enable_shared_from_this<ServiceServerLink>
00059 {
00060 private:
00061   struct CallInfo
00062   {
00063     SerializedMessage req_;
00064     SerializedMessage* resp_;
00065 
00066     bool finished_;
00067     boost::condition_variable finished_condition_;
00068     boost::mutex finished_mutex_;
00069     boost::thread::id caller_thread_id_;
00070 
00071     bool success_;
00072     bool call_finished_;
00073 
00074     std::string exception_string_;
00075   };
00076   typedef boost::shared_ptr<CallInfo> CallInfoPtr;
00077   typedef std::queue<CallInfoPtr> Q_CallInfo;
00078 
00079 public:
00080   typedef std::map<std::string, std::string> M_string;
00081   ServiceServerLink(const std::string& service_name, bool persistent, const std::string& request_md5sum, const std::string& response_md5sum, const M_string& header_values);
00082   virtual ~ServiceServerLink();
00083 
00084   //
00085   bool initialize(const ConnectionPtr& connection);
00086 
00090   bool isValid() const;
00094   bool isPersistent() const { return persistent_; }
00095 
00096   const ConnectionPtr& getConnection() const { return connection_; }
00097 
00098   const std::string& getServiceName() const { return service_name_; }
00099   const std::string& getRequestMD5Sum() const { return request_md5sum_; }
00100   const std::string& getResponseMD5Sum() const { return response_md5sum_; }
00101 
00108   bool call(const SerializedMessage& req, SerializedMessage& resp);
00109 
00110 private:
00111   void onConnectionDropped(const ConnectionPtr& conn);
00112   bool onHeaderReceived(const ConnectionPtr& conn, const Header& header);
00113 
00118   void callFinished();
00123   void processNextCall();
00127   void clearCalls();
00131   void cancelCall(const CallInfoPtr& info);
00132 
00133   void onHeaderWritten(const ConnectionPtr& conn);
00134   void onRequestWritten(const ConnectionPtr& conn);
00135   void onResponseOkAndLength(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success);
00136   void onResponse(const ConnectionPtr& conn, const boost::shared_array<uint8_t>& buffer, uint32_t size, bool success);
00137 
00138   ConnectionPtr connection_;
00139   std::string service_name_;
00140   bool persistent_;
00141   std::string request_md5sum_;
00142   std::string response_md5sum_;
00143 
00144   M_string extra_outgoing_header_values_;
00145   bool header_written_;
00146   bool header_read_;
00147 
00148   Q_CallInfo call_queue_;
00149   boost::mutex call_queue_mutex_;
00150 
00151   CallInfoPtr current_call_;
00152 
00153   bool dropped_;
00154 };
00155 typedef boost::shared_ptr<ServiceServerLink> ServiceServerLinkPtr;
00156 
00157 } // namespace ros
00158 
00159 #endif // ROSCPP_SERVICE_SERVER_LINK_H
00160 
00161 
00162 


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Mon Oct 6 2014 11:46:44