mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-02 00:31:36 +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:
@@ -55,8 +55,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern void init_app_map(map<string, px4_main_t> &apps);
|
||||
extern void list_builtins(map<string, px4_main_t> &apps);
|
||||
static px4_task_t g_dspal_task = -1;
|
||||
|
||||
__BEGIN_DECLS
|
||||
@@ -70,13 +68,13 @@ void qurt_external_hook(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void run_cmd(map<string, px4_main_t> &apps, const vector<string> &appargs)
|
||||
static void run_cmd(apps_map_type &apps, const vector<string> &appargs)
|
||||
{
|
||||
// command is appargs[0]
|
||||
string command = appargs[0];
|
||||
|
||||
//replaces app.find with iterator code to avoid null pointer exception
|
||||
for (map<string, px4_main_t>::iterator it = apps.begin(); it != apps.end(); ++it)
|
||||
for (apps_map_type::iterator it = apps.begin(); it != apps.end(); ++it)
|
||||
if (it->first == command) {
|
||||
// one for command name, one for null terminator
|
||||
const char *arg[MAX_ARGS + 2];
|
||||
@@ -117,7 +115,7 @@ void eat_whitespace(const char *&b, int &i)
|
||||
i = 0;
|
||||
}
|
||||
|
||||
static void process_commands(map<string, px4_main_t> &apps, const char *cmds)
|
||||
static void process_commands(apps_map_type &apps, const char *cmds)
|
||||
{
|
||||
vector<string> appargs;
|
||||
int i = 0;
|
||||
@@ -220,7 +218,7 @@ const char *get_commands()
|
||||
int dspal_entry(int argc, char *argv[])
|
||||
{
|
||||
PX4_INFO("In dspal_entry");
|
||||
map<string, px4_main_t> apps;
|
||||
apps_map_type apps;
|
||||
init_app_map(apps);
|
||||
DriverFramework::Framework::initialize();
|
||||
px4::init_once();
|
||||
|
||||
Reference in New Issue
Block a user