From f5654511b84f4b948fcb035b66dab487c4de2adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 8 Sep 2016 14:53:54 +0200 Subject: [PATCH] uorb: more syntax changes to remove diff between nuttx & posix files --- src/modules/uORB/uORBDevices_nuttx.cpp | 41 +++++++++++++------------- src/modules/uORB/uORBDevices_nuttx.hpp | 41 ++++++++++++++++++-------- src/modules/uORB/uORBDevices_posix.cpp | 9 ++---- 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/src/modules/uORB/uORBDevices_nuttx.cpp b/src/modules/uORB/uORBDevices_nuttx.cpp index cf0edd387d..7ac10393c0 100644 --- a/src/modules/uORB/uORBDevices_nuttx.cpp +++ b/src/modules/uORB/uORBDevices_nuttx.cpp @@ -43,8 +43,9 @@ #include #include +using namespace device; -uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(struct file *filp) +uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(device::file_t *filp) { SubscriberData *sd = (SubscriberData *)(filp->f_priv); return sd; @@ -52,7 +53,7 @@ uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(struct file *filp uORB::DeviceNode::DeviceNode(const struct orb_metadata *meta, const char *name, const char *path, int priority, unsigned int queue_size) : - CDev(name, path), + VDev(name, path), _meta(meta), _data(nullptr), _last_update(0), @@ -77,7 +78,7 @@ uORB::DeviceNode::~DeviceNode() } int -uORB::DeviceNode::open(struct file *filp) +uORB::DeviceNode::open(device::file_t *filp) { int ret; @@ -88,7 +89,7 @@ uORB::DeviceNode::open(struct file *filp) lock(); if (_publisher == 0) { - _publisher = getpid(); + _publisher = px4_getpid(); ret = PX4_OK; } else { @@ -99,7 +100,7 @@ uORB::DeviceNode::open(struct file *filp) /* now complete the open */ if (ret == PX4_OK) { - ret = CDev::open(filp); + ret = VDev::open(filp); /* open failed - not the publisher anymore */ if (ret != PX4_OK) { @@ -130,7 +131,7 @@ uORB::DeviceNode::open(struct file *filp) filp->f_priv = (void *)sd; - ret = CDev::open(filp); + ret = VDev::open(filp); add_internal_subscriber(); @@ -147,10 +148,10 @@ uORB::DeviceNode::open(struct file *filp) } int -uORB::DeviceNode::close(struct file *filp) +uORB::DeviceNode::close(device::file_t *filp) { /* is this the publisher closing? */ - if (getpid() == _publisher) { + if (px4_getpid() == _publisher) { _publisher = 0; } else { @@ -167,11 +168,11 @@ uORB::DeviceNode::close(struct file *filp) } } - return CDev::close(filp); + return VDev::close(filp); } ssize_t -uORB::DeviceNode::read(struct file *filp, char *buffer, size_t buflen) +uORB::DeviceNode::read(device::file_t *filp, char *buffer, size_t buflen) { SubscriberData *sd = (SubscriberData *)filp_to_sd(filp); @@ -227,7 +228,7 @@ uORB::DeviceNode::read(struct file *filp, char *buffer, size_t buflen) } ssize_t -uORB::DeviceNode::write(struct file *filp, const char *buffer, size_t buflen) +uORB::DeviceNode::write(device::file_t *filp, const char *buffer, size_t buflen) { /* * Writes are legal from interrupt context as long as the @@ -282,7 +283,7 @@ uORB::DeviceNode::write(struct file *filp, const char *buffer, size_t buflen) } int -uORB::DeviceNode::ioctl(struct file *filp, int cmd, unsigned long arg) +uORB::DeviceNode::ioctl(device::file_t *filp, int cmd, unsigned long arg) { SubscriberData *sd = filp_to_sd(filp); @@ -354,7 +355,7 @@ uORB::DeviceNode::ioctl(struct file *filp, int cmd, unsigned long arg) default: /* give it to the superclass */ - return CDev::ioctl(filp, cmd, arg); + return VDev::ioctl(filp, cmd, arg); } } @@ -423,7 +424,7 @@ int uORB::DeviceNode::unadvertise(orb_advert_t handle) } pollevent_t -uORB::DeviceNode::poll_state(struct file *filp) +uORB::DeviceNode::poll_state(device::file_t *filp) { SubscriberData *sd = filp_to_sd(filp); @@ -438,15 +439,15 @@ uORB::DeviceNode::poll_state(struct file *filp) } void -uORB::DeviceNode::poll_notify_one(struct pollfd *fds, pollevent_t events) +uORB::DeviceNode::poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events) { - SubscriberData *sd = filp_to_sd((struct file *)fds->priv); + SubscriberData *sd = filp_to_sd((device::file_t *)fds->priv); /* * If the topic looks updated to the subscriber, go ahead and notify them. */ if (appears_updated(sd)) { - CDev::poll_notify_one(fds, events); + VDev::poll_notify_one(fds, events); } } @@ -677,7 +678,7 @@ int16_t uORB::DeviceNode::process_received_message(int32_t length, uint8_t *data } uORB::DeviceMaster::DeviceMaster(Flavor f) : - CDev((f == PUBSUB) ? "obj_master" : "param_master", + VDev((f == PUBSUB) ? "obj_master" : "param_master", (f == PUBSUB) ? TOPIC_MASTER_DEVICE_PATH : PARAM_MASTER_DEVICE_PATH), _flavor(f) { @@ -691,7 +692,7 @@ uORB::DeviceMaster::~DeviceMaster() } int -uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg) +uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) { int ret; @@ -798,7 +799,7 @@ uORB::DeviceMaster::ioctl(struct file *filp, int cmd, unsigned long arg) default: /* give it to the superclass */ - return CDev::ioctl(filp, cmd, arg); + return VDev::ioctl(filp, cmd, arg); } } diff --git a/src/modules/uORB/uORBDevices_nuttx.hpp b/src/modules/uORB/uORBDevices_nuttx.hpp index 3cab5ad29c..705d7716c7 100644 --- a/src/modules/uORB/uORBDevices_nuttx.hpp +++ b/src/modules/uORB/uORBDevices_nuttx.hpp @@ -34,10 +34,27 @@ #pragma once #include +#include "uORBCommon.hpp" + + +#ifdef __PX4_NUTTX #include #include #include "ORBMap.hpp" -#include "uORBCommon.hpp" + +namespace device { +//type mappings to NuttX +typedef ::file file_t; +typedef CDev VDev; +} + +#else + +#include +#include + +#endif /* __PX4_NUTTX */ + namespace uORB @@ -50,7 +67,7 @@ class Manager; /** * Per-object device instance. */ -class uORB::DeviceNode : public device::CDev +class uORB::DeviceNode : public device::VDev { public: DeviceNode(const struct orb_metadata *meta, const char *name, const char *path, @@ -61,12 +78,12 @@ public: * Method to create a subscriber instance and return the struct * pointing to the subscriber as a file pointer. */ - virtual int open(struct file *filp); + virtual int open(device::file_t *filp); /** * Method to close a subscriber for this topic. */ - virtual int close(struct file *filp); + virtual int close(device::file_t *filp); /** * reads data from a subscriber node to the buffer provided. @@ -79,7 +96,7 @@ public: * @return * ssize_t the number of bytes read. */ - virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); + virtual ssize_t read(device::file_t *filp, char *buffer, size_t buflen); /** * writes the published data to the internal buffer to be read by @@ -93,12 +110,12 @@ public: * @return ssize_t * The number of bytes that are written */ - virtual ssize_t write(struct file *filp, const char *buffer, size_t buflen); + virtual ssize_t write(device::file_t *filp, const char *buffer, size_t buflen); /** * IOCTL control for the subscriber. */ - virtual int ioctl(struct file *filp, int cmd, unsigned long arg); + virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg); /** * Method to publish a data to this node. @@ -174,8 +191,8 @@ public: const struct orb_metadata *meta() const { return _meta; } protected: - virtual pollevent_t poll_state(struct file *filp); - virtual void poll_notify_one(struct pollfd *fds, pollevent_t events); + virtual pollevent_t poll_state(device::file_t *filp); + virtual void poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events); private: struct UpdateIntervalData { @@ -206,7 +223,7 @@ private: bool _published; /**< has ever data been published */ unsigned int _queue_size; /**< maximum number of elements in the queue */ - inline static SubscriberData *filp_to_sd(struct file *filp); + inline static SubscriberData *filp_to_sd(device::file_t *filp); bool _IsRemoteSubscriberPresent; int32_t _subscriber_count; @@ -249,10 +266,10 @@ private: * Used primarily to create new objects via the ORBIOCCREATE * ioctl. */ -class uORB::DeviceMaster : public device::CDev +class uORB::DeviceMaster : public device::VDev { public: - virtual int ioctl(struct file *filp, int cmd, unsigned long arg); + virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg); /** * Public interface for getDeviceNodeLocked(). Takes care of synchronization. diff --git a/src/modules/uORB/uORBDevices_posix.cpp b/src/modules/uORB/uORBDevices_posix.cpp index e3b937a0b5..a26e0c6f27 100644 --- a/src/modules/uORB/uORBDevices_posix.cpp +++ b/src/modules/uORB/uORBDevices_posix.cpp @@ -44,6 +44,7 @@ #include #include +using namespace device; uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(device::file_t *filp) { @@ -288,7 +289,6 @@ uORB::DeviceNode::write(device::file_t *filp, const char *buffer, size_t buflen) int uORB::DeviceNode::ioctl(device::file_t *filp, int cmd, unsigned long arg) { - //warnx("uORB::DeviceNode::ioctl fd = %d cmd = %d", filp->fd, cmd); SubscriberData *sd = filp_to_sd(filp); switch (cmd) { @@ -433,7 +433,6 @@ int uORB::DeviceNode::unadvertise(orb_advert_t handle) pollevent_t uORB::DeviceNode::poll_state(device::file_t *filp) { - //warnx("uORB::DeviceNode::poll_state fd = %d", filp->fd); SubscriberData *sd = filp_to_sd(filp); /* @@ -449,7 +448,6 @@ uORB::DeviceNode::poll_state(device::file_t *filp) void uORB::DeviceNode::poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events) { - //warnx("uORB::DeviceNode::poll_notify_one fds = %p fds->priv = %p", fds, fds->priv); SubscriberData *sd = filp_to_sd((device::file_t *)fds->priv); /* @@ -469,7 +467,6 @@ uORB::DeviceNode::appears_updated(SubscriberData *sd) usleep(100); } - //warnx("uORB::DeviceNode::appears_updated sd = %p", sd); /* assume it doesn't look updated */ bool ret = false; @@ -671,7 +668,6 @@ int16_t uORB::DeviceNode::process_received_message(int32_t length, uint8_t *data return PX4_OK; } - uORB::DeviceMaster::DeviceMaster(Flavor f) : VDev((f == PUBSUB) ? "obj_master" : "param_master", (f == PUBSUB) ? TOPIC_MASTER_DEVICE_PATH : PARAM_MASTER_DEVICE_PATH), @@ -781,7 +777,6 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) _node_map[std::string(nodepath)] = node; } - group_tries++; } while (ret != PX4_OK && (group_tries < max_group_tries)); @@ -807,9 +802,9 @@ void uORB::DeviceMaster::printStatistics(bool reset) _last_statistics_output = current_time; PX4_INFO("TOPIC, NR LOST MSGS"); + bool had_print = false; lock(); - bool had_print = false; for (const auto &node : _node_map) { if (node.second->print_statistics(reset)) {