[Positioning] OutputSocket -> OutputUDPSocket

This commit is contained in:
Matteo Cypriani 2011-04-04 17:37:19 +02:00
parent a2c0556ee8
commit 22cad4c214
5 changed files with 27 additions and 20 deletions

View File

@ -76,7 +76,7 @@ OBJ_LIST = \
output.o \
outputterminal.o \
outputcsv.o \
outputsocket.o \
outputudpsocket.o \
positioning.o \
input.o \
inputcsv.o \
@ -214,11 +214,16 @@ $(OBJ_DIR)/outputcsv.o: \
$(SRC_DIR)/outputmedium.hh \
$(OBJ_DIR)/textfilewriter.o \
$(OBJ_DIR)/result.o
$(OBJ_DIR)/outputudpsocket.o: \
$(SRC_DIR)/outputmedium.hh \
$(OBJ_DIR)/result.o
$(OBJ_DIR)/outputcsv.o: \
$(SRC_DIR)/outputmedium.hh \
$(OBJ_DIR)/result.o
$(OBJ_DIR)/output.o: \
$(OBJ_DIR)/outputterminal.o \
$(OBJ_DIR)/outputcsv.o \
$(OBJ_DIR)/outputudpsocket.o \
$(OBJ_DIR)/configuration.o \
$(OBJ_DIR)/posexcept.o
$(OBJ_DIR)/multilaterationalgorithm.o: \

View File

@ -4,7 +4,7 @@
#include "outputterminal.hh"
#include "outputcsv.hh"
#include "outputsocket.hh"
#include "outputudpsocket.hh"
#include <string>
@ -54,8 +54,8 @@ void Output::initialise_output_media()
else if (*i == "CSV")
initialise_output_csv() ;
else if (*i == "Socket")
initialise_output_socket() ;
else if (*i == "UDP")
initialise_output_udp_socket() ;
else
throw bad_configuration(
@ -69,17 +69,19 @@ void Output::initialise_output_terminal()
output_media.push_back(new OutputTerminal) ;
}
void Output::initialise_output_socket()
void Output::initialise_output_udp_socket()
{
if (! Configuration::is_configured("output.remote-ip"))
throw missing_configuration(
"No remote ip specified in the configuration!") ;
output_media.push_back(
new OutputSocket(
new OutputUDPSocket(
Configuration::string_value("output.remote-ip"))) ;
}
void Output::initialise_output_csv()
{
if (! Configuration::is_configured("output.csv-file"))

View File

@ -18,7 +18,7 @@ protected:
void initialise_output_media(void) ;
void initialise_output_terminal(void) ;
void initialise_output_csv(void) ;
void initialise_output_socket(void) ;
void initialise_output_udp_socket(void) ;
//@}
public:

View File

@ -1,4 +1,4 @@
#include "outputsocket.hh"
#include "outputudpsocket.hh"
#include "request.hh"
#include <sstream>
@ -16,14 +16,14 @@ struct sockaddr_in serverAddress ;
/* *** Constructors *** */
OutputSocket::OutputSocket(const string &_remote_ip):
OutputUDPSocket::OutputUDPSocket(const string &_remote_ip):
remote_ip(_remote_ip)
{
init_socket() ;
}
OutputSocket::~OutputSocket()
OutputUDPSocket::~OutputUDPSocket()
{
kill_socket() ;
}
@ -33,7 +33,7 @@ OutputSocket::~OutputSocket()
/* *** Operations *** */
void OutputSocket::write(const Result &result)
void OutputUDPSocket::write(const Result &result)
{
string timestampXYZ;
ostringstream os;
@ -53,7 +53,7 @@ void OutputSocket::write(const Result &result)
}
void OutputSocket::init_socket()
void OutputUDPSocket::init_socket()
{
cout << "Initialisation socket..." << endl;
hostInfo = gethostbyname(remote_ip.c_str());
@ -66,7 +66,7 @@ void OutputSocket::init_socket()
}
void OutputSocket::send_data(string data)
void OutputUDPSocket::send_data(string data)
{
if (sendto(socketDescriptor, data.c_str(), data.size(), 0,
(struct sockaddr *) &serverAddress,
@ -78,7 +78,7 @@ void OutputSocket::send_data(string data)
}
void OutputSocket::kill_socket()
void OutputUDPSocket::kill_socket()
{
cout << "Fermeture de la socket..." << endl;
close(socketDescriptor);

View File

@ -1,12 +1,12 @@
#ifndef _OWLPS_POSITIONING_OUTPUTSOCKET_HH_
#define _OWLPS_POSITIONING_OUTPUTSOCKET_HH_
#ifndef _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_
#define _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_
#include "outputmedium.hh"
#include <string>
/// Sends results to an UDP socket
class OutputSocket: public OutputMedium
class OutputUDPSocket: public OutputMedium
{
private:
int socketDescriptor ;
@ -22,8 +22,8 @@ private:
//@}
public:
OutputSocket(const std::string &_remote_ip) ;
~OutputSocket(void) ;
OutputUDPSocket(const std::string &_remote_ip) ;
~OutputUDPSocket(void) ;
/** @name Operations */
//@{
@ -34,4 +34,4 @@ public:
#endif // _OWLPS_POSITIONING_OUTPUTSOCKET_HH_
#endif // _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_