Browse Source

AP_Mission: add singleton

master
Peter Barker 7 years ago committed by Andrew Tridgell
parent
commit
16b49399db
  1. 12
      libraries/AP_Mission/AP_Mission.cpp
  2. 18
      libraries/AP_Mission/AP_Mission.h

12
libraries/AP_Mission/AP_Mission.cpp

@ -1768,3 +1768,15 @@ const char *AP_Mission::Mission_Command::type() const { @@ -1768,3 +1768,15 @@ const char *AP_Mission::Mission_Command::type() const {
return "?";
}
}
// singleton instance
AP_Mission *AP_Mission::_singleton;
namespace AP {
AP_Mission *mission()
{
return AP_Mission::get_singleton();
}
}

18
libraries/AP_Mission/AP_Mission.h

@ -291,6 +291,13 @@ public: @@ -291,6 +291,13 @@ public:
_prev_nav_cmd_wp_index(AP_MISSION_CMD_INDEX_NONE),
_last_change_time_ms(0)
{
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
if (_singleton != nullptr) {
AP_HAL::panic("Mission must be singleton");
}
#endif
_singleton = this;
// load parameter defaults
AP_Param::setup_object_defaults(this, var_info);
@ -304,6 +311,11 @@ public: @@ -304,6 +311,11 @@ public:
_flags.do_cmd_loaded = false;
}
// get singleton instance
static AP_Mission *get_singleton() {
return _singleton;
}
/* Do not allow copies */
AP_Mission(const AP_Mission &other) = delete;
AP_Mission &operator=(const AP_Mission&) = delete;
@ -470,6 +482,8 @@ public: @@ -470,6 +482,8 @@ public:
static const struct AP_Param::GroupInfo var_info[];
private:
static AP_Mission *_singleton;
static StorageAccess _storage;
struct Mission_Flags {
@ -563,3 +577,7 @@ private: @@ -563,3 +577,7 @@ private:
// const functions
static HAL_Semaphore_Recursive _rsem;
};
namespace AP {
AP_Mission *mission();
};

Loading…
Cancel
Save