make vdev file flags and priv consistent with nuttx

This commit is contained in:
Daniel Agar
2018-11-23 08:15:48 +01:00
committed by Beat Küng
parent f9a3235709
commit f1bf7172e7
3 changed files with 17 additions and 25 deletions
+5 -5
View File
@@ -17,12 +17,12 @@ using px4_file_operations_t = struct file_operations;
using mode_t = uint32_t; using mode_t = uint32_t;
struct file_t { struct file_t {
int flags; int f_oflags{0};
void *priv; void *f_priv{nullptr};
void *vdev; void *vdev{nullptr};
file_t() : flags(0), priv(nullptr), vdev(nullptr) {} file_t() = default;
file_t(int f, void *c) : flags(f), priv(nullptr), vdev(c) {} file_t(int f, void *c) : f_oflags(f), vdev(c) {}
}; };
} // namespace cdev } // namespace cdev
+5 -13
View File
@@ -33,14 +33,6 @@
#include "uORBDeviceNode.hpp" #include "uORBDeviceNode.hpp"
#ifdef __PX4_NUTTX
#define FILE_FLAGS(filp) filp->f_oflags
#define FILE_PRIV(filp) filp->f_priv
#else
#define FILE_FLAGS(filp) filp->flags
#define FILE_PRIV(filp) filp->priv
#endif
#include "uORBDeviceNode.hpp" #include "uORBDeviceNode.hpp"
#include "uORBUtils.hpp" #include "uORBUtils.hpp"
#include "uORBManager.hpp" #include "uORBManager.hpp"
@@ -58,7 +50,7 @@ uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(cdev::file_t *fil
} }
#endif #endif
return (SubscriberData *)(FILE_PRIV(filp)); return (SubscriberData *)(filp->f_priv);
} }
uORB::DeviceNode::DeviceNode(const struct orb_metadata *meta, const char *path, int priority, unsigned int queue_size) : uORB::DeviceNode::DeviceNode(const struct orb_metadata *meta, const char *path, int priority, unsigned int queue_size) :
@@ -82,7 +74,7 @@ uORB::DeviceNode::open(cdev::file_t *filp)
int ret; int ret;
/* is this a publisher? */ /* is this a publisher? */
if (FILE_FLAGS(filp) == PX4_F_WRONLY) { if (filp->f_oflags == PX4_F_WRONLY) {
/* become the publisher if we can */ /* become the publisher if we can */
lock(); lock();
@@ -111,7 +103,7 @@ uORB::DeviceNode::open(cdev::file_t *filp)
} }
/* is this a new subscriber? */ /* is this a new subscriber? */
if (FILE_FLAGS(filp) == PX4_F_RDONLY) { if (filp->f_oflags == PX4_F_RDONLY) {
/* allocate subscriber data */ /* allocate subscriber data */
SubscriberData *sd = new SubscriberData{}; SubscriberData *sd = new SubscriberData{};
@@ -123,7 +115,7 @@ uORB::DeviceNode::open(cdev::file_t *filp)
/* If there were any previous publications, allow the subscriber to read them */ /* If there were any previous publications, allow the subscriber to read them */
sd->generation = _generation - (_queue_size < _generation ? _queue_size : _generation); sd->generation = _generation - (_queue_size < _generation ? _queue_size : _generation);
FILE_PRIV(filp) = (void *)sd; filp->f_priv = (void *)sd;
ret = CDev::open(filp); ret = CDev::open(filp);
@@ -137,7 +129,7 @@ uORB::DeviceNode::open(cdev::file_t *filp)
return ret; return ret;
} }
if (FILE_FLAGS(filp) == 0) { if (filp->f_oflags == 0) {
return CDev::open(filp); return CDev::open(filp);
} }
@@ -120,7 +120,7 @@ private:
int VCDevNode::open(cdev::file_t *handlep) int VCDevNode::open(cdev::file_t *handlep)
{ {
// Only allow one writer // Only allow one writer
if (_is_open_for_write && (handlep->flags & PX4_F_WRONLY)) { if (_is_open_for_write && (handlep->f_oflags & PX4_F_WRONLY)) {
errno = EBUSY; errno = EBUSY;
return -1; return -1;
} }
@@ -131,9 +131,9 @@ int VCDevNode::open(cdev::file_t *handlep)
return ret; return ret;
} }
handlep->priv = new PrivData; handlep->f_priv = new PrivData;
if (_is_open_for_write && (handlep->flags & PX4_F_WRONLY)) { if (_is_open_for_write && (handlep->f_oflags & PX4_F_WRONLY)) {
_is_open_for_write = true; _is_open_for_write = true;
} }
@@ -142,12 +142,12 @@ int VCDevNode::open(cdev::file_t *handlep)
int VCDevNode::close(cdev::file_t *handlep) int VCDevNode::close(cdev::file_t *handlep)
{ {
delete (PrivData *)handlep->priv; delete (PrivData *)handlep->f_priv;
handlep->priv = nullptr; handlep->f_priv = nullptr;
CDev::close(handlep); CDev::close(handlep);
// Enable a new writer of the device is re-opened for write // Enable a new writer of the device is re-opened for write
if ((handlep->flags & PX4_F_WRONLY) && _is_open_for_write) { if ((handlep->f_oflags & PX4_F_WRONLY) && _is_open_for_write) {
_is_open_for_write = false; _is_open_for_write = false;
} }
@@ -169,7 +169,7 @@ ssize_t VCDevNode::write(cdev::file_t *handlep, const char *buffer, size_t bufle
ssize_t VCDevNode::read(cdev::file_t *handlep, char *buffer, size_t buflen) ssize_t VCDevNode::read(cdev::file_t *handlep, char *buffer, size_t buflen)
{ {
PrivData *p = (PrivData *)handlep->priv; PrivData *p = (PrivData *)handlep->f_priv;
ssize_t chars_read = 0; ssize_t chars_read = 0;
PX4_INFO("read %zu write %zu", p->_read_offset, _write_offset); PX4_INFO("read %zu write %zu", p->_read_offset, _write_offset);