mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 06:03:34 +08:00
Clean up of app.h
app.h, generated from app.h_in, has unnecessary code duplication and isn't a header file (it defines globals, static functions and doesn't have a header guard, moreover, it has a 'using namespace std;'). Because of this, a real headerfile that declares the stuff defined in apps.h was missing leading to even more code duplication: scattered forward declarations in .cpp files and an often repeated type of std::map<std::string, px4_main_t>. This patch moves cmake/qurt/apps.h_in to src/platforms/apps.cpp.in (with some changes) and removes cmake/posix/apps.h_in. Then src/platforms/apps.cpp.in is split into src/platforms/apps.cpp.in and src/platforms/apps.h.in, splitting declarations from definitions. A typedef is defined for the map (apps_map_type). The main difference between cmake/posix/apps.h_in and cmake/qurt/apps.h_in was that the first defined a global 'apps', while qurt stores the apps in QShell. I opted to get rid of the global variable (which are in general evil for various reasons) and used the API of cmake/qurt/apps.h_in where a provided 'apps' map is initialized with a call to init_app_map. Thus removing the existing code duplication.
This commit is contained in:
@@ -48,6 +48,8 @@
|
||||
#include <stdio.h>
|
||||
#include "apps.h"
|
||||
#include "px4_middleware.h"
|
||||
#include "px4_posix.h"
|
||||
#include "px4_log.h"
|
||||
#include "DriverFramework.hpp"
|
||||
#include <termios.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -191,6 +193,14 @@ static void print_prompt()
|
||||
|
||||
static void run_cmd(const vector<string> &appargs, bool exit_on_fail, bool silently_fail = false)
|
||||
{
|
||||
static apps_map_type apps;
|
||||
static bool initialized = false;
|
||||
|
||||
if (!initialized) {
|
||||
init_app_map(apps);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
// command is appargs[0]
|
||||
string command = appargs[0];
|
||||
|
||||
@@ -217,7 +227,7 @@ static void run_cmd(const vector<string> &appargs, bool exit_on_fail, bool silen
|
||||
}
|
||||
|
||||
} else if (command.compare("help") == 0) {
|
||||
list_builtins();
|
||||
list_builtins(apps);
|
||||
|
||||
} else if (command.length() == 0 || command[0] == '#') {
|
||||
// Do nothing
|
||||
|
||||
Reference in New Issue
Block a user