mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-21 09:22:18 +00: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:
74
src/platforms/apps.cpp.in
Normal file
74
src/platforms/apps.cpp.in
Normal file
@@ -0,0 +1,74 @@
|
||||
/* definitions of builtin command list - automatically generated, do not edit */
|
||||
#include "px4_posix.h"
|
||||
#include "px4_log.h"
|
||||
|
||||
#include "apps.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
extern void px4_show_devices(void);
|
||||
|
||||
void init_app_map(apps_map_type &apps)
|
||||
{
|
||||
${builtin_apps_string}
|
||||
apps["shutdown"] = shutdown_main;
|
||||
apps["list_tasks"] = list_tasks_main;
|
||||
apps["list_files"] = list_files_main;
|
||||
apps["list_devices"] = list_devices_main;
|
||||
apps["list_topics"] = list_topics_main;
|
||||
apps["sleep"] = sleep_main;
|
||||
}
|
||||
|
||||
void list_builtins(apps_map_type &apps)
|
||||
{
|
||||
PX4_INFO("Builtin Commands:\n");
|
||||
for (apps_map_type::iterator it = apps.begin(); it != apps.end(); ++it)
|
||||
PX4_INFO("%s : 0x%x\n", it->first.c_str(), it->second);
|
||||
}
|
||||
|
||||
int shutdown_main(int argc, char *argv[])
|
||||
{
|
||||
std::cout << "Shutting down" << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int list_tasks_main(int argc, char *argv[])
|
||||
{
|
||||
px4_show_tasks();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int list_devices_main(int argc, char *argv[])
|
||||
{
|
||||
px4_show_devices();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int list_topics_main(int argc, char *argv[])
|
||||
{
|
||||
px4_show_topics();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int list_files_main(int argc, char *argv[])
|
||||
{
|
||||
px4_show_files();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sleep_main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
PX4_WARN( "Usage: sleep <seconds>" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
unsigned long usecs = 1000000UL * atol(argv[1]);
|
||||
std::cout << "Sleeping for " << argv[1] << " s; (" << usecs << " us)." << std::endl;
|
||||
usleep(usecs);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user