AP_Vehicle: add singleton

This commit is contained in:
Peter Barker 2019-10-09 09:36:46 +11:00 committed by Peter Barker
parent 2cc50afe7e
commit 9fee2a9c06
2 changed files with 38 additions and 1 deletions

View File

@ -0,0 +1,18 @@
#include <AP_Vehicle/AP_Vehicle.h>
AP_Vehicle *AP_Vehicle::_singleton = nullptr;
AP_Vehicle *AP_Vehicle::get_singleton()
{
return _singleton;
}
namespace AP {
AP_Vehicle *vehicle()
{
return AP_Vehicle::get_singleton();
}
};

View File

@ -36,7 +36,18 @@ class AP_Vehicle : public AP_HAL::HAL::Callbacks {
public:
AP_Vehicle() {}
AP_Vehicle() {
if (_singleton) {
AP_HAL::panic("Too many Vehicles");
}
_singleton = this;
}
/* Do not allow copies */
AP_Vehicle(const AP_Vehicle &other) = delete;
AP_Vehicle &operator=(const AP_Vehicle&) = delete;
static AP_Vehicle *get_singleton();
/*
common parameters for fixed wing aircraft
@ -121,6 +132,14 @@ protected:
// false disables external leds)
AP_Notify notify;
private:
static AP_Vehicle *_singleton;
};
namespace AP {
AP_Vehicle *vehicle();
};
extern const AP_HAL::HAL& hal;