mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-26 13:50:34 +08:00
uORB::Subscription minor API cleanup
* the forceInit() method was combined with the existing subscribe() * delete unused last_update()
This commit is contained in:
@@ -42,36 +42,59 @@
|
||||
namespace uORB
|
||||
{
|
||||
|
||||
bool Subscription::subscribe()
|
||||
bool
|
||||
Subscription::subscribe()
|
||||
{
|
||||
DeviceMaster *device_master = uORB::Manager::get_instance()->get_device_master();
|
||||
_node = device_master->getDeviceNode(_meta, _instance);
|
||||
// valid ORB_ID required
|
||||
if (_meta == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if already subscribed
|
||||
if (_node != nullptr) {
|
||||
_node->add_internal_subscriber();
|
||||
|
||||
// If there were any previous publications, allow the subscriber to read them
|
||||
const unsigned curr_gen = _node->published_message_count();
|
||||
const unsigned q_size = _node->get_queue_size();
|
||||
|
||||
_last_generation = curr_gen - (q_size < curr_gen ? q_size : curr_gen);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DeviceMaster *device_master = uORB::Manager::get_instance()->get_device_master();
|
||||
|
||||
if (device_master != nullptr) {
|
||||
uORB::DeviceNode *node = device_master->getDeviceNode(_meta, _instance);
|
||||
|
||||
if (node != nullptr) {
|
||||
_node = node;
|
||||
_node->add_internal_subscriber();
|
||||
|
||||
// If there were any previous publications, allow the subscriber to read them
|
||||
const unsigned curr_gen = _node->published_message_count();
|
||||
const uint8_t q_size = _node->get_queue_size();
|
||||
|
||||
if (q_size < curr_gen) {
|
||||
_last_generation = curr_gen - q_size;
|
||||
|
||||
} else {
|
||||
_last_generation = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Subscription::unsubscribe()
|
||||
void
|
||||
Subscription::unsubscribe()
|
||||
{
|
||||
if (_node != nullptr) {
|
||||
_node->remove_internal_subscriber();
|
||||
}
|
||||
|
||||
_node = nullptr;
|
||||
_last_generation = 0;
|
||||
}
|
||||
|
||||
bool Subscription::init()
|
||||
bool
|
||||
Subscription::init()
|
||||
{
|
||||
if (_meta != nullptr) {
|
||||
// this throttles the relatively expensive calls to getDeviceNode()
|
||||
@@ -90,18 +113,8 @@ bool Subscription::init()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Subscription::forceInit()
|
||||
{
|
||||
if (_node == nullptr) {
|
||||
// reset generation to force subscription attempt
|
||||
_last_generation = 0;
|
||||
return subscribe();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Subscription::update(uint64_t *time, void *dst)
|
||||
bool
|
||||
Subscription::update(uint64_t *time, void *dst)
|
||||
{
|
||||
if ((time != nullptr) && (dst != nullptr) && published()) {
|
||||
// always copy data to dst regardless of update
|
||||
|
||||
Reference in New Issue
Block a user