INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         

udpport.h

00001 /*
00002  * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
00003  *               http://gearbox.sf.net/
00004  * Copyright (c) 2008 Geoffrey Biggs
00005  *
00006  * flexiport flexible hardware data communications library.
00007  *
00008  * This distribution is licensed to you under the terms described in the LICENSE file included in
00009  * this distribution.
00010  *
00011  * This work is a product of the National Institute of Advanced Industrial Science and Technology,
00012  * Japan. Registration number: H20PRO-881
00013  *
00014  * This file is part of flexiport.
00015  *
00016  * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
00017  * Lesser General Public License as published by the Free Software Foundation, either version 3 of
00018  * the License, or (at your option) any later version.
00019  *
00020  * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
00021  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License along with flexiport.
00025  * If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 #ifndef __UDPPORT_H
00029 #define __UDPPORT_H
00030 
00031 #include "port.h"
00032 #include "flexiport_config.h"
00033 
00034 #include <map>
00035 #include <string>
00036 #if !defined (WIN32)
00037         #include <netinet/in.h>
00038 #endif
00039 
00044 namespace flexiport
00045 {
00046 
00077 class FLEXIPORT_EXPORT UDPPort : public Port
00078 {
00079         public:
00080                 UDPPort (std::map<std::string, std::string> options);
00081                 ~UDPPort ();
00082 
00086                 void Open ();
00088                 void Close ();
00090                 ssize_t Read (void * const buffer, size_t count);
00092                 ssize_t ReadFull (void * const buffer, size_t count);
00094                 ssize_t ReadUntil (void * const buffer, size_t count, uint8_t terminator);
00096                 ssize_t ReadStringUntil (std::string &buffer, char terminator);
00098                 ssize_t Skip (size_t count);
00101                 ssize_t SkipUntil (uint8_t terminator, unsigned int count);
00103                 ssize_t BytesAvailable ();
00105                 ssize_t BytesAvailableWait ();
00107                 ssize_t Write (const void * const buffer, size_t count);
00109                 void Flush ();
00111                 void Drain ();
00113                 std::string GetStatus () const;
00115                 void SetTimeout (Timeout timeout);
00117                 void SetCanRead (bool canRead);
00119                 void SetCanWrite (bool canWrite);
00121                 bool IsOpen () const                        { return _open; }
00122 
00123         private:
00124 #if !defined (WIN32)
00125         #if defined (FLEXIPORT_HAVE_GETADDRINFO)
00126                 struct sockaddr _destSockAddr;
00127         #else
00128                 struct sockaddr_in _destSockAddr;
00129         #endif
00130 #endif // !defined (WIN32)
00131                 int _sendSock;      // Socket to send data from.
00132                 int _recvSock;      // Socket to receive data on.
00133 
00134                 std::string _destIP;
00135                 unsigned int _destPort;
00136                 std::string _recvIP;
00137                 unsigned int _recvPort;
00138                 bool _open;
00139 
00140                 void CheckPort (bool read);
00141 
00142                 bool ProcessOption (const std::string &option, const std::string &value);
00143 
00144                 void OpenSender ();
00145                 void CloseSender ();
00146                 void OpenReceiver ();
00147                 void CloseReceiver ();
00148                 typedef enum {TIMED_OUT, DATA_AVAILABLE, CAN_WRITE} WaitStatus;
00149                 WaitStatus WaitForDataOrTimeout ();
00150                 bool IsDataAvailable ();
00151                 WaitStatus WaitForWritableOrTimeout ();
00152                 void SetSocketBlockingFlag ();
00153 };
00154 
00155 } // namespace flexiport
00156 
00159 #endif // __UDPPORT_H
 

Generated for GearBox by  doxygen 1.4.5