2010-01-11 19:40:45 +01:00
|
|
|
#include "request.hh"
|
|
|
|
#include "mobile.hh"
|
|
|
|
|
|
|
|
using namespace std ;
|
|
|
|
using std::tr1::unordered_map ;
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Constructors *** */
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
Request::Request(const unordered_map<string, Measurement> &_measurements)
|
|
|
|
{
|
|
|
|
mobile = NULL ;
|
|
|
|
timestamp.tv_sec = 0 ;
|
|
|
|
timestamp.tv_nsec = 0 ;
|
|
|
|
measurements = _measurements ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Request::Request(const struct timespec &_timestamp,
|
|
|
|
const unordered_map<string, Measurement> &_measurements)
|
|
|
|
{
|
|
|
|
mobile = NULL ;
|
|
|
|
timestamp = _timestamp ;
|
|
|
|
measurements = _measurements ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Request::Request(const Mobile *_mobile, const struct timespec &_timestamp,
|
|
|
|
const unordered_map<string, Measurement> &_measurements)
|
|
|
|
{
|
2010-01-18 14:19:57 +01:00
|
|
|
mobile = const_cast<Mobile*>(_mobile) ;
|
2010-01-11 19:40:45 +01:00
|
|
|
timestamp = _timestamp ;
|
|
|
|
measurements = _measurements ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
|
|
|
* Note that the value pointed by #mobile is not deleted.
|
|
|
|
*/
|
|
|
|
Request::~Request()
|
|
|
|
{
|
|
|
|
measurements.clear() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* *** Write accessors *** */
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/**
|
|
|
|
* - #mobile is NULLified, but the value it pointed to is not deleted.
|
|
|
|
* - The fields of #timestamp are initialised to 0.
|
|
|
|
* - #measurements is cleared.
|
|
|
|
*/
|
2010-01-11 19:40:45 +01:00
|
|
|
void Request::clear()
|
|
|
|
{
|
|
|
|
mobile = NULL ;
|
|
|
|
timestamp.tv_sec = 0 ;
|
|
|
|
timestamp.tv_nsec = 0 ;
|
|
|
|
measurements.clear() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-16 12:23:07 +01:00
|
|
|
/* *** Operators *** */
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
ostream &operator<<(ostream &os, const Request &r)
|
|
|
|
{
|
|
|
|
// Timestamp
|
|
|
|
os
|
2010-02-01 17:11:36 +01:00
|
|
|
<< "At " << PosUtil::timespec_to_ms(r.timestamp) << "; " ;
|
2010-01-11 19:40:45 +01:00
|
|
|
|
|
|
|
// MAC address
|
|
|
|
os
|
|
|
|
<< "Mobile: "
|
|
|
|
<< (r.mobile != NULL ? r.mobile->get_mac_addr() : "Unknown_Mobile")
|
|
|
|
<< ":" ;
|
|
|
|
|
|
|
|
// List of Measurements
|
|
|
|
if (r.measurements.size() == 0)
|
|
|
|
os << " No values" ;
|
|
|
|
else
|
|
|
|
for (unordered_map<string, Measurement>::const_iterator i
|
2010-01-13 15:29:44 +01:00
|
|
|
= r.measurements.begin() ; i != r.measurements.end() ; ++i)
|
2010-01-11 19:40:45 +01:00
|
|
|
{
|
|
|
|
os << '\n' << i->first << ": " << i->second ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return os ;
|
|
|
|
}
|