[Positioner] Add Mobile::last_request

The last request transmitted by (received from) a mobile is now stored
along with last_results instead of relying on last_results.request which
is not guaranteed to be a valid pointer.
master
Matteo Cypriani 10 years ago
parent 7b0aacd212
commit e8f3479cdd

@ -13,6 +13,47 @@
#include "mobile.hh"
#include "request.hh"
/* *** Constructors *** */
Mobile::Mobile(const Mobile &m):
WifiDevice(m), last_results(m.last_results)
{
update_last_request() ;
}
Mobile::~Mobile()
{
if (last_request)
delete last_request ;
}
/* *** Write accessors *** */
void Mobile::update_last_request()
{
if (last_results.empty())
{
delete last_request ;
last_request = nullptr ;
return ;
}
if (! last_request)
last_request = new Request(*last_results.get_request()) ;
else
*last_request = *last_results.get_request() ;
last_results.set_request(last_request) ;
}

@ -15,6 +15,8 @@
#ifndef _OWLPS_POSITIONING_MOBILE_HH_
#define _OWLPS_POSITIONING_MOBILE_HH_
class Request ;
#include "wifidevice.hh"
#include "resultlist.hh"
@ -26,7 +28,18 @@
/// localised
class Mobile: public WifiDevice
{
private:
/// Last request received from this mobile
Request *last_request ;
/** @name Write accessors */
//@{
/// Updates last_request from last_results
void update_last_request(void) ;
//@}
protected:
/// Last results computed for this mobile
ResultList last_results ;
public:
@ -34,15 +47,15 @@ public:
const std::string &_mac_addr = "",
const float _antenna_gain = MOBILE_DEFAULT_ANTENNA_GAIN,
const float _trx_power = WIFIDEVICE_DEFAULT_TRX_POWER):
WifiDevice(_ip_addr, _mac_addr, _antenna_gain, _trx_power) {}
WifiDevice(_ip_addr, _mac_addr, _antenna_gain, _trx_power),
last_request(nullptr) {}
Mobile(const WifiDevice &wd):
WifiDevice(wd) {}
WifiDevice(wd), last_request(nullptr) {}
Mobile(const Mobile &m):
WifiDevice(m), last_results(m.last_results) {}
Mobile(const Mobile &m) ;
~Mobile(void) {}
~Mobile(void) ;
/** @name Read accessors */
//@{
@ -83,6 +96,7 @@ inline const ResultList& Mobile::get_last_results() const
inline void Mobile::set_last_results(const ResultList &_last_results)
{
last_results = _last_results ;
update_last_request() ;
}

Loading…
Cancel
Save