forked from Archive/PX4-Autopilot
make vdev file flags and priv consistent with nuttx
This commit is contained in:
parent
f9a3235709
commit
f1bf7172e7
|
@ -17,12 +17,12 @@ using px4_file_operations_t = struct file_operations;
|
|||
using mode_t = uint32_t;
|
||||
|
||||
struct file_t {
|
||||
int flags;
|
||||
void *priv;
|
||||
void *vdev;
|
||||
int f_oflags{0};
|
||||
void *f_priv{nullptr};
|
||||
void *vdev{nullptr};
|
||||
|
||||
file_t() : flags(0), priv(nullptr), vdev(nullptr) {}
|
||||
file_t(int f, void *c) : flags(f), priv(nullptr), vdev(c) {}
|
||||
file_t() = default;
|
||||
file_t(int f, void *c) : f_oflags(f), vdev(c) {}
|
||||
};
|
||||
|
||||
} // namespace cdev
|
||||
|
|
|
@ -33,14 +33,6 @@
|
|||
|
||||
#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 "uORBUtils.hpp"
|
||||
#include "uORBManager.hpp"
|
||||
|
@ -58,7 +50,7 @@ uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(cdev::file_t *fil
|
|||
}
|
||||
|
||||
#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) :
|
||||
|
@ -82,7 +74,7 @@ uORB::DeviceNode::open(cdev::file_t *filp)
|
|||
int ret;
|
||||
|
||||
/* is this a publisher? */
|
||||
if (FILE_FLAGS(filp) == PX4_F_WRONLY) {
|
||||
if (filp->f_oflags == PX4_F_WRONLY) {
|
||||
|
||||
/* become the publisher if we can */
|
||||
lock();
|
||||
|
@ -111,7 +103,7 @@ uORB::DeviceNode::open(cdev::file_t *filp)
|
|||
}
|
||||
|
||||
/* is this a new subscriber? */
|
||||
if (FILE_FLAGS(filp) == PX4_F_RDONLY) {
|
||||
if (filp->f_oflags == PX4_F_RDONLY) {
|
||||
|
||||
/* allocate subscriber data */
|
||||
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 */
|
||||
sd->generation = _generation - (_queue_size < _generation ? _queue_size : _generation);
|
||||
|
||||
FILE_PRIV(filp) = (void *)sd;
|
||||
filp->f_priv = (void *)sd;
|
||||
|
||||
ret = CDev::open(filp);
|
||||
|
||||
|
@ -137,7 +129,7 @@ uORB::DeviceNode::open(cdev::file_t *filp)
|
|||
return ret;
|
||||
}
|
||||
|
||||
if (FILE_FLAGS(filp) == 0) {
|
||||
if (filp->f_oflags == 0) {
|
||||
return CDev::open(filp);
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ private:
|
|||
int VCDevNode::open(cdev::file_t *handlep)
|
||||
{
|
||||
// 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;
|
||||
return -1;
|
||||
}
|
||||
|
@ -131,9 +131,9 @@ int VCDevNode::open(cdev::file_t *handlep)
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -142,12 +142,12 @@ int VCDevNode::open(cdev::file_t *handlep)
|
|||
|
||||
int VCDevNode::close(cdev::file_t *handlep)
|
||||
{
|
||||
delete (PrivData *)handlep->priv;
|
||||
handlep->priv = nullptr;
|
||||
delete (PrivData *)handlep->f_priv;
|
||||
handlep->f_priv = nullptr;
|
||||
CDev::close(handlep);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
PrivData *p = (PrivData *)handlep->priv;
|
||||
PrivData *p = (PrivData *)handlep->f_priv;
|
||||
ssize_t chars_read = 0;
|
||||
PX4_INFO("read %zu write %zu", p->_read_offset, _write_offset);
|
||||
|
||||
|
|
Loading…
Reference in New Issue