module_base: remove CRTP template pattern to reduce flash bloat (#26476)

* module_base: claude rewrite to remove CRTP bloat

* module_base: apply to all drivers/modules

* format

* fix build errors

* fix missing syntax

* remove reference to module.h in files that need module_base.h

* remove old ModuleBase<T>

* add module_base.cpp to px4_protected_layers.cmake

* fix IridiumSBD can_stop()

* fix IridiumSBD.cpp

* clang-tidy: downcast static cast

* get_instance() template accessor, revert clang-tidy global

* rename module_base.h to module.h

* revert changes in zenoh/Kconfig.topics
This commit is contained in:
Jacob Dahl
2026-02-19 15:17:17 +13:00
committed by GitHub
parent 657854ae1b
commit ce3e62841f
227 changed files with 1741 additions and 1496 deletions
+21 -6
View File
@@ -117,7 +117,7 @@ struct GPS_Sat_Info {
static constexpr int TASK_STACK_SIZE = PX4_STACK_ADJUSTED(2040);
class GPS : public ModuleBase<GPS>, public device::Device
class GPS : public ModuleBase, public device::Device
{
public:
@@ -133,6 +133,8 @@ public:
unsigned configured_baudrate);
~GPS() override;
static Descriptor desc;
/** @see ModuleBase */
static int task_spawn(int argc, char *argv[]);
@@ -150,6 +152,11 @@ public:
/** @see ModuleBase */
static int print_usage(const char *reason = nullptr);
/**
* task spawn trampoline for the primary GPS
*/
static int run_trampoline(int argc, char *argv[]);
/**
* task spawn trampoline for the secondary GPS
*/
@@ -302,6 +309,7 @@ private:
px4::atomic_bool GPS::_is_gps_main_advertised{false};
px4::atomic<GPS *> GPS::_secondary_instance{nullptr};
ModuleBase::Descriptor GPS::desc{task_spawn, custom_command, print_usage};
/*
* Driver 'main' command.
@@ -1418,12 +1426,12 @@ int
GPS::custom_command(int argc, char *argv[])
{
// Check if the driver is running.
if (!is_running()) {
if (!is_running(desc)) {
PX4_INFO("not running");
return PX4_ERROR;
}
GPS *_instance = get_instance();
GPS *_instance = get_instance<GPS>(desc);
bool res = false;
@@ -1517,17 +1525,24 @@ int GPS::task_spawn(int argc, char *argv[], Instance instance)
entry_point, (char *const *)argv);
if (task_id < 0) {
_task_id = -1;
desc.task_id = -1;
return -errno;
}
if (instance == Instance::Main) {
_task_id = task_id;
desc.task_id = task_id;
}
return 0;
}
int GPS::run_trampoline(int argc, char *argv[])
{
return ModuleBase::run_trampoline_impl(desc, [](int ac, char *av[]) -> ModuleBase * {
return GPS::instantiate(ac, av);
}, argc, argv);
}
int GPS::run_trampoline_secondary(int argc, char *argv[])
{
// the task name is the first argument
@@ -1693,5 +1708,5 @@ GPS *GPS::instantiate(int argc, char *argv[], Instance instance)
int
gps_main(int argc, char *argv[])
{
return GPS::main(argc, argv);
return ModuleBase::main(GPS::desc, argc, argv);
}