|
TOBI Interface A
0.1
|
00001 /* 00002 This file is part of the TOBI Interface A (TiA) library. 00003 00004 Commercial Usage 00005 Licensees holding valid Graz University of Technology Commercial 00006 licenses may use this file in accordance with the Graz University 00007 of Technology Commercial License Agreement provided with the 00008 Software or, alternatively, in accordance with the terms contained in 00009 a written agreement between you and Graz University of Technology. 00010 00011 -------------------------------------------------- 00012 00013 GNU Lesser General Public License Usage 00014 Alternatively, this file may be used under the terms of the GNU Lesser 00015 General Public License version 3.0 as published by the Free Software 00016 Foundation and appearing in the file lgpl.txt included in the 00017 packaging of this file. Please review the following information to 00018 ensure the GNU General Public License version 3.0 requirements will be 00019 met: http://www.gnu.org/copyleft/lgpl.html. 00020 00021 In case of GNU Lesser General Public License Usage ,the TiA library 00022 is distributed in the hope that it will be useful, 00023 but WITHOUT ANY WARRANTY; without even the implied warranty of 00024 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00025 GNU General Public License for more details. 00026 00027 You should have received a copy of the GNU Lesser General Public License 00028 along with the TiA library. If not, see <http://www.gnu.org/licenses/>. 00029 00030 Copyright 2010 Graz University of Technology 00031 Contact: TiA@tobi-project.org 00032 */ 00033 00039 #ifndef UDPDATASERVER_H 00040 #define UDPDATASERVER_H 00041 00042 // STL 00043 #include <set> 00044 #include <vector> 00045 00046 // BOOST 00047 #include <boost/asio.hpp> 00048 #include <boost/cstdint.hpp> 00049 00050 namespace tia 00051 { 00052 // forward declarations 00053 class DataPacket; 00054 00062 class UDPDataServer 00063 { 00064 public: 00070 UDPDataServer(boost::asio::io_service& io_service); 00074 virtual ~UDPDataServer(){} 00075 00081 void setDestination(const std::string& address, boost::uint16_t port); 00082 00083 std::string getTargetIP(){return(target_.address ().to_string ());} 00084 00089 boost::asio::ip::udp::endpoint destination() const { return target_; } 00090 00094 void incClientCount() 00095 { 00096 ++num_clients_; 00097 } 00098 00102 void decClientCount() 00103 { 00104 if (num_clients_ > 0) --num_clients_; 00105 } 00106 00112 void sendDataPacket(DataPacket& packet); 00113 00114 private: 00118 void handleWrite(const boost::system::error_code& error, 00119 std::size_t bytes_transferred); 00120 00121 private: 00122 boost::asio::io_service& io_service_; 00123 boost::asio::ip::udp::socket socket_; 00124 boost::asio::ip::udp::endpoint target_; 00125 boost::uint32_t num_clients_; 00126 }; 00127 00128 } // Namespace tobiss 00129 00130 #endif //UDPDATASERVER_H