diff --git a/owlps-positioner/src/request.cc b/owlps-positioner/src/request.cc index a41c94a..0a6b42a 100644 --- a/owlps-positioner/src/request.cc +++ b/owlps-positioner/src/request.cc @@ -16,9 +16,44 @@ using std::tr1::unordered_map ; /* *** Constructors *** */ +Request::Request( + const Mobile *_mobile, + const Timestamp &_time_sent, + const std::tr1::unordered_map &_measurements +): + type(OWL_REQUEST_UNDEFINED), nb_packets(1), + mobile(const_cast(_mobile)), time_sent(_time_sent), + measurements(_measurements), real_position(NULL) +{ + received_now() ; +} + + +Request::Request(const std::tr1::unordered_map + &_measurements): + type(OWL_REQUEST_UNDEFINED), nb_packets(1), + mobile(NULL), measurements(_measurements), real_position(NULL) +{ + received_now() ; +} + + +Request::Request( + const Timestamp &_time_sent, + const std::tr1::unordered_map &_measurements +): + type(OWL_REQUEST_UNDEFINED), nb_packets(1), + mobile(NULL), time_sent(_time_sent), + measurements(_measurements), real_position(NULL) +{ + received_now() ; +} + + Request::Request(const Request &source): type(source.type), nb_packets(source.nb_packets), mobile(source.mobile), time_sent(source.time_sent), + time_received(source.time_received), measurements(source.measurements), real_position(NULL) { if (source.real_position) @@ -82,7 +117,7 @@ void Request::set_real_position(const Point3D &_real_position) * - #nb_packets is set to 1 (this is the default value when * constructing a Request). * - #mobile is NULLified, but the value it pointed to is not deleted. - * - The fields of #time_sent are initialised to 0. + * - The fields of #time_sent and #time_received are initialised to 0. * - #measurements is cleared. */ void Request::clear() @@ -91,6 +126,7 @@ void Request::clear() nb_packets = 1 ; mobile = NULL ; time_sent.clear() ; + time_received.clear() ; measurements.clear() ; clear_real_position() ; } @@ -128,6 +164,7 @@ Request& Request::operator=(const Request &source) nb_packets = source.nb_packets ; mobile = source.mobile ; time_sent = source.time_sent ; + time_received = source.time_received ; measurements = source.measurements ; clear_real_position() ; @@ -154,6 +191,7 @@ bool Request::operator==(const Request &source) const nb_packets == source.nb_packets && mobile == source.mobile && time_sent == source.time_sent && + time_received == source.time_received && measurements == source.measurements ; } @@ -162,18 +200,18 @@ bool Request::operator==(const Request &source) const ostream& operator<<(ostream &os, const Request &r) { // Timestamp - os << "At " << r.time_sent << "; " ; + os << "At " << r.time_sent + << " (received at " << r.time_received << "; " ; if (r.real_position) os << " Real coordinates : " << *r.real_position << "; " ; // MAC address - os - << "Type: " << static_cast(r.type) - << ", Number of packets sent: " << r.nb_packets - << ", Mobile: " - << (r.mobile != NULL ? r.mobile->get_mac_addr() : "Unknown_Mobile") - << ":" ; + os << "Type: " << static_cast(r.type) + << ", Number of packets sent: " << r.nb_packets + << ", Mobile: " + << (r.mobile != NULL ? r.mobile->get_mac_addr() : "Unknown_Mobile") + << ":" ; // List of Measurements if (r.measurements.empty()) @@ -199,6 +237,7 @@ size_t hash_value(const Request &source) boost::hash_combine(seed, source.type) ; boost::hash_combine(seed, source.nb_packets) ; boost::hash_combine(seed, source.time_sent) ; + boost::hash_combine(seed, source.time_received) ; if (source.mobile) boost::hash_combine(seed, source.mobile->get_mac_addr()) ; if (source.real_position) diff --git a/owlps-positioner/src/request.hh b/owlps-positioner/src/request.hh index 6668fb0..41ba518 100644 --- a/owlps-positioner/src/request.hh +++ b/owlps-positioner/src/request.hh @@ -32,6 +32,8 @@ protected: Mobile *mobile ; /// Local date of the request on the mobile Timestamp time_sent ; + /// Date at which we received the request from the aggregator + Timestamp time_received ; /// List of Measurement of the request /** Note that this is not a pointer list, values are actually stored. The \em string parameter is the MAC address of the receiver AP. */ @@ -50,23 +52,15 @@ public: const Timestamp &_time_sent = Timestamp(), const std::tr1::unordered_map &_measurements = - std::tr1::unordered_map()): - type(OWL_REQUEST_UNDEFINED), nb_packets(1), - mobile(const_cast(_mobile)), time_sent(_time_sent), - measurements(_measurements), real_position(NULL) {} + std::tr1::unordered_map()) ; Request(const std::tr1::unordered_map - &_measurements): - type(OWL_REQUEST_UNDEFINED), nb_packets(1), - mobile(NULL), measurements(_measurements), real_position(NULL) {} + &_measurements) ; Request(const Timestamp &_time_sent, const std::tr1::unordered_map &_measurements = - std::tr1::unordered_map()): - type(OWL_REQUEST_UNDEFINED), nb_packets(1), - mobile(NULL), time_sent(_time_sent), - measurements(_measurements), real_position(NULL) {} + std::tr1::unordered_map()) ; Request(const Request &source) ; @@ -78,6 +72,7 @@ public: uint_fast16_t get_nb_packets(void) const ; Mobile* get_mobile(void) const ; const Timestamp& get_time_sent(void) const ; + const Timestamp& get_time_received(void) const ; /// Returns all the measurements const std::tr1::unordered_map& get_measurements(void) const ; @@ -93,6 +88,7 @@ public: void set_nb_packets(const uint_fast16_t _nb_packets) ; void set_mobile(const Mobile *_mobile) ; void set_time_sent(const Timestamp &_time_sent) ; + void received_now(void) ; void set_measurements(const std::tr1::unordered_map &_measurements) ; void set_real_position(const Point3D &_real_position) ; @@ -151,6 +147,12 @@ inline const Timestamp& Request::get_time_sent() const } +inline const Timestamp& Request::get_time_received() const +{ + return time_received ; +} + + inline const std::tr1::unordered_map& Request::get_measurements(void) const { @@ -192,6 +194,12 @@ inline void Request::set_time_sent(const Timestamp &_time_sent) } +inline void Request::received_now() +{ + time_received.now() ; +} + + inline void Request:: set_measurements(const std::tr1::unordered_map &_measurements) @@ -220,6 +228,7 @@ inline Request::operator bool() const return mobile != NULL || time_sent || + time_received || measurements.size() > 0 ; }