mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-17 11:43:35 +08:00
multiplatform subscription: uorb: separate class for no callback case
This commit is contained in:
@@ -168,7 +168,7 @@ public:
|
||||
std::function<void(const M &)> callback,
|
||||
unsigned interval)
|
||||
{
|
||||
SubscriberUORB<M> *sub_px4 = new SubscriberUORB<M>(meta, interval, callback, &_subs);
|
||||
SubscriberUORBCallback<M> *sub_px4 = new SubscriberUORBCallback<M>(meta, interval, callback, &_subs);
|
||||
|
||||
/* Check if this is the smallest interval so far and update _sub_min_interval */
|
||||
if (_sub_min_interval == nullptr || _sub_min_interval->getInterval() > sub_px4->getInterval()) {
|
||||
|
||||
@@ -161,22 +161,6 @@ class SubscriberUORB :
|
||||
public uORB::Subscription<M>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct SubscriberUORB by providing orb meta data
|
||||
* @param meta orb metadata for the topic which is used
|
||||
* @param callback Callback, executed on receiving a new message
|
||||
* @param interval Minimal interval between calls to callback
|
||||
* @param list subscriber is added to this list
|
||||
*/
|
||||
SubscriberUORB(const struct orb_metadata *meta,
|
||||
unsigned interval,
|
||||
std::function<void(const M &)> callback,
|
||||
List<uORB::SubscriptionNode *> *list) :
|
||||
Subscriber<M>(),
|
||||
uORB::Subscription<M>(meta, interval, list),
|
||||
_callback(callback)
|
||||
//XXX store callback
|
||||
{}
|
||||
|
||||
/**
|
||||
* Construct SubscriberUORB by providing orb meta data without callback
|
||||
@@ -188,19 +172,61 @@ public:
|
||||
unsigned interval,
|
||||
List<uORB::SubscriptionNode *> *list) :
|
||||
Subscriber<M>(),
|
||||
uORB::Subscription<M>(meta, interval, list),
|
||||
_callback(nullptr)
|
||||
//XXX store callback
|
||||
uORB::Subscription<M>(meta, interval, list)
|
||||
{}
|
||||
|
||||
~SubscriberUORB() {};
|
||||
|
||||
/**
|
||||
* Update Subscription
|
||||
* Invoked by the list traversal in NodeHandle::spinOnce
|
||||
*/
|
||||
virtual void update()
|
||||
{
|
||||
if (!uORB::Subscription<M>::updated()) {
|
||||
/* Topic not updated */
|
||||
return;
|
||||
}
|
||||
|
||||
/* get latest data */
|
||||
uORB::Subscription<M>::update();
|
||||
};
|
||||
|
||||
/* Accessors*/
|
||||
/**
|
||||
* Get the last message value
|
||||
*/
|
||||
const M& get() { return uORB::Subscription<M>::getData(); }
|
||||
};
|
||||
|
||||
template<typename M>
|
||||
class SubscriberUORBCallback :
|
||||
public SubscriberUORB<M>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct SubscriberUORBCallback by providing orb meta data
|
||||
* @param meta orb metadata for the topic which is used
|
||||
* @param callback Callback, executed on receiving a new message
|
||||
* @param interval Minimal interval between calls to callback
|
||||
* @param list subscriber is added to this list
|
||||
*/
|
||||
SubscriberUORBCallback(const struct orb_metadata *meta,
|
||||
unsigned interval,
|
||||
std::function<void(const M &)> callback,
|
||||
List<uORB::SubscriptionNode *> *list) :
|
||||
SubscriberUORB<M>(meta, interval, list),
|
||||
_callback(callback)
|
||||
{}
|
||||
|
||||
~SubscriberUORBCallback() {};
|
||||
|
||||
/**
|
||||
* Update Subscription
|
||||
* Invoked by the list traversal in NodeHandle::spinOnce
|
||||
* If new data is available the callback is called
|
||||
*/
|
||||
void update()
|
||||
virtual void update()
|
||||
{
|
||||
if (!uORB::Subscription<M>::updated()) {
|
||||
/* Topic not updated, do not call callback */
|
||||
@@ -221,16 +247,9 @@ public:
|
||||
|
||||
};
|
||||
|
||||
/* Accessors*/
|
||||
/**
|
||||
* Get the last message value
|
||||
*/
|
||||
const M& get() { return uORB::Subscription<M>::getData(); }
|
||||
|
||||
protected:
|
||||
std::function<void(const M &)> _callback; /**< Callback handle,
|
||||
called when new data is available */
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user