owlps/owlps-positioning/src/outputnetworksocket.hh

59 lines
1.5 KiB
C++

/*
* This file is part of the Owl Positioning System (OwlPS).
* OwlPS is a project of the University of Franche-Comté
* (Université de Franche-Comté), France.
*/
#ifndef _OWLPS_POSITIONING_OUTPUTNETWORKSOCKET_HH_
#define _OWLPS_POSITIONING_OUTPUTNETWORKSOCKET_HH_
#include "outputmedium.hh"
#include <string>
#include <stdint.h> // <cstdint> is not C++ 98 compliant
#include <arpa/inet.h>
#include <netinet/in.h>
/// Parent class for all output media that use network sockets
class OutputNetworkSocket: 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
/**
* You are required to call this function from the constructor of any
* derived class.
*/
virtual bool init_socket(void) = 0 ;
/// Sends a string through the socket
virtual bool send_data(const std::string &data) const = 0 ;
//@}
public:
OutputNetworkSocket(const std::string &_remote_host,
const uint_fast16_t _remote_port):
sockfd(-1), remote_host(_remote_host), remote_port(_remote_port) {}
~OutputNetworkSocket(void) ;
/** @name Operations */
//@{
/// Sends a list of results through the socket
void write(const ResultList &results) ;
/// Sends a single result through the socket
void write(const Result &result) ;
/// Closes the socket
bool close_socket(void) ;
//@}
} ;
#endif // _OWLPS_POSITIONING_OUTPUTNETWORKSOCKET_HH_