mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-19 11:13:34 +08:00
orb_advert_t changed to void * and checks changed to nullptr
The existing orb_advert_t use thoughout the code sometimes tries to treat it as a file descriptor and there are checks for < 0 and ::close calls on orb_advert_t types which is an invalid use of an object pointer, which is what orb_advert_t really is. Initially I had changed the -1 initializations to 0 but it was suggested that this should be nullptr. That was a good recommendation but the definition of orb_advert_t had to change to void * because you cannot initialize a uintptr_t as nullptr. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
committed by
Lorenz Meier
parent
180c8b0cb0
commit
1ca05aaa64
@@ -64,7 +64,7 @@ public:
|
||||
*/
|
||||
PublicationBase(const struct orb_metadata *meta) :
|
||||
_meta(meta),
|
||||
_handle(-1) {
|
||||
_handle(nullptr) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
* @param data The uORB message struct we are updating.
|
||||
*/
|
||||
void update(void * data) {
|
||||
if (_handle > 0) {
|
||||
if (_handle != nullptr) {
|
||||
orb_publish(getMeta(), getHandle(), data);
|
||||
} else {
|
||||
setHandle(orb_advertise(getMeta(), data));
|
||||
@@ -83,11 +83,10 @@ public:
|
||||
* Deconstructor
|
||||
*/
|
||||
virtual ~PublicationBase() {
|
||||
orb_unsubscribe(getHandle());
|
||||
}
|
||||
// accessors
|
||||
const struct orb_metadata *getMeta() { return _meta; }
|
||||
int getHandle() { return _handle; }
|
||||
orb_advert_t getHandle() { return _handle; }
|
||||
protected:
|
||||
// accessors
|
||||
void setHandle(orb_advert_t handle) { _handle = handle; }
|
||||
|
||||
@@ -135,7 +135,7 @@ __BEGIN_DECLS
|
||||
* a file-descriptor-based handle would not otherwise be in scope for the
|
||||
* publisher.
|
||||
*/
|
||||
typedef uintptr_t orb_advert_t;
|
||||
typedef void * orb_advert_t;
|
||||
|
||||
/**
|
||||
* Advertise as the publisher of a topic.
|
||||
|
||||
@@ -73,11 +73,11 @@ class uORB::Manager
|
||||
* @param data A pointer to the initial data to be published.
|
||||
* For topics updated by interrupt handlers, the advertisement
|
||||
* must be performed from non-interrupt context.
|
||||
* @return ERROR on error, otherwise returns a handle
|
||||
* @return nullptr on error, otherwise returns an object pointer
|
||||
* that can be used to publish to the topic.
|
||||
* If the topic in question is not known (due to an
|
||||
* ORB_DEFINE with no corresponding ORB_DECLARE)
|
||||
* this function will return -1 and set errno to ENOENT.
|
||||
* this function will return nullptr and set errno to ENOENT.
|
||||
*/
|
||||
orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *data);
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
|
||||
fd = node_open(PUBSUB, meta, data, true, instance, priority);
|
||||
if (fd == ERROR) {
|
||||
warnx("node_open as advertiser failed.");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* get the advertiser handle and close the node */
|
||||
@@ -102,14 +102,14 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
|
||||
px4_close(fd);
|
||||
if (result == ERROR) {
|
||||
warnx("px4_ioctl ORBIOCGADVERTISER failed. fd = %d", fd);
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* the advertiser must perform an initial publish to initialise the object */
|
||||
result = orb_publish(meta, advertiser, data);
|
||||
if (result == ERROR) {
|
||||
warnx("orb_publish failed");
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return advertiser;
|
||||
|
||||
@@ -192,7 +192,7 @@ int uORBTest::UnitTest::test()
|
||||
test_note("try multi-topic support");
|
||||
|
||||
int instance0;
|
||||
int pfd0 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance0, ORB_PRIO_MAX);
|
||||
orb_advert_t pfd0 = orb_advertise_multi(ORB_ID(orb_multitest), &t, &instance0, ORB_PRIO_MAX);
|
||||
|
||||
test_note("advertised");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user