Merge pull request #2501 from mcharleb/whitespace-cleanup

Code cleanup - Whitespace changes
This commit is contained in:
Lorenz Meier 2015-07-01 23:46:44 +02:00
commit af4cc8ec91
14 changed files with 160 additions and 90 deletions

View File

@ -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);

View File

@ -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);

View File

@ -51,31 +51,35 @@
#include "topics/tecs_status.h"
#include "topics/rc_channels.h"
namespace uORB {
namespace uORB
{
template<class T>
Publication<T>::Publication(
const struct orb_metadata *meta,
List<PublicationNode *> * list) :
List<PublicationNode *> *list) :
T(), // initialize data structure to zero
PublicationNode(meta, list) {
PublicationNode(meta, list)
{
}
template<class T>
Publication<T>::~Publication() {}
template<class T>
void * Publication<T>::getDataVoidPtr() {
void *Publication<T>::getDataVoidPtr()
{
return (void *)(T *)(this);
}
PublicationNode::PublicationNode(const struct orb_metadata *meta,
List<PublicationNode *> * list) :
PublicationBase(meta) {
if (list != nullptr) list->add(this);
List<PublicationNode *> *list) :
PublicationBase(meta)
{
if (list != nullptr) { list->add(this); }
}
template class __EXPORT Publication<vehicle_attitude_s>;
template class __EXPORT Publication<vehicle_local_position_s>;

View File

@ -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<PublicationNode *> * list=nullptr);
List<PublicationNode *> *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<PublicationNode *> * list=nullptr);
List<PublicationNode *> *list = nullptr);
/**
* Deconstructor
@ -170,7 +174,8 @@ public:
/**
* Create an update function that uses the embedded struct.
*/
void update() {
void update()
{
PublicationBase::update(getDataVoidPtr());
}
};

View File

@ -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 */

View File

@ -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
};
/**

View File

@ -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);
}

View File

@ -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.

View File

@ -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_

View File

@ -36,10 +36,11 @@
#include <stdint.h>
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_ */

View File

@ -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);

View File

@ -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);

View File

@ -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");

View File

@ -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
*