mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-03 04:00:36 +08:00
uorb: add uorb_unadvertise method
This is necessary when using multiple instances of a topic. However it does not free the underlying resources, as it is assumed they will be used again at a later point.
This commit is contained in:
@@ -352,6 +352,30 @@ uORB::DeviceNode::publish(const orb_metadata *meta, orb_advert_t handle, const v
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
int uORB::DeviceNode::unadvertise(orb_advert_t handle)
|
||||
{
|
||||
if (handle == nullptr) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
uORB::DeviceNode *devnode = (uORB::DeviceNode *)handle;
|
||||
|
||||
/*
|
||||
* We are cheating a bit here. First, with the current implementation, we can only
|
||||
* have multiple publishers for instance 0. In this case the caller will have
|
||||
* instance=nullptr and _published has no effect at all. Thus no unadvertise is
|
||||
* necessary.
|
||||
* In case of multiple instances, we have at most 1 publisher per instance and
|
||||
* we can signal an instance as 'free' by setting _published to false.
|
||||
* We never really free the DeviceNode, for this we would need reference counting
|
||||
* of subscribers and publishers. But we also do not have a leak since future
|
||||
* publishers reuse the same DeviceNode object.
|
||||
*/
|
||||
devnode->_published = false;
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
pollevent_t
|
||||
uORB::DeviceNode::poll_state(device::file_t *filp)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user