cdev: posix remove std::map usage

- this is to make things a little easier for platforms like QuRT (voxl snapdragon) where there are libstdc++ complications
This commit is contained in:
Daniel Agar
2020-07-21 10:17:55 -04:00
committed by GitHub
parent 81f57bccb6
commit b8b19f6166
7 changed files with 132 additions and 243 deletions
+20 -35
View File
@@ -42,18 +42,6 @@
#include "uORBCommunicator.hpp"
#endif /* ORB_COMMUNICATOR */
uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(cdev::file_t *filp)
{
#ifndef __PX4_NUTTX
if (!filp) {
return nullptr;
}
#endif
return (SubscriberData *)(filp->f_priv);
}
uORB::DeviceNode::DeviceNode(const struct orb_metadata *meta, const uint8_t instance, const char *path,
ORB_PRIO priority, uint8_t queue_size) :
CDev(path),
@@ -125,7 +113,7 @@ int
uORB::DeviceNode::close(cdev::file_t *filp)
{
if (filp->f_oflags == PX4_F_RDONLY) { /* subscriber */
SubscriberData *sd = filp_to_sd(filp);
SubscriberData *sd = static_cast<SubscriberData *>(filp->f_priv);
if (sd != nullptr) {
remove_internal_subscriber();
@@ -196,7 +184,7 @@ uORB::DeviceNode::read(cdev::file_t *filp, char *buffer, size_t buflen)
return -EIO;
}
SubscriberData *sd = (SubscriberData *)filp_to_sd(filp);
SubscriberData *sd = static_cast<SubscriberData *>(filp->f_priv);
/*
* Perform an atomic copy & state update
@@ -282,12 +270,10 @@ uORB::DeviceNode::write(cdev::file_t *filp, const char *buffer, size_t buflen)
int
uORB::DeviceNode::ioctl(cdev::file_t *filp, int cmd, unsigned long arg)
{
SubscriberData *sd = filp_to_sd(filp);
switch (cmd) {
case ORBIOCUPDATED: {
ATOMIC_ENTER;
*(bool *)arg = appears_updated(sd);
*(bool *)arg = appears_updated(filp);
ATOMIC_LEAVE;
return PX4_OK;
}
@@ -296,6 +282,8 @@ uORB::DeviceNode::ioctl(cdev::file_t *filp, int cmd, unsigned long arg)
int ret = PX4_OK;
lock();
SubscriberData *sd = static_cast<SubscriberData *>(filp->f_priv);
if (arg == 0) {
if (sd->update_interval) {
delete (sd->update_interval);
@@ -337,12 +325,15 @@ uORB::DeviceNode::ioctl(cdev::file_t *filp, int cmd, unsigned long arg)
return ret;
}
case ORBIOCGETINTERVAL:
if (sd->update_interval) {
*(unsigned *)arg = sd->update_interval->interval;
case ORBIOCGETINTERVAL: {
SubscriberData *sd = static_cast<SubscriberData *>(filp->f_priv);
} else {
*(unsigned *)arg = 0;
if (sd->update_interval) {
*(unsigned *)arg = sd->update_interval->interval;
} else {
*(unsigned *)arg = 0;
}
}
return OK;
@@ -459,12 +450,8 @@ int16_t uORB::DeviceNode::topic_unadvertised(const orb_metadata *meta, ORB_PRIO
px4_pollevent_t
uORB::DeviceNode::poll_state(cdev::file_t *filp)
{
SubscriberData *sd = filp_to_sd(filp);
/*
* If the topic appears updated to the subscriber, say so.
*/
if (appears_updated(sd)) {
// If the topic appears updated to the subscriber, say so.
if (appears_updated(filp)) {
return POLLIN;
}
@@ -474,24 +461,22 @@ uORB::DeviceNode::poll_state(cdev::file_t *filp)
void
uORB::DeviceNode::poll_notify_one(px4_pollfd_struct_t *fds, px4_pollevent_t events)
{
SubscriberData *sd = filp_to_sd((cdev::file_t *)fds->priv);
/*
* If the topic looks updated to the subscriber, go ahead and notify them.
*/
if (appears_updated(sd)) {
// If the topic looks updated to the subscriber, go ahead and notify them.
if (appears_updated((cdev::file_t *)fds->priv)) {
CDev::poll_notify_one(fds, events);
}
}
bool
uORB::DeviceNode::appears_updated(SubscriberData *sd)
uORB::DeviceNode::appears_updated(cdev::file_t *filp)
{
// check if this topic has been published yet, if not bail out
if (_data == nullptr) {
return false;
}
SubscriberData *sd = static_cast<SubscriberData *>(filp->f_priv);
// if subscriber has interval check time since last update
if (sd->update_interval != nullptr) {
if (hrt_elapsed_time(&sd->update_interval->last_update) < sd->update_interval->interval) {