00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*- 00002 00003 // -- BEGIN LICENSE BLOCK ---------------------------------------------- 00004 00024 // -- END LICENSE BLOCK ------------------------------------------------ 00025 00026 //---------------------------------------------------------------------- 00033 //---------------------------------------------------------------------- 00034 00035 #ifndef SICK_SAFETYSCANNERS_COMMUNICATION_ASYNCUDPCLIENT_H 00036 #define SICK_SAFETYSCANNERS_COMMUNICATION_ASYNCUDPCLIENT_H 00037 00038 #include <ros/ros.h> 00039 00040 #include <functional> 00041 #include <iostream> 00042 00043 #include <boost/array.hpp> 00044 #include <boost/asio.hpp> 00045 #include <boost/cstdint.hpp> 00046 #include <boost/function.hpp> 00047 00048 #include <sick_safetyscanners/datastructure/PacketBuffer.h> 00049 00050 00051 namespace sick { 00052 namespace communication { 00053 00057 class AsyncUDPClient 00058 { 00059 public: 00063 typedef boost::function<void(const sick::datastructure::PacketBuffer&)> PacketHandler; 00064 00072 AsyncUDPClient(PacketHandler packet_handler, 00073 boost::asio::io_service& io_service, 00074 const uint16_t& local_port = 0); 00075 00079 virtual ~AsyncUDPClient(); 00080 00084 void runService(); 00085 00090 unsigned short get_local_port(); 00091 00092 private: 00093 datastructure::PacketBuffer::ArrayBuffer m_recv_buffer; 00094 00095 PacketHandler m_packet_handler; 00096 00097 std::shared_ptr<boost::asio::io_service::work> m_io_work_ptr; 00098 boost::asio::io_service& m_io_service; 00099 std::shared_ptr<boost::asio::ip::udp::socket> m_socket_ptr; 00100 boost::asio::ip::udp::endpoint m_remote_endpoint; 00101 00102 void startReceive(); 00103 void handleReceive(const boost::system::error_code& error, const std::size_t& bytes_transferred); 00104 00105 00106 AsyncUDPClient(AsyncUDPClient&); // block default copy constructor 00107 }; 00108 } // namespace communication 00109 } // namespace sick 00110 00111 #endif // SICK_SAFETYSCANNERS_COMMUNICATION_ASYNCUDPCLIENT_H