Skip to content
Snippets Groups Projects
Commit edea1b65 authored by Daniel Agar's avatar Daniel Agar
Browse files

uORB delete unused Flavor

parent cc061885
No related branches found
No related tags found
No related merge requests found
...@@ -45,23 +45,11 @@ namespace uORB ...@@ -45,23 +45,11 @@ namespace uORB
{ {
static const unsigned orb_maxpath = 64; static const unsigned orb_maxpath = 64;
#ifdef ERROR
# undef ERROR
#endif
/* ERROR is not defined for c++ */
const int ERROR = -1;
enum Flavor {
PUBSUB = 0,
PARAM,
Flavor_count
};
struct orb_advertdata { struct orb_advertdata {
const struct orb_metadata *meta; const struct orb_metadata *meta;
int *instance; int *instance;
int priority; int priority;
}; };
} }
#endif // _uORBCommon_hpp_ #endif // _uORBCommon_hpp_
...@@ -429,13 +429,13 @@ uORB::DeviceNode::publish(const orb_metadata *meta, orb_advert_t handle, const v ...@@ -429,13 +429,13 @@ uORB::DeviceNode::publish(const orb_metadata *meta, orb_advert_t handle, const v
/* check if the device handle is initialized */ /* check if the device handle is initialized */
if ((devnode == nullptr) || (meta == nullptr)) { if ((devnode == nullptr) || (meta == nullptr)) {
errno = EFAULT; errno = EFAULT;
return ERROR; return PX4_ERROR;
} }
/* check if the orb meta data matches the publication */ /* check if the orb meta data matches the publication */
if (devnode->_meta != meta) { if (devnode->_meta != meta) {
errno = EINVAL; errno = EINVAL;
return ERROR; return PX4_ERROR;
} }
/* call the devnode write method with no file pointer */ /* call the devnode write method with no file pointer */
...@@ -443,12 +443,12 @@ uORB::DeviceNode::publish(const orb_metadata *meta, orb_advert_t handle, const v ...@@ -443,12 +443,12 @@ uORB::DeviceNode::publish(const orb_metadata *meta, orb_advert_t handle, const v
if (ret < 0) { if (ret < 0) {
errno = -ret; errno = -ret;
return ERROR; return PX4_ERROR;
} }
if (ret != (int)meta->o_size) { if (ret != (int)meta->o_size) {
errno = EIO; errno = EIO;
return ERROR; return PX4_ERROR;
} }
/* /*
...@@ -458,9 +458,8 @@ uORB::DeviceNode::publish(const orb_metadata *meta, orb_advert_t handle, const v ...@@ -458,9 +458,8 @@ uORB::DeviceNode::publish(const orb_metadata *meta, orb_advert_t handle, const v
if (ch != nullptr) { if (ch != nullptr) {
if (ch->send_message(meta->o_name, meta->o_size, (uint8_t *)data) != 0) { if (ch->send_message(meta->o_name, meta->o_size, (uint8_t *)data) != 0) {
warnx("[uORB::DeviceNode::publish(%d)]: Error Sending [%s] topic data over comm_channel", PX4_ERR("Error Sending [%s] topic data over comm_channel", meta->o_name);
__LINE__, meta->o_name); return PX4_ERROR;
return ERROR;
} }
} }
...@@ -778,7 +777,7 @@ int uORB::DeviceNode::update_queue_size(unsigned int queue_size) ...@@ -778,7 +777,7 @@ int uORB::DeviceNode::update_queue_size(unsigned int queue_size)
//queue size is limited to 255 for the single reason that we use uint8 to store it //queue size is limited to 255 for the single reason that we use uint8 to store it
if (_data || _queue_size > queue_size || queue_size > 255) { if (_data || _queue_size > queue_size || queue_size > 255) {
return ERROR; return PX4_ERROR;
} }
_queue_size = queue_size; _queue_size = queue_size;
...@@ -815,38 +814,31 @@ int16_t uORB::DeviceNode::process_received_message(int32_t length, uint8_t *data ...@@ -815,38 +814,31 @@ int16_t uORB::DeviceNode::process_received_message(int32_t length, uint8_t *data
int16_t ret = -1; int16_t ret = -1;
if (length != (int32_t)(_meta->o_size)) { if (length != (int32_t)(_meta->o_size)) {
warnx("[uORB::DeviceNode::process_received_message(%d)]Error:[%s] Received DataLength[%d] != ExpectedLen[%d]", PX4_ERR("Received DataLength[%d] != ExpectedLen[%d]", _meta->o_name, (int)length, (int)_meta->o_size);
__LINE__, _meta->o_name, (int)length, (int)_meta->o_size); return PX4_ERROR;
return ERROR;
} }
/* call the devnode write method with no file pointer */ /* call the devnode write method with no file pointer */
ret = write(nullptr, (const char *)data, _meta->o_size); ret = write(nullptr, (const char *)data, _meta->o_size);
if (ret < 0) { if (ret < 0) {
return ERROR; return PX4_ERROR;
} }
if (ret != (int)_meta->o_size) { if (ret != (int)_meta->o_size) {
errno = EIO; errno = EIO;
return ERROR; return PX4_ERROR;
} }
return PX4_OK; return PX4_OK;
} }
uORB::DeviceMaster::DeviceMaster(Flavor f) : uORB::DeviceMaster::DeviceMaster() :
CDev((f == PUBSUB) ? "obj_master" : "param_master", CDev("obj_master", TOPIC_MASTER_DEVICE_PATH)
(f == PUBSUB) ? TOPIC_MASTER_DEVICE_PATH : PARAM_MASTER_DEVICE_PATH),
_flavor(f)
{ {
_last_statistics_output = hrt_absolute_time(); _last_statistics_output = hrt_absolute_time();
} }
uORB::DeviceMaster::~DeviceMaster()
{
}
int int
uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
{ {
...@@ -856,19 +848,16 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) ...@@ -856,19 +848,16 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
case ORBIOCADVERTISE: { case ORBIOCADVERTISE: {
const struct orb_advertdata *adv = (const struct orb_advertdata *)arg; const struct orb_advertdata *adv = (const struct orb_advertdata *)arg;
const struct orb_metadata *meta = adv->meta; const struct orb_metadata *meta = adv->meta;
const char *objname;
const char *devpath;
char nodepath[orb_maxpath]; char nodepath[orb_maxpath];
uORB::DeviceNode *node;
/* construct a path to the node - this also checks the node name */ /* construct a path to the node - this also checks the node name */
ret = uORB::Utils::node_mkpath(nodepath, _flavor, meta, adv->instance); ret = uORB::Utils::node_mkpath(nodepath, meta, adv->instance);
if (ret != PX4_OK) { if (ret != PX4_OK) {
return ret; return ret;
} }
ret = ERROR; ret = PX4_ERROR;
/* try for topic groups */ /* try for topic groups */
const unsigned max_group_tries = (adv->instance != nullptr) ? ORB_MULTI_MAX_INSTANCES : 1; const unsigned max_group_tries = (adv->instance != nullptr) ? ORB_MULTI_MAX_INSTANCES : 1;
...@@ -895,17 +884,17 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) ...@@ -895,17 +884,17 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
*(adv->instance) = group_tries; *(adv->instance) = group_tries;
} }
objname = meta->o_name; //no need for a copy, meta->o_name will never be freed or changed const char *objname = meta->o_name; //no need for a copy, meta->o_name will never be freed or changed
/* driver wants a permanent copy of the path, so make one here */ /* driver wants a permanent copy of the path, so make one here */
devpath = strdup(nodepath); const char *devpath = strdup(nodepath);
if (devpath == nullptr) { if (devpath == nullptr) {
return -ENOMEM; return -ENOMEM;
} }
/* construct the new node */ /* construct the new node */
node = new uORB::DeviceNode(meta, objname, devpath, adv->priority); uORB::DeviceNode *node = new uORB::DeviceNode(meta, objname, devpath, adv->priority);
/* if we didn't get a device, that's bad */ /* if we didn't get a device, that's bad */
if (node == nullptr) { if (node == nullptr) {
......
...@@ -298,8 +298,8 @@ public: ...@@ -298,8 +298,8 @@ public:
private: private:
// Private constructor, uORB::Manager takes care of its creation // Private constructor, uORB::Manager takes care of its creation
DeviceMaster(Flavor f); DeviceMaster();
virtual ~DeviceMaster(); virtual ~DeviceMaster() = default;
struct DeviceNodeStatisticsData { struct DeviceNodeStatisticsData {
DeviceNode *node; DeviceNode *node;
...@@ -322,8 +322,6 @@ private: ...@@ -322,8 +322,6 @@ private:
*/ */
uORB::DeviceNode *getDeviceNodeLocked(const char *node_name); uORB::DeviceNode *getDeviceNodeLocked(const char *node_name);
const Flavor _flavor;
#ifdef __PX4_NUTTX #ifdef __PX4_NUTTX
ORBMap _node_map; ORBMap _node_map;
#else #else
......
...@@ -105,7 +105,7 @@ uorb_main(int argc, char *argv[]) ...@@ -105,7 +105,7 @@ uorb_main(int argc, char *argv[])
} }
/* create the driver */ /* create the driver */
g_dev = uORB::Manager::get_instance()->get_device_master(uORB::PUBSUB); g_dev = uORB::Manager::get_instance()->get_device_master();
if (g_dev == nullptr) { if (g_dev == nullptr) {
return -errno; return -errno;
......
...@@ -64,9 +64,7 @@ bool uORB::Manager::initialize() ...@@ -64,9 +64,7 @@ bool uORB::Manager::initialize()
uORB::Manager::Manager() uORB::Manager::Manager()
: _comm_channel(nullptr) : _comm_channel(nullptr)
{ {
for (int i = 0; i < Flavor_count; ++i) { _device_master = nullptr;
_device_masters[i] = nullptr;
}
#ifdef ORB_USE_PUBLISHER_RULES #ifdef ORB_USE_PUBLISHER_RULES
const char *file_name = "./rootfs/orb_publisher.rules"; const char *file_name = "./rootfs/orb_publisher.rules";
...@@ -86,26 +84,22 @@ uORB::Manager::Manager() ...@@ -86,26 +84,22 @@ uORB::Manager::Manager()
uORB::Manager::~Manager() uORB::Manager::~Manager()
{ {
for (int i = 0; i < Flavor_count; ++i) { delete _device_master;
if (_device_masters[i]) {
delete _device_masters[i];
}
}
} }
uORB::DeviceMaster *uORB::Manager::get_device_master(Flavor flavor) uORB::DeviceMaster *uORB::Manager::get_device_master()
{ {
if (!_device_masters[flavor]) { if (!_device_master) {
_device_masters[flavor] = new DeviceMaster(flavor); _device_master = new DeviceMaster();
if (_device_masters[flavor]) { if (_device_master) {
int ret = _device_masters[flavor]->init(); int ret = _device_master->init();
if (ret != PX4_OK) { if (ret != PX4_OK) {
PX4_ERR("Initialization of DeviceMaster failed (%i)", ret); PX4_ERR("Initialization of DeviceMaster failed (%i)", ret);
errno = -ret; errno = -ret;
delete _device_masters[flavor]; delete _device_master;
_device_masters[flavor] = nullptr; _device_master = nullptr;
} }
} else { } else {
...@@ -114,7 +108,7 @@ uORB::DeviceMaster *uORB::Manager::get_device_master(Flavor flavor) ...@@ -114,7 +108,7 @@ uORB::DeviceMaster *uORB::Manager::get_device_master(Flavor flavor)
} }
} }
return _device_masters[flavor]; return _device_master;
} }
int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance) int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance)
...@@ -124,11 +118,11 @@ int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance) ...@@ -124,11 +118,11 @@ int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance)
*/ */
char path[orb_maxpath]; char path[orb_maxpath];
int inst = instance; int inst = instance;
int ret = uORB::Utils::node_mkpath(path, PUBSUB, meta, &inst); int ret = uORB::Utils::node_mkpath(path, meta, &inst);
if (ret != OK) { if (ret != OK) {
errno = -ret; errno = -ret;
return ERROR; return PX4_ERROR;
} }
#if defined(__PX4_NUTTX) #if defined(__PX4_NUTTX)
...@@ -138,7 +132,7 @@ int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance) ...@@ -138,7 +132,7 @@ int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance)
ret = px4_access(path, F_OK); ret = px4_access(path, F_OK);
if (ret == -1 && meta != nullptr && !_remote_topics.empty()) { if (ret == -1 && meta != nullptr && !_remote_topics.empty()) {
ret = (_remote_topics.find(meta->o_name) != _remote_topics.end()) ? OK : ERROR; ret = (_remote_topics.find(meta->o_name) != _remote_topics.end()) ? OK : PX4_ERROR;
} }
#endif #endif
...@@ -154,7 +148,7 @@ int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance) ...@@ -154,7 +148,7 @@ int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance)
if (px4_ioctl(fd, ORBIOCISPUBLISHED, (unsigned long)&is_published) == 0) { if (px4_ioctl(fd, ORBIOCISPUBLISHED, (unsigned long)&is_published) == 0) {
if (!is_published) { if (!is_published) {
ret = ERROR; ret = PX4_ERROR;
} }
} }
...@@ -196,9 +190,9 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta, ...@@ -196,9 +190,9 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
orb_advert_t advertiser; orb_advert_t advertiser;
/* open the node as an advertiser */ /* open the node as an advertiser */
fd = node_open(PUBSUB, meta, data, true, instance, priority); fd = node_open(meta, data, true, instance, priority);
if (fd == ERROR) { if (fd == PX4_ERROR) {
PX4_ERR("%s advertise failed", meta->o_name); PX4_ERR("%s advertise failed", meta->o_name);
return nullptr; return nullptr;
} }
...@@ -216,7 +210,7 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta, ...@@ -216,7 +210,7 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
result = px4_ioctl(fd, ORBIOCGADVERTISER, (unsigned long)&advertiser); result = px4_ioctl(fd, ORBIOCGADVERTISER, (unsigned long)&advertiser);
px4_close(fd); px4_close(fd);
if (result == ERROR) { if (result == PX4_ERROR) {
PX4_WARN("px4_ioctl ORBIOCGADVERTISER failed. fd = %d", fd); PX4_WARN("px4_ioctl ORBIOCGADVERTISER failed. fd = %d", fd);
return nullptr; return nullptr;
} }
...@@ -227,7 +221,7 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta, ...@@ -227,7 +221,7 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
/* the advertiser must perform an initial publish to initialise the object */ /* the advertiser must perform an initial publish to initialise the object */
result = orb_publish(meta, advertiser, data); result = orb_publish(meta, advertiser, data);
if (result == ERROR) { if (result == PX4_ERROR) {
PX4_WARN("orb_publish failed"); PX4_WARN("orb_publish failed");
return nullptr; return nullptr;
} }
...@@ -250,13 +244,13 @@ int uORB::Manager::orb_unadvertise(orb_advert_t handle) ...@@ -250,13 +244,13 @@ int uORB::Manager::orb_unadvertise(orb_advert_t handle)
int uORB::Manager::orb_subscribe(const struct orb_metadata *meta) int uORB::Manager::orb_subscribe(const struct orb_metadata *meta)
{ {
return node_open(PUBSUB, meta, nullptr, false); return node_open(meta, nullptr, false);
} }
int uORB::Manager::orb_subscribe_multi(const struct orb_metadata *meta, unsigned instance) int uORB::Manager::orb_subscribe_multi(const struct orb_metadata *meta, unsigned instance)
{ {
int inst = instance; int inst = instance;
return node_open(PUBSUB, meta, nullptr, false, &inst); return node_open(meta, nullptr, false, &inst);
} }
int uORB::Manager::orb_unsubscribe(int fd) int uORB::Manager::orb_unsubscribe(int fd)
...@@ -284,12 +278,12 @@ int uORB::Manager::orb_copy(const struct orb_metadata *meta, int handle, void *b ...@@ -284,12 +278,12 @@ int uORB::Manager::orb_copy(const struct orb_metadata *meta, int handle, void *b
ret = px4_read(handle, buffer, meta->o_size); ret = px4_read(handle, buffer, meta->o_size);
if (ret < 0) { if (ret < 0) {
return ERROR; return PX4_ERROR;
} }
if (ret != (int)meta->o_size) { if (ret != (int)meta->o_size) {
errno = EIO; errno = EIO;
return ERROR; return PX4_ERROR;
} }
return PX4_OK; return PX4_OK;
...@@ -333,7 +327,7 @@ int uORB::Manager::node_advertise ...@@ -333,7 +327,7 @@ int uORB::Manager::node_advertise
) )
{ {
int fd = -1; int fd = -1;
int ret = ERROR; int ret = PX4_ERROR;
/* fill advertiser data */ /* fill advertiser data */
const struct orb_advertdata adv = { meta, instance, priority }; const struct orb_advertdata adv = { meta, instance, priority };
...@@ -362,15 +356,8 @@ out: ...@@ -362,15 +356,8 @@ out:
return ret; return ret;
} }
int uORB::Manager::node_open int uORB::Manager::node_open(const struct orb_metadata *meta, const void *data, bool advertiser, int *instance,
( int priority)
Flavor f,
const struct orb_metadata *meta,
const void *data,
bool advertiser,
int *instance,
int priority
)
{ {
char path[orb_maxpath]; char path[orb_maxpath];
int fd = -1, ret; int fd = -1, ret;
...@@ -381,7 +368,7 @@ int uORB::Manager::node_open ...@@ -381,7 +368,7 @@ int uORB::Manager::node_open
*/ */
if (nullptr == meta) { if (nullptr == meta) {
errno = ENOENT; errno = ENOENT;
return ERROR; return PX4_ERROR;
} }
/* /*
...@@ -389,7 +376,7 @@ int uORB::Manager::node_open ...@@ -389,7 +376,7 @@ int uORB::Manager::node_open
*/ */
if (advertiser && (data == nullptr)) { if (advertiser && (data == nullptr)) {
errno = EINVAL; errno = EINVAL;
return ERROR; return PX4_ERROR;
} }
/* if we have an instance and are an advertiser, we will generate a new node and set the instance, /* if we have an instance and are an advertiser, we will generate a new node and set the instance,
...@@ -398,11 +385,11 @@ int uORB::Manager::node_open ...@@ -398,11 +385,11 @@ int uORB::Manager::node_open
/* /*
* Generate the path to the node and try to open it. * Generate the path to the node and try to open it.
*/ */
ret = uORB::Utils::node_mkpath(path, f, meta, instance); ret = uORB::Utils::node_mkpath(path, meta, instance);
if (ret != OK) { if (ret != OK) {
errno = -ret; errno = -ret;
return ERROR; return PX4_ERROR;
} }
/* open the path as either the advertiser or the subscriber */ /* open the path as either the advertiser or the subscriber */
...@@ -420,11 +407,11 @@ int uORB::Manager::node_open ...@@ -420,11 +407,11 @@ int uORB::Manager::node_open
if (ret == PX4_OK) { if (ret == PX4_OK) {
/* update the path, as it might have been updated during the node_advertise call */ /* update the path, as it might have been updated during the node_advertise call */
ret = uORB::Utils::node_mkpath(path, f, meta, instance); ret = uORB::Utils::node_mkpath(path, meta, instance);
if (ret != PX4_OK) { if (ret != PX4_OK) {
errno = -ret; errno = -ret;
return ERROR; return PX4_ERROR;
} }
} }
...@@ -447,7 +434,7 @@ int uORB::Manager::node_open ...@@ -447,7 +434,7 @@ int uORB::Manager::node_open
if (fd < 0) { if (fd < 0) {
errno = EIO; errno = EIO;
return ERROR; return PX4_ERROR;
} }
/* everything has been OK, we can return the handle now */ /* everything has been OK, we can return the handle now */
...@@ -488,23 +475,21 @@ int16_t uORB::Manager::process_remote_topic(const char *topic_name, bool isAdver ...@@ -488,23 +475,21 @@ int16_t uORB::Manager::process_remote_topic(const char *topic_name, bool isAdver
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int16_t uORB::Manager::process_add_subscription(const char *messageName, int16_t uORB::Manager::process_add_subscription(const char *messageName, int32_t msgRateInHz)
int32_t msgRateInHz)
{ {
PX4_DEBUG("[posix-uORB::Manager::process_add_subscription(%d)] entering Manager_process_add_subscription: name: %s", PX4_DEBUG("entering Manager_process_add_subscription: name: %s", messageName);
__LINE__, messageName);
int16_t rc = 0; int16_t rc = 0;
_remote_subscriber_topics.insert(messageName); _remote_subscriber_topics.insert(messageName);
char nodepath[orb_maxpath]; char nodepath[orb_maxpath];
int ret = uORB::Utils::node_mkpath(nodepath, PUBSUB, messageName); int ret = uORB::Utils::node_mkpath(nodepath, messageName);
DeviceMaster *device_master = get_device_master(PUBSUB); DeviceMaster *device_master = get_device_master();
if (ret == OK && device_master) { if (ret == OK && device_master) {
uORB::DeviceNode *node = device_master->getDeviceNode(nodepath); uORB::DeviceNode *node = device_master->getDeviceNode(nodepath);
if (node == nullptr) { if (node == nullptr) {
PX4_DEBUG("[posix-uORB::Manager::process_add_subscription(%d)]DeviceNode(%s) not created yet", PX4_DEBUG("DeviceNode(%s) not created yet", messageName);
__LINE__, messageName);
} else { } else {
// node is present. // node is present.
...@@ -520,14 +505,13 @@ int16_t uORB::Manager::process_add_subscription(const char *messageName, ...@@ -520,14 +505,13 @@ int16_t uORB::Manager::process_add_subscription(const char *messageName,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int16_t uORB::Manager::process_remove_subscription( int16_t uORB::Manager::process_remove_subscription(const char *messageName)
const char *messageName)
{ {
int16_t rc = -1; int16_t rc = -1;
_remote_subscriber_topics.erase(messageName); _remote_subscriber_topics.erase(messageName);
char nodepath[orb_maxpath]; char nodepath[orb_maxpath];
int ret = uORB::Utils::node_mkpath(nodepath, PUBSUB, messageName); int ret = uORB::Utils::node_mkpath(nodepath, messageName);
DeviceMaster *device_master = get_device_master(PUBSUB); DeviceMaster *device_master = get_device_master();
if (ret == OK && device_master) { if (ret == OK && device_master) {
uORB::DeviceNode *node = device_master->getDeviceNode(nodepath); uORB::DeviceNode *node = device_master->getDeviceNode(nodepath);
...@@ -549,21 +533,19 @@ int16_t uORB::Manager::process_remove_subscription( ...@@ -549,21 +533,19 @@ int16_t uORB::Manager::process_remove_subscription(
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int16_t uORB::Manager::process_received_message(const char *messageName, int16_t uORB::Manager::process_received_message(const char *messageName, int32_t length, uint8_t *data)
int32_t length, uint8_t *data)
{ {
int16_t rc = -1; int16_t rc = -1;
char nodepath[orb_maxpath]; char nodepath[orb_maxpath];
int ret = uORB::Utils::node_mkpath(nodepath, PUBSUB, messageName); int ret = uORB::Utils::node_mkpath(nodepath, messageName);
DeviceMaster *device_master = get_device_master(PUBSUB); DeviceMaster *device_master = get_device_master();
if (ret == OK && device_master) { if (ret == OK && device_master) {
uORB::DeviceNode *node = device_master->getDeviceNode(nodepath); uORB::DeviceNode *node = device_master->getDeviceNode(nodepath);
// get the node name. // get the node name.
if (node == nullptr) { if (node == nullptr) {
PX4_DEBUG("[uORB::Manager::process_received_message(%d)]Error No existing subscriber found for message: [%s] nodepath:[%s]", PX4_DEBUG("No existing subscriber found for message: [%s] nodepath:[%s]", messageName, nodepath);
__LINE__, messageName, nodepath);
} else { } else {
// node is present. // node is present.
......
...@@ -79,12 +79,12 @@ public: ...@@ -79,12 +79,12 @@ public:
} }
/** /**
* Get the DeviceMaster for a given Flavor. If it does not exist, * Get the DeviceMaster. If it does not exist,
* it will be created and initialized. * it will be created and initialized.
* Note: the first call to this is not thread-safe. * Note: the first call to this is not thread-safe.
* @return nullptr if initialization failed (and errno will be set) * @return nullptr if initialization failed (and errno will be set)
*/ */
uORB::DeviceMaster *get_device_master(Flavor flavor); uORB::DeviceMaster *get_device_master();
// ==== uORB interface methods ==== // ==== uORB interface methods ====
/** /**
...@@ -145,7 +145,7 @@ public: ...@@ -145,7 +145,7 @@ public:
* and handle different priorities (@see orb_priority()). * and handle different priorities (@see orb_priority()).
* @param queue_size Maximum number of buffered elements. If this is 1, no queuing is * @param queue_size Maximum number of buffered elements. If this is 1, no queuing is
* used. * used.
* @return ERROR on error, otherwise returns a handle * @return PX4_ERROR on error, otherwise returns a handle
* that can be used to publish to the topic. * that can be used to publish to the topic.
* If the topic in question is not known (due to an * If the topic in question is not known (due to an
* ORB_DEFINE with no corresponding ORB_DECLARE) * ORB_DEFINE with no corresponding ORB_DECLARE)
...@@ -174,7 +174,7 @@ public: ...@@ -174,7 +174,7 @@ public:
* for the topic. * for the topic.
* @handle The handle returned from orb_advertise. * @handle The handle returned from orb_advertise.
* @param data A pointer to the data to be published. * @param data A pointer to the data to be published.
* @return OK on success, ERROR otherwise with errno set accordingly. * @return OK on success, PX4_ERROR otherwise with errno set accordingly.
*/ */
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data); int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data);
...@@ -200,7 +200,7 @@ public: ...@@ -200,7 +200,7 @@ public:
* *
* @param meta The uORB metadata (usually from the ORB_ID() macro) * @param meta The uORB metadata (usually from the ORB_ID() macro)
* for the topic. * for the topic.
* @return ERROR on error, otherwise returns a handle * @return PX4_ERROR on error, otherwise returns a handle
* that can be used to read and update the topic. * that can be used to read and update the topic.
*/ */
int orb_subscribe(const struct orb_metadata *meta); int orb_subscribe(const struct orb_metadata *meta);
...@@ -232,7 +232,7 @@ public: ...@@ -232,7 +232,7 @@ public:
* @param instance The instance of the topic. Instance 0 matches the * @param instance The instance of the topic. Instance 0 matches the
* topic of the orb_subscribe() call, higher indices * topic of the orb_subscribe() call, higher indices
* are for topics created with orb_advertise_multi(). * are for topics created with orb_advertise_multi().
* @return ERROR on error, otherwise returns a handle * @return PX4_ERROR on error, otherwise returns a handle
* that can be used to read and update the topic. * that can be used to read and update the topic.
* If the topic in question is not known (due to an * If the topic in question is not known (due to an
* ORB_DEFINE_OPTIONAL with no corresponding ORB_DECLARE) * ORB_DEFINE_OPTIONAL with no corresponding ORB_DECLARE)
...@@ -244,7 +244,7 @@ public: ...@@ -244,7 +244,7 @@ public:
* Unsubscribe from a topic. * Unsubscribe from a topic.
* *
* @param handle A handle returned from orb_subscribe. * @param handle A handle returned from orb_subscribe.
* @return OK on success, ERROR otherwise with errno set accordingly. * @return OK on success, PX4_ERROR otherwise with errno set accordingly.
*/ */
int orb_unsubscribe(int handle); int orb_unsubscribe(int handle);
...@@ -262,7 +262,7 @@ public: ...@@ -262,7 +262,7 @@ public:
* @param buffer Pointer to the buffer receiving the data, or NULL * @param buffer Pointer to the buffer receiving the data, or NULL
* if the caller wants to clear the updated flag without * if the caller wants to clear the updated flag without
* using the data. * using the data.
* @return OK on success, ERROR otherwise with errno set accordingly. * @return OK on success, PX4_ERROR otherwise with errno set accordingly.
*/ */
int orb_copy(const struct orb_metadata *meta, int handle, void *buffer); int orb_copy(const struct orb_metadata *meta, int handle, void *buffer);
...@@ -281,7 +281,7 @@ public: ...@@ -281,7 +281,7 @@ public:
* @param handle A handle returned from orb_subscribe. * @param handle A handle returned from orb_subscribe.
* @param updated Set to true if the topic has been updated since the * @param updated Set to true if the topic has been updated since the
* last time it was copied using this handle. * last time it was copied using this handle.
* @return OK if the check was successful, ERROR otherwise with * @return OK if the check was successful, PX4_ERROR otherwise with
* errno set accordingly. * errno set accordingly.
*/ */
int orb_check(int handle, bool *updated); int orb_check(int handle, bool *updated);
...@@ -293,7 +293,7 @@ public: ...@@ -293,7 +293,7 @@ public:
* @param handle A handle returned from orb_subscribe. * @param handle A handle returned from orb_subscribe.
* @param time Returns the absolute time that the topic was updated, or zero if it has * @param time Returns the absolute time that the topic was updated, or zero if it has
* never been updated. Time is measured in microseconds. * never been updated. Time is measured in microseconds.
* @return OK on success, ERROR otherwise with errno set accordingly. * @return OK on success, PX4_ERROR otherwise with errno set accordingly.
*/ */
int orb_stat(int handle, uint64_t *time); int orb_stat(int handle, uint64_t *time);
...@@ -302,7 +302,7 @@ public: ...@@ -302,7 +302,7 @@ public:
* *
* @param meta ORB topic metadata. * @param meta ORB topic metadata.
* @param instance ORB instance * @param instance ORB instance
* @return OK if the topic exists, ERROR otherwise. * @return OK if the topic exists, PX4_ERROR otherwise.
*/ */
int orb_exists(const struct orb_metadata *meta, int instance); int orb_exists(const struct orb_metadata *meta, int instance);
...@@ -314,7 +314,7 @@ public: ...@@ -314,7 +314,7 @@ public:
* topics which are published by multiple publishers (e.g. mag0, mag1, etc.) * topics which are published by multiple publishers (e.g. mag0, mag1, etc.)
* and allows a subscriber to pick the topic with the highest priority, * and allows a subscriber to pick the topic with the highest priority,
* independent of the startup order of the associated publishers. * independent of the startup order of the associated publishers.
* @return OK on success, ERROR otherwise with errno set accordingly. * @return OK on success, PX4_ERROR otherwise with errno set accordingly.
*/ */
int orb_priority(int handle, int32_t *priority); int orb_priority(int handle, int32_t *priority);
...@@ -334,7 +334,7 @@ public: ...@@ -334,7 +334,7 @@ public:
* *
* @param handle A handle returned from orb_subscribe. * @param handle A handle returned from orb_subscribe.
* @param interval An interval period in milliseconds. * @param interval An interval period in milliseconds.
* @return OK on success, ERROR otherwise with ERRNO set accordingly. * @return OK on success, PX4_ERROR otherwise with ERRNO set accordingly.
*/ */
int orb_set_interval(int handle, unsigned interval); int orb_set_interval(int handle, unsigned interval);
...@@ -346,7 +346,7 @@ public: ...@@ -346,7 +346,7 @@ public:
* *
* @param handle A handle returned from orb_subscribe. * @param handle A handle returned from orb_subscribe.
* @param interval The returned interval period in milliseconds. * @param interval The returned interval period in milliseconds.
* @return OK on success, ERROR otherwise with ERRNO set accordingly. * @return OK on success, PX4_ERROR otherwise with ERRNO set accordingly.
*/ */
int orb_get_interval(int handle, unsigned *interval); int orb_get_interval(int handle, unsigned *interval);
...@@ -393,25 +393,18 @@ private: // class methods ...@@ -393,25 +393,18 @@ private: // class methods
* Handles creation of the object and the initial publication for * Handles creation of the object and the initial publication for
* advertisers. * advertisers.
*/ */
int int node_open(const struct orb_metadata *meta, const void *data, bool advertiser, int *instance = nullptr,
node_open int priority = ORB_PRIO_DEFAULT);
(
Flavor f,
const struct orb_metadata *meta,
const void *data,
bool advertiser,
int *instance = nullptr,
int priority = ORB_PRIO_DEFAULT
);
private: // data members private: // data members
static Manager *_Instance; static Manager *_Instance;
// the communicator channel instance. // the communicator channel instance.
uORBCommunicator::IChannel *_comm_channel; uORBCommunicator::IChannel *_comm_channel;
ORBSet _remote_subscriber_topics; ORBSet _remote_subscriber_topics;
ORBSet _remote_topics; ORBSet _remote_topics;
DeviceMaster *_device_masters[Flavor_count]; ///< Allow at most one DeviceMaster per Flavor DeviceMaster *_device_master{nullptr};
private: //class methods private: //class methods
Manager(); Manager();
......
...@@ -35,13 +35,7 @@ ...@@ -35,13 +35,7 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
int uORB::Utils::node_mkpath int uORB::Utils::node_mkpath(char *buf, const struct orb_metadata *meta, int *instance)
(
char *buf,
Flavor f,
const struct orb_metadata *meta,
int *instance
)
{ {
unsigned len; unsigned len;
...@@ -51,9 +45,7 @@ int uORB::Utils::node_mkpath ...@@ -51,9 +45,7 @@ int uORB::Utils::node_mkpath
index = *instance; index = *instance;
} }
len = snprintf(buf, orb_maxpath, "/%s/%s%d", len = snprintf(buf, orb_maxpath, "/%s/%s%d", "obj", meta->o_name, index);
(f == PUBSUB) ? "obj" : "param",
meta->o_name, index);
if (len >= orb_maxpath) { if (len >= orb_maxpath) {
return -ENAMETOOLONG; return -ENAMETOOLONG;
...@@ -64,15 +56,13 @@ int uORB::Utils::node_mkpath ...@@ -64,15 +56,13 @@ int uORB::Utils::node_mkpath
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int uORB::Utils::node_mkpath(char *buf, Flavor f, int uORB::Utils::node_mkpath(char *buf, const char *orbMsgName)
const char *orbMsgName)
{ {
unsigned len; unsigned len;
unsigned index = 0; unsigned index = 0;
len = snprintf(buf, orb_maxpath, "/%s/%s%d", (f == PUBSUB) ? "obj" : "param", len = snprintf(buf, orb_maxpath, "/%s/%s%d", "obj", orbMsgName, index);
orbMsgName, index);
if (len >= orb_maxpath) { if (len >= orb_maxpath) {
return -ENAMETOOLONG; return -ENAMETOOLONG;
......
...@@ -43,18 +43,12 @@ class Utils; ...@@ -43,18 +43,12 @@ class Utils;
class uORB::Utils class uORB::Utils
{ {
public: public:
static int node_mkpath static int node_mkpath(char *buf, const struct orb_metadata *meta, int *instance = nullptr);
(
char *buf,
Flavor f,
const struct orb_metadata *meta,
int *instance = nullptr
);
/** /**
* same as above except this generators the path based on the string. * same as above except this generators the path based on the string.
*/ */
static int node_mkpath(char *buf, Flavor f, const char *orbMsgName); static int node_mkpath(char *buf, const char *orbMsgName);
}; };
......
...@@ -131,7 +131,7 @@ int uORBTest::UnitTest::pubsublatency_main() ...@@ -131,7 +131,7 @@ int uORBTest::UnitTest::pubsublatency_main()
if (f == nullptr) { if (f == nullptr) {
warnx("Error opening file!\n"); warnx("Error opening file!\n");
delete[] timings; delete[] timings;
return uORB::ERROR; return PX4_ERROR;
} }
for (unsigned i = 0; i < maxruns; i++) { for (unsigned i = 0; i < maxruns; i++) {
...@@ -148,7 +148,7 @@ int uORBTest::UnitTest::pubsublatency_main() ...@@ -148,7 +148,7 @@ int uORBTest::UnitTest::pubsublatency_main()
pubsubtest_passed = true; pubsubtest_passed = true;
if (static_cast<float>(latency_integral / maxruns) > 100.0f) { if (static_cast<float>(latency_integral / maxruns) > 100.0f) {
pubsubtest_res = uORB::ERROR; pubsubtest_res = PX4_ERROR;
} else { } else {
pubsubtest_res = PX4_OK; pubsubtest_res = PX4_OK;
...@@ -825,7 +825,8 @@ int uORBTest::UnitTest::test_fail(const char *fmt, ...) ...@@ -825,7 +825,8 @@ int uORBTest::UnitTest::test_fail(const char *fmt, ...)
va_end(ap); va_end(ap);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
fflush(stderr); fflush(stderr);
return uORB::ERROR;
return PX4_ERROR;
} }
int uORBTest::UnitTest::test_note(const char *fmt, ...) int uORBTest::UnitTest::test_note(const char *fmt, ...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment