Browse Source

AP_Vehicle: add singleton

master
Peter Barker 5 years ago committed by Peter Barker
parent
commit
9fee2a9c06
  1. 18
      libraries/AP_Vehicle/AP_Vehicle.cpp
  2. 21
      libraries/AP_Vehicle/AP_Vehicle.h

18
libraries/AP_Vehicle/AP_Vehicle.cpp

@ -0,0 +1,18 @@ @@ -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();
}
};

21
libraries/AP_Vehicle/AP_Vehicle.h

@ -36,7 +36,18 @@ class AP_Vehicle : public AP_HAL::HAL::Callbacks { @@ -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: @@ -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…
Cancel
Save