AP_Vehicle: add singleton
This commit is contained in:
parent
2cc50afe7e
commit
9fee2a9c06
18
libraries/AP_Vehicle/AP_Vehicle.cpp
Normal file
18
libraries/AP_Vehicle/AP_Vehicle.cpp
Normal 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();
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user