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
43
44namespace flexiport
45{
46
77class 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
158
159#endif // __UDPPORT_H
An object used to represent timeouts.
Definition timeout.h:63
void SetCanRead(bool canRead)
Set the read permissions of the port.
Definition udpport.cpp:658
std::string GetStatus() const
Get the status of the port (type, device, etc).
Definition udpport.cpp:633
ssize_t ReadFull(void *const buffer, size_t count)
Read the requested quantity of data from the port.
Definition udpport.cpp:313
ssize_t BytesAvailable()
Get the number of bytes waiting to be read at the port. Returns immediatly.
Definition udpport.cpp:465
bool IsOpen() const
Check if the port is open.
Definition udpport.h:121
ssize_t BytesAvailableWait()
Get the number of bytes waiting after blocking for the timeout.
Definition udpport.cpp:495
ssize_t ReadUntil(void *const buffer, size_t count, uint8_t terminator)
Read data until a specified termination byte is received.
Definition udpport.cpp:380
ssize_t Skip(size_t count)
Dump data until the specified number of bytes have been read.
Definition udpport.cpp:451
void Open()
Open the port.
Definition udpport.cpp:179
void Close()
Close the port.
Definition udpport.cpp:195
void SetTimeout(Timeout timeout)
Set the timeout value in milliseconds.
Definition udpport.cpp:652
ssize_t SkipUntil(uint8_t terminator, unsigned int count)
Read and dump data until the specified termination character has been seen count times.
Definition udpport.cpp:458
void Flush()
Flush the port's input and output buffers, discarding all data.
Definition udpport.cpp:591
void SetCanWrite(bool canWrite)
Set the write permissions of the port.
Definition udpport.cpp:667
ssize_t Write(const void *const buffer, size_t count)
Write data to the port.
Definition udpport.cpp:541
ssize_t Read(void *const buffer, size_t count)
Read from the port.
Definition udpport.cpp:212
void Drain()
Drain the port's input and output buffers.
Definition udpport.cpp:622
ssize_t ReadStringUntil(std::string &buffer, char terminator)
Read a string until the specified termination character is received.
Definition udpport.cpp:444
FlexiPort data communications library.
 

Generated for GearBox by  doxygen 1.4.5