owlps/owlps-positioning/src/outputudpsocket.hh

49 lines
1.1 KiB
C++

#ifndef _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_
#define _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_
#include "outputmedium.hh"
#include <string>
#include <stdint.h> // <cstdint> is not C++ 98 compliant
#include <arpa/inet.h>
/// Sends results to a remote host by UDP
/**
* The results are sent through an UDP socket as a CSV string value. The
* format used is the same as in OutputCSV.
*/
class OutputUDPSocket: public OutputMedium
{
protected:
int sockfd ;
std::string remote_host ;
uint_fast16_t remote_port ;
struct sockaddr_in server_info ;
struct sockaddr_in client_info ;
/** @name Operations */
//@{
/// Initialises the socket
bool init_socket(void) ;
void send_data(const std::string &data) ;
//@}
public:
OutputUDPSocket(const std::string &_remote_ip,
const uint_fast16_t _port) ;
~OutputUDPSocket(void) ;
/** @name Operations */
//@{
void write(const Result &result) ;
void write(const ResultList &results) ;
/// Closes the socket
bool close_socket(void) ;
//@}
} ;
#endif // _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_