mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-01 13:20:35 +08:00
sensors/vehicle_gps_position: only register callbacks once topic published
- this avoids creating unnecessary uORB device nodes for GPS instances that might never exist
This commit is contained in:
@@ -68,22 +68,24 @@ public:
|
||||
|
||||
bool registerCallback()
|
||||
{
|
||||
if (_subscription.get_node() && _subscription.get_node()->register_callback(this)) {
|
||||
// registered
|
||||
_registered = true;
|
||||
if (!_registered) {
|
||||
if (_subscription.get_node() && _subscription.get_node()->register_callback(this)) {
|
||||
// registered
|
||||
_registered = true;
|
||||
|
||||
} else {
|
||||
// force topic creation by subscribing with old API
|
||||
int fd = orb_subscribe_multi(_subscription.get_topic(), _subscription.get_instance());
|
||||
} else {
|
||||
// force topic creation by subscribing with old API
|
||||
int fd = orb_subscribe_multi(_subscription.get_topic(), _subscription.get_instance());
|
||||
|
||||
// try to register callback again
|
||||
if (_subscription.subscribe()) {
|
||||
if (_subscription.get_node() && _subscription.get_node()->register_callback(this)) {
|
||||
_registered = true;
|
||||
// try to register callback again
|
||||
if (_subscription.subscribe()) {
|
||||
if (_subscription.get_node() && _subscription.get_node()->register_callback(this)) {
|
||||
_registered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
orb_unsubscribe(fd);
|
||||
orb_unsubscribe(fd);
|
||||
}
|
||||
}
|
||||
|
||||
return _registered;
|
||||
@@ -131,6 +133,8 @@ public:
|
||||
|
||||
virtual void call() = 0;
|
||||
|
||||
bool registered() const { return _registered; }
|
||||
|
||||
protected:
|
||||
|
||||
bool _registered{false};
|
||||
|
||||
Reference in New Issue
Block a user