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
1 /*
2  * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
3  * http://gearbox.sf.net/
4  * Copyright (c) 2008 Geoffrey Biggs
5  *
6  * flexiport flexible hardware data communications library.
7  *
8  * This distribution is licensed to you under the terms described in the LICENSE file included in
9  * this distribution.
10  *
11  * This work is a product of the National Institute of Advanced Industrial Science and Technology,
12  * Japan. Registration number: H20PRO-881
13  *
14  * This file is part of flexiport.
15  *
16  * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
17  * Lesser General Public License as published by the Free Software Foundation, either version 3 of
18  * the License, or (at your option) any later version.
19  *
20  * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
21  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License along with flexiport.
25  * If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #ifndef __UDPPORT_H
29 #define __UDPPORT_H
30 
31 #include "port.h"
32 #include "flexiport_config.h"
33 
34 #include <map>
35 #include <string>
36 #if !defined (WIN32)
37  #include <netinet/in.h>
38 #endif
39 
44 namespace flexiport
45 {
46 
77 class FLEXIPORT_EXPORT UDPPort : public Port
78 {
79  public:
80  UDPPort (std::map<std::string, std::string> options);
81  ~UDPPort ();
82 
86  void Open ();
88  void Close ();
90  ssize_t Read (void * const buffer, size_t count);
92  ssize_t ReadFull (void * const buffer, size_t count);
94  ssize_t ReadUntil (void * const buffer, size_t count, uint8_t terminator);
96  ssize_t ReadStringUntil (std::string &buffer, char terminator);
98  ssize_t Skip (size_t count);
101  ssize_t SkipUntil (uint8_t terminator, unsigned int count);
103  ssize_t BytesAvailable ();
105  ssize_t BytesAvailableWait ();
107  ssize_t Write (const void * const buffer, size_t count);
109  void Flush ();
111  void Drain ();
113  std::string GetStatus () const;
115  void SetTimeout (Timeout timeout);
117  void SetCanRead (bool canRead);
119  void SetCanWrite (bool canWrite);
121  bool IsOpen () const { return _open; }
122 
123  private:
124 #if !defined (WIN32)
125  #if defined (FLEXIPORT_HAVE_GETADDRINFO)
126  struct sockaddr _destSockAddr;
127  #else
128  struct sockaddr_in _destSockAddr;
129  #endif
130 #endif // !defined (WIN32)
131  int _sendSock; // Socket to send data from.
132  int _recvSock; // Socket to receive data on.
133 
134  std::string _destIP;
135  unsigned int _destPort;
136  std::string _recvIP;
137  unsigned int _recvPort;
138  bool _open;
139 
140  void CheckPort (bool read);
141 
142  bool ProcessOption (const std::string &option, const std::string &value);
143 
144  void OpenSender ();
145  void CloseSender ();
146  void OpenReceiver ();
147  void CloseReceiver ();
148  typedef enum {TIMED_OUT, DATA_AVAILABLE, CAN_WRITE} WaitStatus;
149  WaitStatus WaitForDataOrTimeout ();
150  bool IsDataAvailable ();
151  WaitStatus WaitForWritableOrTimeout ();
152  void SetSocketBlockingFlag ();
153 };
154 
155 } // namespace flexiport
156 
159 #endif // __UDPPORT_H
UDP implementation of the Port class. This class provides UDP communication between two known end poi...
Definition: udpport.h:77
An object used to represent timeouts.
Definition: timeout.h:62
FlexiPort data communications library.
Base Port class.
Definition: port.h:79
bool IsOpen() const
Check if the port is open.
Definition: udpport.h:121
 

Generated for GearBox by  doxygen 1.4.5