mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 18:47:21 +08:00
uORB orb_exists use internal linked list instead of file path
This commit is contained in:
@@ -94,34 +94,44 @@ uORB::DeviceMaster *uORB::Manager::get_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)
|
||||||
{
|
{
|
||||||
|
int ret = PX4_ERROR;
|
||||||
|
|
||||||
|
// instance valid range: [0, ORB_MULTI_MAX_INSTANCES)
|
||||||
|
if ((instance < 0) || (instance > (ORB_MULTI_MAX_INSTANCES - 1))) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_device_master()) {
|
||||||
|
uORB::DeviceNode *node = _device_master->getDeviceNode(meta, instance);
|
||||||
|
|
||||||
|
if (node != nullptr) {
|
||||||
|
if (node->is_published()) {
|
||||||
|
return PX4_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ORB_COMMUNICATOR
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generate the path to the node and try to open it.
|
* Generate the path to the node and try to open it.
|
||||||
*/
|
*/
|
||||||
char path[orb_maxpath];
|
char path[orb_maxpath];
|
||||||
int inst = instance;
|
int inst = instance;
|
||||||
int ret = uORB::Utils::node_mkpath(path, meta, &inst);
|
|
||||||
|
ret = uORB::Utils::node_mkpath(path, meta, &inst);
|
||||||
|
|
||||||
if (ret != OK) {
|
if (ret != OK) {
|
||||||
errno = -ret;
|
errno = -ret;
|
||||||
return PX4_ERROR;
|
return PX4_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__PX4_NUTTX)
|
|
||||||
struct stat buffer;
|
|
||||||
ret = stat(path, &buffer);
|
|
||||||
#else
|
|
||||||
ret = px4_access(path, F_OK);
|
ret = px4_access(path, F_OK);
|
||||||
|
|
||||||
#ifdef ORB_COMMUNICATOR
|
|
||||||
|
|
||||||
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 : PX4_ERROR;
|
ret = (_remote_topics.find(meta->o_name) != _remote_topics.end()) ? OK : PX4_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* ORB_COMMUNICATOR */
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
// we know the topic exists, but it's not necessarily advertised/published yet (for example
|
// we know the topic exists, but it's not necessarily advertised/published yet (for example
|
||||||
// if there is only a subscriber)
|
// if there is only a subscriber)
|
||||||
@@ -141,6 +151,8 @@ int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* ORB_COMMUNICATOR */
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user