From 676303998069d16f943d0207cd7e4c40e0c930df Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Wed, 1 Jul 2015 09:10:30 -0700 Subject: [PATCH] Code cleanup - Whitespace changes These are only whitespace changes Signed-off-by: Mark Charlebois --- src/modules/uORB/ORBMap.hpp | 36 +++++++++++++------ src/modules/uORB/ORBSet.hpp | 34 +++++++++++++----- src/modules/uORB/Publication.cpp | 20 ++++++----- src/modules/uORB/Publication.hpp | 21 ++++++----- src/modules/uORB/topics/mission.h | 25 +++++++------ .../uORB/topics/multirotor_motor_limits.h | 8 ++--- src/modules/uORB/uORB.cpp | 26 +++++++------- src/modules/uORB/uORB.h | 2 +- src/modules/uORB/uORBCommon.hpp | 30 ++++++++-------- src/modules/uORB/uORBCommunicator.hpp | 31 +++++++++++----- src/modules/uORB/uORBDevices_nuttx.cpp | 2 ++ src/modules/uORB/uORBDevices_posix.cpp | 2 ++ src/modules/uORB/uORBTest_UnitTest.cpp | 11 ++++++ .../uorb_unittests/uORBCommunicatorMock.hpp | 2 +- 14 files changed, 160 insertions(+), 90 deletions(-) diff --git a/src/modules/uORB/ORBMap.hpp b/src/modules/uORB/ORBMap.hpp index e50725878b..3d26735809 100644 --- a/src/modules/uORB/ORBMap.hpp +++ b/src/modules/uORB/ORBMap.hpp @@ -39,8 +39,8 @@ namespace uORB { - class DeviceNode; - class ORBMap; +class DeviceNode; +class ORBMap; } class uORB::ORBMap @@ -48,7 +48,7 @@ class uORB::ORBMap public: struct Node { struct Node *next; - const char * node_name; + const char *node_name; uORB::DeviceNode *node; }; @@ -56,9 +56,11 @@ public: _top(nullptr), _end(nullptr) { } - ~ORBMap() { + ~ORBMap() + { while (_top != nullptr) { unlinkNext(_top); + if (_top->next == nullptr) { free((void *)_top->node_name); free(_top); @@ -67,20 +69,26 @@ public: } } } - void insert(const char *node_name, uORB::DeviceNode*node) + void insert(const char *node_name, uORB::DeviceNode *node) { Node **p; - if (_top == nullptr) + + if (_top == nullptr) { p = &_top; - else + + } else { p = &_end->next; + } *p = (Node *)malloc(sizeof(Node)); - if (_end) + + if (_end) { _end = _end->next; - else { + + } else { _end = _top; } + _end->next = nullptr; _end->node_name = strdup(node_name); _end->node = node; @@ -89,34 +97,42 @@ public: bool find(const char *node_name) { Node *p = _top; + while (p) { if (strcmp(p->node_name, node_name) == 0) { return true; } + p = p->next; } + return false; } - uORB::DeviceNode* get(const char *node_name) + uORB::DeviceNode *get(const char *node_name) { Node *p = _top; + while (p) { if (strcmp(p->node_name, node_name) == 0) { return p->node; } + p = p->next; } + return nullptr; } void unlinkNext(Node *a) { Node *b = a->next; + if (b != nullptr) { if (_end == b) { _end = a; } + a->next = b->next; free((void *)b->node_name); free(b); diff --git a/src/modules/uORB/ORBSet.hpp b/src/modules/uORB/ORBSet.hpp index 8b1e0d00fb..78c58625db 100644 --- a/src/modules/uORB/ORBSet.hpp +++ b/src/modules/uORB/ORBSet.hpp @@ -38,37 +38,45 @@ class ORBSet public: struct Node { struct Node *next; - const char * node_name; + const char *node_name; }; - ORBSet() : + ORBSet() : _top(nullptr), _end(nullptr) { } - ~ORBSet() { + ~ORBSet() + { while (_top != nullptr) { unlinkNext(_top); + if (_top->next == nullptr) { free((void *)_top->node_name); free(_top); _top = nullptr; } - } + } } void insert(const char *node_name) { Node **p; - if (_top == nullptr) + + if (_top == nullptr) { p = &_top; - else + + } else { p = &_end->next; + } *p = (Node *)malloc(sizeof(Node)); - if (_end) + + if (_end) { _end = _end->next; - else { + + } else { _end = _top; } + _end->next = nullptr; _end->node_name = strdup(node_name); } @@ -76,34 +84,42 @@ public: bool find(const char *node_name) { Node *p = _top; + while (p) { if (strcmp(p->node_name, node_name) == 0) { return true; } + p = p->next; } + return false; } bool erase(const char *node_name) { Node *p = _top; + if (_top && (strcmp(_top->node_name, node_name) == 0)) { p = _top->next; free((void *)_top->node_name); free(_top); _top = p; + if (_top == nullptr) { _end = nullptr; } + return true; } + while (p->next) { if (strcmp(p->next->node_name, node_name) == 0) { unlinkNext(p); return true; } } + return nullptr; } @@ -112,10 +128,12 @@ private: void unlinkNext(Node *a) { Node *b = a->next; + if (b != nullptr) { if (_end == b) { _end = a; } + a->next = b->next; free((void *)b->node_name); free(b); diff --git a/src/modules/uORB/Publication.cpp b/src/modules/uORB/Publication.cpp index 0ea8e5db51..bd8ecf13b4 100644 --- a/src/modules/uORB/Publication.cpp +++ b/src/modules/uORB/Publication.cpp @@ -51,31 +51,35 @@ #include "topics/tecs_status.h" #include "topics/rc_channels.h" -namespace uORB { +namespace uORB +{ template Publication::Publication( const struct orb_metadata *meta, - List * list) : + List *list) : T(), // initialize data structure to zero - PublicationNode(meta, list) { + PublicationNode(meta, list) +{ } template Publication::~Publication() {} template -void * Publication::getDataVoidPtr() { +void *Publication::getDataVoidPtr() +{ return (void *)(T *)(this); } PublicationNode::PublicationNode(const struct orb_metadata *meta, - List * list) : - PublicationBase(meta) { - if (list != nullptr) list->add(this); + List *list) : + PublicationBase(meta) +{ + if (list != nullptr) { list->add(this); } } - + template class __EXPORT Publication; template class __EXPORT Publication; diff --git a/src/modules/uORB/Publication.hpp b/src/modules/uORB/Publication.hpp index 6a0c733c64..f8af00e96d 100644 --- a/src/modules/uORB/Publication.hpp +++ b/src/modules/uORB/Publication.hpp @@ -64,16 +64,19 @@ public: */ PublicationBase(const struct orb_metadata *meta) : _meta(meta), - _handle(nullptr) { + _handle(nullptr) + { } /** * Update the struct * @param data The uORB message struct we are updating. */ - void update(void * data) { + void update(void *data) + { if (_handle != nullptr) { orb_publish(getMeta(), getHandle(), data); + } else { setHandle(orb_advertise(getMeta(), data)); } @@ -82,7 +85,8 @@ public: /** * Deconstructor */ - virtual ~PublicationBase() { + virtual ~PublicationBase() + { } // accessors const struct orb_metadata *getMeta() { return _meta; } @@ -95,9 +99,9 @@ protected: orb_advert_t _handle; private: // forbid copy - PublicationBase(const PublicationBase&) : _meta(), _handle() {}; + PublicationBase(const PublicationBase &) : _meta(), _handle() {}; // forbid assignment - PublicationBase& operator = (const PublicationBase &); + PublicationBase &operator = (const PublicationBase &); }; /** @@ -124,7 +128,7 @@ public: * that this should be appended to. */ PublicationNode(const struct orb_metadata *meta, - List * list=nullptr); + List *list = nullptr); /** * This function is the callback for list traversal @@ -151,7 +155,7 @@ public: * list during construction */ Publication(const struct orb_metadata *meta, - List * list=nullptr); + List *list = nullptr); /** * Deconstructor @@ -170,7 +174,8 @@ public: /** * Create an update function that uses the embedded struct. */ - void update() { + void update() + { PublicationBase::update(getDataVoidPtr()); } }; diff --git a/src/modules/uORB/topics/mission.h b/src/modules/uORB/topics/mission.h index 22a8f3ecb8..226ea2e980 100644 --- a/src/modules/uORB/topics/mission.h +++ b/src/modules/uORB/topics/mission.h @@ -50,17 +50,17 @@ /* compatible to mavlink MAV_CMD */ enum NAV_CMD { - NAV_CMD_IDLE=0, - NAV_CMD_WAYPOINT=16, - NAV_CMD_LOITER_UNLIMITED=17, - NAV_CMD_LOITER_TURN_COUNT=18, - NAV_CMD_LOITER_TIME_LIMIT=19, - NAV_CMD_RETURN_TO_LAUNCH=20, - NAV_CMD_LAND=21, - NAV_CMD_TAKEOFF=22, - NAV_CMD_ROI=80, - NAV_CMD_PATHPLANNING=81, - NAV_CMD_DO_JUMP=177 + NAV_CMD_IDLE = 0, + NAV_CMD_WAYPOINT = 16, + NAV_CMD_LOITER_UNLIMITED = 17, + NAV_CMD_LOITER_TURN_COUNT = 18, + NAV_CMD_LOITER_TIME_LIMIT = 19, + NAV_CMD_RETURN_TO_LAUNCH = 20, + NAV_CMD_LAND = 21, + NAV_CMD_TAKEOFF = 22, + NAV_CMD_ROI = 80, + NAV_CMD_PATHPLANNING = 81, + NAV_CMD_DO_JUMP = 177 }; enum ORIGIN { @@ -102,8 +102,7 @@ struct mission_item_s { * This topic used to notify navigator about mission changes, mission itself and new mission state * must be stored in dataman before publication. */ -struct mission_s -{ +struct mission_s { int dataman_id; /**< default 0, there are two offboard storage places in the dataman: 0 or 1 */ unsigned count; /**< count of the missions stored in the dataman */ int current_seq; /**< default -1, start at the one changed latest */ diff --git a/src/modules/uORB/topics/multirotor_motor_limits.h b/src/modules/uORB/topics/multirotor_motor_limits.h index 589f8a650c..30fd96b938 100644 --- a/src/modules/uORB/topics/multirotor_motor_limits.h +++ b/src/modules/uORB/topics/multirotor_motor_limits.h @@ -52,10 +52,10 @@ * Motor limits */ struct multirotor_motor_limits_s { - uint8_t lower_limit : 1; // at least one actuator command has saturated on the lower limit - uint8_t upper_limit : 1; // at least one actuator command has saturated on the upper limit - uint8_t yaw : 1; // yaw limit reached - uint8_t reserved : 5; // reserved + uint8_t lower_limit : 1; // at least one actuator command has saturated on the lower limit + uint8_t upper_limit : 1; // at least one actuator command has saturated on the upper limit + uint8_t yaw : 1; // yaw limit reached + uint8_t reserved : 5; // reserved }; /** diff --git a/src/modules/uORB/uORB.cpp b/src/modules/uORB/uORB.cpp index c1266552fe..d292628be0 100644 --- a/src/modules/uORB/uORB.cpp +++ b/src/modules/uORB/uORB.cpp @@ -62,7 +62,7 @@ */ orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data) { - return uORB::Manager::get_instance()->orb_advertise( meta, data ); + return uORB::Manager::get_instance()->orb_advertise(meta, data); } /** @@ -91,9 +91,9 @@ orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data) * this function will return -1 and set errno to ENOENT. */ orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance, - int priority) + int priority) { - return uORB::Manager::get_instance()->orb_advertise_multi( meta, data, instance, priority ); + return uORB::Manager::get_instance()->orb_advertise_multi(meta, data, instance, priority); } @@ -112,7 +112,7 @@ orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *da */ int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data) { - return uORB::Manager::get_instance()->orb_publish( meta, handle, data ); + return uORB::Manager::get_instance()->orb_publish(meta, handle, data); } /** @@ -143,7 +143,7 @@ int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const voi */ int orb_subscribe(const struct orb_metadata *meta) { - return uORB::Manager::get_instance()->orb_subscribe( meta ); + return uORB::Manager::get_instance()->orb_subscribe(meta); } /** @@ -177,7 +177,7 @@ int orb_subscribe(const struct orb_metadata *meta) */ int orb_subscribe_multi(const struct orb_metadata *meta, unsigned instance) { - return uORB::Manager::get_instance()->orb_subscribe_multi( meta, instance ); + return uORB::Manager::get_instance()->orb_subscribe_multi(meta, instance); } /** @@ -188,7 +188,7 @@ int orb_subscribe_multi(const struct orb_metadata *meta, unsigned instance) */ int orb_unsubscribe(int handle) { - return uORB::Manager::get_instance()->orb_unsubscribe( handle ); + return uORB::Manager::get_instance()->orb_unsubscribe(handle); } /** @@ -209,7 +209,7 @@ int orb_unsubscribe(int handle) */ int orb_copy(const struct orb_metadata *meta, int handle, void *buffer) { - return uORB::Manager::get_instance()->orb_copy( meta, handle, buffer ); + return uORB::Manager::get_instance()->orb_copy(meta, handle, buffer); } /** @@ -232,7 +232,7 @@ int orb_copy(const struct orb_metadata *meta, int handle, void *buffer) */ int orb_check(int handle, bool *updated) { - return uORB::Manager::get_instance()->orb_check( handle, updated ); + return uORB::Manager::get_instance()->orb_check(handle, updated); } /** @@ -245,7 +245,7 @@ int orb_check(int handle, bool *updated) */ int orb_stat(int handle, uint64_t *time) { - return uORB::Manager::get_instance()->orb_stat( handle, time ); + return uORB::Manager::get_instance()->orb_stat(handle, time); } /** @@ -257,7 +257,7 @@ int orb_stat(int handle, uint64_t *time) */ int orb_exists(const struct orb_metadata *meta, int instance) { - return uORB::Manager::get_instance()->orb_exists( meta, instance ); + return uORB::Manager::get_instance()->orb_exists(meta, instance); } /** @@ -272,7 +272,7 @@ int orb_exists(const struct orb_metadata *meta, int instance) */ int orb_priority(int handle, int *priority) { - return uORB::Manager::get_instance()->orb_priority( handle, priority ); + return uORB::Manager::get_instance()->orb_priority(handle, priority); } /** @@ -295,6 +295,6 @@ int orb_priority(int handle, int *priority) */ int orb_set_interval(int handle, unsigned interval) { - return uORB::Manager::get_instance()->orb_set_interval( handle, interval ); + return uORB::Manager::get_instance()->orb_set_interval(handle, interval); } diff --git a/src/modules/uORB/uORB.h b/src/modules/uORB/uORB.h index d8e826ec8f..3ae0f56a30 100644 --- a/src/modules/uORB/uORB.h +++ b/src/modules/uORB/uORB.h @@ -135,7 +135,7 @@ __BEGIN_DECLS * a file-descriptor-based handle would not otherwise be in scope for the * publisher. */ -typedef void * orb_advert_t; +typedef void *orb_advert_t; /** * Advertise as the publisher of a topic. diff --git a/src/modules/uORB/uORBCommon.hpp b/src/modules/uORB/uORBCommon.hpp index 06f731e823..be2ad8a89d 100644 --- a/src/modules/uORB/uORBCommon.hpp +++ b/src/modules/uORB/uORBCommon.hpp @@ -43,23 +43,23 @@ namespace uORB { - static const unsigned orb_maxpath = 64; +static const unsigned orb_maxpath = 64; - #ifdef ERROR - # undef ERROR - #endif - /* ERROR is not defined for c++ */ - const int ERROR = -1; +#ifdef ERROR +# undef ERROR +#endif +/* ERROR is not defined for c++ */ +const int ERROR = -1; - enum Flavor { - PUBSUB, - PARAM - }; +enum Flavor { + PUBSUB, + PARAM +}; - struct orb_advertdata { - const struct orb_metadata *meta; - int *instance; - int priority; - }; +struct orb_advertdata { + const struct orb_metadata *meta; + int *instance; + int priority; +}; } #endif // _uORBCommon_hpp_ diff --git a/src/modules/uORB/uORBCommunicator.hpp b/src/modules/uORB/uORBCommunicator.hpp index e7db2e464f..971ee3ab01 100644 --- a/src/modules/uORB/uORBCommunicator.hpp +++ b/src/modules/uORB/uORBCommunicator.hpp @@ -36,10 +36,11 @@ #include + namespace uORBCommunicator { - class IChannel; - class IChannelRxHandler; +class IChannel; +class IChannelRxHandler; } /** @@ -69,7 +70,9 @@ public: * Note: This does not mean that the receiver as received it. * otherwise = failure. */ - virtual int16_t add_subscription( const char *messageName, int32_t msgRateInHz ) = 0; + + virtual int16_t add_subscription(const char *messageName, int32_t msgRateInHz) = 0; + /** @@ -83,12 +86,14 @@ public: * Note: This does not necessarily mean that the receiver as received it. * otherwise = failure. */ - virtual int16_t remove_subscription( const char *messageName ) = 0; + + virtual int16_t remove_subscription(const char *messageName) = 0; + /** * Register Message Handler. This is internal for the IChannel implementer* */ - virtual int16_t register_handler( uORBCommunicator::IChannelRxHandler* handler ) = 0; + virtual int16_t register_handler(uORBCommunicator::IChannelRxHandler *handler) = 0; //========================================================================= @@ -109,7 +114,9 @@ public: * Note: This does not mean that the receiver as received it. * otherwise = failure. */ - virtual int16_t send_message( const char *messageName, int32_t length, uint8_t* data) = 0; + + virtual int16_t send_message(const char *messageName, int32_t length, uint8_t *data) = 0; + }; /** @@ -132,7 +139,9 @@ public: * handler. * otherwise = failure. */ - virtual int16_t process_add_subscription( const char *messageName, int32_t msgRateInHz ) = 0; + + virtual int16_t process_add_subscription(const char *messageName, int32_t msgRateInHz) = 0; + /** * Interface to process a received control msg to remove subscription @@ -144,7 +153,9 @@ public: * handler. * otherwise = failure. */ - virtual int16_t process_remove_subscription( const char *messageName ) = 0; + + virtual int16_t process_remove_subscription(const char *messageName) = 0; + /** * Interface to process the received data message. @@ -160,7 +171,9 @@ public: * handler. * otherwise = failure. */ - virtual int16_t process_received_message( const char *messageName, int32_t length, uint8_t* data ) = 0; + + virtual int16_t process_received_message(const char *messageName, int32_t length, uint8_t *data) = 0; + }; #endif /* _uORBCommunicator_hpp_ */ diff --git a/src/modules/uORB/uORBDevices_nuttx.cpp b/src/modules/uORB/uORBDevices_nuttx.cpp index 5d58dbcae9..5d0ce3b99e 100644 --- a/src/modules/uORB/uORBDevices_nuttx.cpp +++ b/src/modules/uORB/uORBDevices_nuttx.cpp @@ -639,10 +639,12 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg) if ((existing_node != nullptr) && !(existing_node->is_published())) { /* nothing has been published yet, lets claim it */ ret = OK; + } else { /* otherwise: data has already been published, keep looking */ } } + /* also discard the name now */ free((void *)objname); free((void *)devpath); diff --git a/src/modules/uORB/uORBDevices_posix.cpp b/src/modules/uORB/uORBDevices_posix.cpp index 96a46beea5..7c48c4ed79 100644 --- a/src/modules/uORB/uORBDevices_posix.cpp +++ b/src/modules/uORB/uORBDevices_posix.cpp @@ -655,10 +655,12 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) if ((existing_node != nullptr) && !(existing_node->is_published())) { /* nothing has been published yet, lets claim it */ ret = PX4_OK; + } else { /* otherwise: data has already been published, keep looking */ } } + /* also discard the name now */ free((void *)objname); free((void *)devpath); diff --git a/src/modules/uORB/uORBTest_UnitTest.cpp b/src/modules/uORB/uORBTest_UnitTest.cpp index 7a0c15b476..6b30e75b2f 100644 --- a/src/modules/uORB/uORBTest_UnitTest.cpp +++ b/src/modules/uORB/uORBTest_UnitTest.cpp @@ -141,17 +141,23 @@ int uORBTest::UnitTest::pubsublatency_main(void) int uORBTest::UnitTest::test() { int ret = test_single(); + if (ret != OK) { return ret; } + ret = test_multi(); + if (ret != OK) { return ret; } + ret = test_multi_reversed(); + if (ret != OK) { return ret; } + return OK; } @@ -323,16 +329,21 @@ int uORBTest::UnitTest::test_multi_reversed() /* Subscribe first and advertise afterwards. */ int sfd2 = orb_subscribe_multi(ORB_ID(orb_multitest), 2); + if (sfd2 < 0) { return test_fail("sub. id2: ret: %d", sfd2); } struct orb_test t, u; + t.val = 0; + int instance2; + orb_advert_t pfd2 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance2, ORB_PRIO_MAX); int instance3; + orb_advert_t pfd3 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance3, ORB_PRIO_MIN); test_note("advertised"); diff --git a/unittests/uorb_unittests/uORBCommunicatorMock.hpp b/unittests/uorb_unittests/uORBCommunicatorMock.hpp index e0cb3da532..8c5b861b1e 100644 --- a/unittests/uorb_unittests/uORBCommunicatorMock.hpp +++ b/unittests/uorb_unittests/uORBCommunicatorMock.hpp @@ -1,3 +1,4 @@ + /**************************************************************************** * * Copyright (c) 2015 Mark Charlebois. All rights reserved. @@ -75,7 +76,6 @@ class uORB_test::uORBCommunicatorMock : public uORBCommunicator::IChannel */ virtual int16_t add_subscription( const char *messageName, int32_t msgRateInHz ); - /** * @brief Interface to notify the remote entity of removal of a subscription *