AP_ADSB: added singleton interface

This commit is contained in:
Andrew Tridgell 2019-10-02 20:54:10 +10:00
parent 2451d1bf38
commit da943524d1
2 changed files with 33 additions and 4 deletions

View File

@ -50,6 +50,8 @@
extern const AP_HAL::HAL& hal;
AP_ADSB *AP_ADSB::_singleton;
// table of user settable parameters
const AP_Param::GroupInfo AP_ADSB::var_info[] = {
// @Param: ENABLE
@ -159,6 +161,16 @@ const AP_Param::GroupInfo AP_ADSB::var_info[] = {
AP_GROUPEND
};
// constructor
AP_ADSB::AP_ADSB()
{
AP_Param::setup_object_defaults(this, var_info);
if (_singleton != nullptr) {
AP_HAL::panic("AP_ADSB must be singleton");
}
_singleton = this;
}
/*
* Initialize variables and allocate memory for array
*/
@ -940,3 +952,9 @@ void AP_ADSB::write_log(const adsb_vehicle_t &vehicle)
};
AP::logger().WriteBlock(&pkt, sizeof(pkt));
}
AP_ADSB *AP::ADSB()
{
return AP_ADSB::get_singleton();
}

View File

@ -29,10 +29,8 @@
class AP_ADSB {
public:
AP_ADSB()
{
AP_Param::setup_object_defaults(this, var_info);
}
// constructor
AP_ADSB();
/* Do not allow copies */
AP_ADSB(const AP_ADSB &other) = delete;
@ -88,7 +86,14 @@ public:
// confirm a value is a valid callsign
static bool is_valid_callsign(uint16_t octal) WARN_IF_UNUSED;
// get singleton instance
static AP_ADSB *get_singleton(void) {
return _singleton;
}
private:
static AP_ADSB *_singleton;
// initialize _vehicle_list
void init();
@ -202,4 +207,10 @@ private:
SPECIAL_ONLY = 1,
ALL = 2
};
};
namespace AP {
AP_ADSB *ADSB();
};