diff options
author | Mark Charlebois <charlebm@gmail.com> | 2015-03-13 16:39:41 -0700 |
---|---|---|
committer | Mark Charlebois <charlebm@gmail.com> | 2015-04-20 11:00:18 -0700 |
commit | 938751993d2c5539c5cc6904e84bb62ed8145357 (patch) | |
tree | d7d0dc4eb29ae24f44553d757fc4896a81ee98e3 | |
parent | 5259f1c861d09a94601f5c21cf09d726b10c87f7 (diff) | |
download | px4-firmware-938751993d2c5539c5cc6904e84bb62ed8145357.tar.gz px4-firmware-938751993d2c5539c5cc6904e84bb62ed8145357.tar.bz2 px4-firmware-938751993d2c5539c5cc6904e84bb62ed8145357.zip |
Changed AppMgr to AppState
The previous name implied some kind of daemon. AppState is
aggregated state of an application's running state and interfaces
to request app termination, and check app state.
Signed-off-by: Mark Charlebois <charlebm@gmail.com>
-rw-r--r-- | src/platforms/linux/hello/hello_example.cpp | 6 | ||||
-rw-r--r-- | src/platforms/linux/hello/hello_example.h | 2 | ||||
-rw-r--r-- | src/platforms/linux/hello/hello_start_linux.cpp | 6 | ||||
-rw-r--r-- | src/platforms/linux/vcdev_test/vcdevtest_example.cpp | 19 | ||||
-rw-r--r-- | src/platforms/linux/vcdev_test/vcdevtest_example.h | 2 | ||||
-rw-r--r-- | src/platforms/linux/vcdev_test/vcdevtest_start_linux.cpp | 6 | ||||
-rw-r--r-- | src/platforms/px4_app.h | 30 | ||||
-rw-r--r-- | src/platforms/px4_nodehandle.h | 8 |
8 files changed, 45 insertions, 34 deletions
diff --git a/src/platforms/linux/hello/hello_example.cpp b/src/platforms/linux/hello/hello_example.cpp index 7881b73d6..a30aeb57b 100644 --- a/src/platforms/linux/hello/hello_example.cpp +++ b/src/platforms/linux/hello/hello_example.cpp @@ -43,14 +43,14 @@ #include <unistd.h> #include <stdio.h> -px4::AppMgr HelloExample::mgr; +px4::AppState HelloExample::appState; int HelloExample::main() { - mgr.setRunning(true); + appState.setRunning(true); int i=0; - while (!mgr.exitRequested() && i<5) { + while (!appState.exitRequested() && i<5) { sleep(2); printf(" Doing work...\n"); diff --git a/src/platforms/linux/hello/hello_example.h b/src/platforms/linux/hello/hello_example.h index b736f60bc..a4ae51705 100644 --- a/src/platforms/linux/hello/hello_example.h +++ b/src/platforms/linux/hello/hello_example.h @@ -49,5 +49,5 @@ public: int main(); - static px4::AppMgr mgr; /* Manage requests to terminate app */ + static px4::AppState appState; /* track requests to terminate app */ }; diff --git a/src/platforms/linux/hello/hello_start_linux.cpp b/src/platforms/linux/hello/hello_start_linux.cpp index a7d21fa59..240c5d845 100644 --- a/src/platforms/linux/hello/hello_start_linux.cpp +++ b/src/platforms/linux/hello/hello_start_linux.cpp @@ -63,7 +63,7 @@ int hello_main(int argc, char *argv[]) if (!strcmp(argv[1], "start")) { - if (HelloExample::mgr.isRunning()) { + if (HelloExample::appState.isRunning()) { printf("already running\n"); /* this is not an error */ return 0; @@ -80,12 +80,12 @@ int hello_main(int argc, char *argv[]) } if (!strcmp(argv[1], "stop")) { - HelloExample::mgr.requestExit(); + HelloExample::appState.requestExit(); return 0; } if (!strcmp(argv[1], "status")) { - if (HelloExample::mgr.isRunning()) { + if (HelloExample::appState.isRunning()) { printf("is running\n"); } else { diff --git a/src/platforms/linux/vcdev_test/vcdevtest_example.cpp b/src/platforms/linux/vcdev_test/vcdevtest_example.cpp index 5650b4640..39c804ada 100644 --- a/src/platforms/linux/vcdev_test/vcdevtest_example.cpp +++ b/src/platforms/linux/vcdev_test/vcdevtest_example.cpp @@ -45,7 +45,7 @@ #include <unistd.h> #include <stdio.h> -px4::AppMgr VCDevExample::mgr; +px4::AppState VCDevExample::appState; using namespace device; @@ -117,7 +117,7 @@ int test_pub_block(int fd, unsigned long blocked) int VCDevExample::main() { - mgr.setRunning(true); + appState.setRunning(true); _node = new VCDevNode(); @@ -164,7 +164,7 @@ int VCDevExample::main() writer_main, (char* const*)NULL); - while (!mgr.exitRequested() && i<5) { + while (!appState.exitRequested() && i<3) { sleep(2); printf(" polling...\n"); @@ -179,12 +179,15 @@ int VCDevExample::main() printf("poll failed %d %d\n", ret, px4_errno); px4_close(fd); } - else if (ret == 0) - printf(" Nothing to read\n"); - else { - printf(" %d to read\n", ret); + else if (i > 0 && ret == 0) + printf(" Nothing to read - PASS\n"); + else if (i == 0) { + if (ret == 1) + printf(" %d to read - %s\n", ret, fds[0].revents & POLLIN ? "PASS" : "FAIL"); + else + printf(" %d to read - FAIL\n", ret); + } - printf(" Doing work...\n"); ++i; } px4_close(fd); diff --git a/src/platforms/linux/vcdev_test/vcdevtest_example.h b/src/platforms/linux/vcdev_test/vcdevtest_example.h index ed00fd5cb..4898210df 100644 --- a/src/platforms/linux/vcdev_test/vcdevtest_example.h +++ b/src/platforms/linux/vcdev_test/vcdevtest_example.h @@ -51,7 +51,7 @@ public: int main(); - static px4::AppMgr mgr; /* Manage requests to terminate app */ + static px4::AppState appState; /* track requests to terminate app */ private: VCDevNode *_node; diff --git a/src/platforms/linux/vcdev_test/vcdevtest_start_linux.cpp b/src/platforms/linux/vcdev_test/vcdevtest_start_linux.cpp index c00613611..9adb65085 100644 --- a/src/platforms/linux/vcdev_test/vcdevtest_start_linux.cpp +++ b/src/platforms/linux/vcdev_test/vcdevtest_start_linux.cpp @@ -58,7 +58,7 @@ int vcdevtest_main(int argc, char *argv[]) if (!strcmp(argv[1], "start")) { - if (VCDevExample::mgr.isRunning()) { + if (VCDevExample::appState.isRunning()) { printf("already running\n"); /* this is not an error */ return 0; @@ -75,12 +75,12 @@ int vcdevtest_main(int argc, char *argv[]) } if (!strcmp(argv[1], "stop")) { - VCDevExample::mgr.requestExit(); + VCDevExample::appState.requestExit(); return 0; } if (!strcmp(argv[1], "status")) { - if (VCDevExample::mgr.isRunning()) { + if (VCDevExample::appState.isRunning()) { printf("is running\n"); } else { diff --git a/src/platforms/px4_app.h b/src/platforms/px4_app.h index 2c9765ae2..9aa285e22 100644 --- a/src/platforms/px4_app.h +++ b/src/platforms/px4_app.h @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright (c) 2015 Mark Charlebois. All rights reserved. + * Copyright (c) 2015 Mark Charlebois. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,21 +31,28 @@ * ****************************************************************************/ +/** + * @file px4_app.h + * + * PX4 app template classes, functions and defines. Apps need to call their + * main function PX4_MAIN. + */ + #pragma once namespace px4 { -class AppMgr { +class AppState { public: - ~AppMgr() {} + ~AppState() {} #if defined(__PX4_ROS) - AppMgr() {} + AppState() {} bool exitRequested() { return !ros::ok(); } void requestExit() { ros::shutdown(); } #else - AppMgr() : _exitRequested(false), _isRunning(false) {} + AppState() : _exitRequested(false), _isRunning(false) {} bool exitRequested() { return _exitRequested; } void requestExit() { _exitRequested = true; } @@ -58,22 +65,23 @@ protected: bool _isRunning; #endif private: - AppMgr(const AppMgr&); - const AppMgr& operator=(const AppMgr&); + AppState(const AppState&); + const AppState& operator=(const AppState&); }; } +// PX4_MAIN is defined if module.mk sets MODULE_COMMAND +// For ROS and NuttX it is "main" and for Linux it is +// $(MODULE_COMMAND)_app_main since some apps already +// define $(MODULE_COMMAND)_main + // Task/process based build #if defined(__PX4_ROS) || defined(__PX4_NUTTX) // Thread based build #else -// The name passed must be globally unique -// set PX4_APPMAIN in module.mk -// EXTRADEFINES += -DPX4_MAIN=foo_app #ifdef PX4_MAIN - extern int PX4_MAIN(int argc, char *argv[]); #endif diff --git a/src/platforms/px4_nodehandle.h b/src/platforms/px4_nodehandle.h index c45ce5cc7..e4a483de6 100644 --- a/src/platforms/px4_nodehandle.h +++ b/src/platforms/px4_nodehandle.h @@ -142,11 +142,11 @@ protected: class __EXPORT NodeHandle { public: - NodeHandle(AppMgr &a) : + NodeHandle(AppState &a) : _subs(), _pubs(), _sub_min_interval(nullptr), - _mgr(a) + _appState(a) {} ~NodeHandle() @@ -264,7 +264,7 @@ public: */ void spin() { - while (!_mgr.exitRequested()) { + while (!_appState.exitRequested()) { const int timeout_ms = 100; /* Only continue in the loop if the nodehandle has subscriptions */ @@ -289,7 +289,7 @@ protected: SubscriberNode *_sub_min_interval; /**< Points to the sub wtih the smallest interval of all Subscriptions in _subs*/ - AppMgr &_mgr; + AppState &_appState; /** * Check if this is the smallest interval so far and update _sub_min_interval |