From 232551c15012c46ed7182a4bda7152955c05cbc9 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Thu, 21 Jul 2011 21:39:54 +0200 Subject: [PATCH] [Positioning] ReferencePoint::delete_generated_requests() --- owlps-positioning/src/referencepoint.cc | 46 +++++++++++++++++++++++-- owlps-positioning/src/referencepoint.hh | 2 ++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/owlps-positioning/src/referencepoint.cc b/owlps-positioning/src/referencepoint.cc index f58f91f..f769e42 100644 --- a/owlps-positioning/src/referencepoint.cc +++ b/owlps-positioning/src/referencepoint.cc @@ -117,9 +117,9 @@ void ReferencePoint::delete_requests() int stock_nb_requests = Stock::nb_calibration_requests() ; #endif // NDEBUG - for (vector::iterator i = requests.begin() ; - i != requests.end() ; ++i) - Stock::delete_calibration_request(**i) ; + for (vector::iterator r = requests.begin() ; + r != requests.end() ; ++r) + Stock::delete_calibration_request(**r) ; assert(Stock::nb_calibration_requests() == stock_nb_requests - requests.size()) ; @@ -128,6 +128,46 @@ void ReferencePoint::delete_requests() } +/** + * Note that the requests pointed by the elements of #requests are + * actually deleted from the Stock. + * @returns \em true if at least one request was deleted. + * @returns \em false if the ReferencePoint was left untouched. + */ +bool ReferencePoint::delete_generated_requests(void) +{ + bool modified = false ; + + for (vector::iterator r = requests.begin() ; + r != requests.end() ; ++r) + { + assert(*r) ; + if ((*r)->get_mobile() == NULL) + { + requests.erase(r) ; + modified = true ; + continue ; + } + + unordered_map::const_iterator ap ; + for (ap = Stock::get_aps().begin() ; ap != Stock::get_aps().end() ; + ++ap) + if ((*r)->get_mobile()->get_mac_addr() == + ap->second.get_mac_addr()) + break ; + + if (ap == Stock::get_aps().end()) // r is not associated with an AP + { + Stock::delete_calibration_request(**r) ; + requests.erase(r) ; + modified = true ; + } + } + + return modified ; +} + + /* *** Operations *** */ diff --git a/owlps-positioning/src/referencepoint.hh b/owlps-positioning/src/referencepoint.hh index efd26a8..4516cc1 100644 --- a/owlps-positioning/src/referencepoint.hh +++ b/owlps-positioning/src/referencepoint.hh @@ -57,6 +57,8 @@ public: void add_request(const CalibrationRequest *cm) ; /// Deletes all the requests contained in #requests void delete_requests(void) ; + /// Deletes the requests that are not sent by an AP + bool delete_generated_requests(void) ; //@} /** @name Operations */