diff --git a/owlps-positioning/src/outputsocket.cc b/owlps-positioning/src/outputsocket.cc index e2d5725..eca6762 100644 --- a/owlps-positioning/src/outputsocket.cc +++ b/owlps-positioning/src/outputsocket.cc @@ -1,16 +1,8 @@ #include "outputsocket.hh" #include "request.hh" -#include -#include -#include -#include -#include -//#include "mobile.hh" -//#include -//#include -//#include -//#include +#include +#include #define PORT 9910 @@ -20,18 +12,27 @@ struct hostent *hostInfo ; struct sockaddr_in serverAddress ; -/* *** Operations *** */ -/*OutputSocket::OutputSocket(const string m_ip) +/* *** Constructors *** */ + + +OutputSocket::OutputSocket(const string &_remote_ip): + remote_ip(_remote_ip) { -init_socket(); -}*/ + init_socket() ; +} + OutputSocket::~OutputSocket() { -kill_socket(); + kill_socket() ; } + + +/* *** Operations *** */ + + void OutputSocket::write(const Result &result) { string timestampXYZ; @@ -40,26 +41,31 @@ void OutputSocket::write(const Result &result) Point3D position = result.get_position() ; - os << request->get_time_sent() << ";" << position.get_x() << ";" << position.get_y() << ";" << position.get_z(); - timestampXYZ= os.str(); + os + << request->get_time_sent() << ';' + << position.get_x() << ';' + << position.get_y() << ';' + << position.get_z() ; + timestampXYZ = os.str() ; - cout << timestampXYZ << endl; + cout << timestampXYZ << '\n' ; send_data(timestampXYZ); } + void OutputSocket::init_socket() { cout << "Initialisation socket..." << endl; - hostInfo = gethostbyname(m_ip.c_str()); + hostInfo = gethostbyname(remote_ip.c_str()); serverPort = PORT; socketDescriptor = socket(AF_INET, SOCK_DGRAM, 0); serverAddress.sin_family = hostInfo->h_addrtype; memcpy((char *) &serverAddress.sin_addr.s_addr, hostInfo->h_addr_list[0], hostInfo->h_length); serverAddress.sin_port = htons(serverPort); - } + void OutputSocket::send_data(string data) { if (sendto(socketDescriptor, data.c_str(), data.size(), 0, @@ -71,13 +77,9 @@ void OutputSocket::send_data(string data) } } + void OutputSocket::kill_socket() { cout << "Fermeture de la socket..." << endl; close(socketDescriptor); } - -void OutputSocket::send_screen() -{ - cout << "Hello world !!" << endl; -} diff --git a/owlps-positioning/src/outputsocket.hh b/owlps-positioning/src/outputsocket.hh index c1d52e9..6a24cec 100644 --- a/owlps-positioning/src/outputsocket.hh +++ b/owlps-positioning/src/outputsocket.hh @@ -1,36 +1,37 @@ #ifndef _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ #define _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ -#include "outputmedium.hh" -#include -#include // is not C++ 98 compliant -#include -//#include -//#include -/// Send a result to socket +#include "outputmedium.hh" + +#include + +/// Sends results to an UDP socket class OutputSocket: public OutputMedium { private: int socketDescriptor ; - std::string m_ip ; + std::string remote_ip ; unsigned short int serverPort ; -public: - OutputSocket(const std::string &remote_ip): m_ip(remote_ip) { init_socket(); } - ~OutputSocket() ; - - void write(const Result &result) ; - - std::string float2string(float f) ; - std::string uint2string(uint64_t f) ; - std::string int2string(int f) ; - void init_socket() ; - void kill_socket() ; + /** @name Operations */ + //@{ + /// Initialises the socket + void init_socket(void) ; + void kill_socket(void) ; void send_data(std::string msg) ; - void send_screen() ; + //@} + +public: + OutputSocket(const std::string &_remote_ip) ; + ~OutputSocket(void) ; + + /** @name Operations */ + //@{ + /// Initialises the socket + void write(const Result &result) ; + //@} } ; #endif // _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ -