diff --git a/platforms/common/uORB/uORBDeviceMaster.cpp b/platforms/common/uORB/uORBDeviceMaster.cpp index caf28111b9..f4e8223e1d 100644 --- a/platforms/common/uORB/uORBDeviceMaster.cpp +++ b/platforms/common/uORB/uORBDeviceMaster.cpp @@ -459,34 +459,6 @@ uORB::DeviceNode *uORB::DeviceMaster::getDeviceNode(const char *nodepath) return nullptr; } -bool uORB::DeviceMaster::deviceNodeExists(ORB_ID id, const uint8_t instance) -{ - if ((id == ORB_ID::INVALID) || (instance > ORB_MULTI_MAX_INSTANCES - 1)) { - return false; - } - - return _node_exists[instance][(uint8_t)id]; -} - -uORB::DeviceNode *uORB::DeviceMaster::getDeviceNode(const struct orb_metadata *meta, const uint8_t instance) -{ - if (meta == nullptr) { - return nullptr; - } - - if (!deviceNodeExists(static_cast(meta->o_id), instance)) { - return nullptr; - } - - lock(); - uORB::DeviceNode *node = getDeviceNodeLocked(meta, instance); - unlock(); - - //We can safely return the node that can be used by any thread, because - //a DeviceNode never gets deleted. - return node; -} - uORB::DeviceNode *uORB::DeviceMaster::getDeviceNodeLocked(const struct orb_metadata *meta, const uint8_t instance) { for (uORB::DeviceNode *node : _node_list) { diff --git a/platforms/common/uORB/uORBDeviceMaster.hpp b/platforms/common/uORB/uORBDeviceMaster.hpp index cf4f8de4cf..94c97e61df 100644 --- a/platforms/common/uORB/uORBDeviceMaster.hpp +++ b/platforms/common/uORB/uORBDeviceMaster.hpp @@ -72,9 +72,34 @@ public: * @return node if exists, nullptr otherwise */ uORB::DeviceNode *getDeviceNode(const char *node_name); - uORB::DeviceNode *getDeviceNode(const struct orb_metadata *meta, const uint8_t instance); - - bool deviceNodeExists(ORB_ID id, const uint8_t instance); + uORB::DeviceNode *getDeviceNode(const struct orb_metadata *meta, const uint8_t instance) + { + if (meta == nullptr) { + return nullptr; + } + + if (!deviceNodeExists(static_cast(meta->o_id), instance)) { + return nullptr; + } + + lock(); + uORB::DeviceNode *node = getDeviceNodeLocked(meta, instance); + unlock(); + + //We can safely return the node that can be used by any thread, because + //a DeviceNode never gets deleted. + return node; + + } + + bool deviceNodeExists(ORB_ID id, const uint8_t instance) + { + if ((id == ORB_ID::INVALID) || (instance > ORB_MULTI_MAX_INSTANCES - 1)) { + return false; + } + + return _node_exists[instance][(uint8_t)id]; + } /** * Print statistics for each existing topic.