aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/px4_subscriber.h
diff options
context:
space:
mode:
authorThomas Gubler <thomasgubler@gmail.com>2014-12-11 15:33:32 +0100
committerThomas Gubler <thomasgubler@gmail.com>2014-12-11 15:33:32 +0100
commit998646f03b229ae86bd6e57ff0bd15dd1763c342 (patch)
tree340fa4c7d15b9a92158bd142a9e53a53d7b178cf /src/platforms/px4_subscriber.h
parentc68c277c94cacd2a64b634dd9c45ace2a04c2911 (diff)
downloadpx4-firmware-998646f03b229ae86bd6e57ff0bd15dd1763c342.tar.gz
px4-firmware-998646f03b229ae86bd6e57ff0bd15dd1763c342.tar.bz2
px4-firmware-998646f03b229ae86bd6e57ff0bd15dd1763c342.zip
add base class and template subscriber class as well to improve interface to get last msg value
Diffstat (limited to 'src/platforms/px4_subscriber.h')
-rw-r--r--src/platforms/px4_subscriber.h38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/platforms/px4_subscriber.h b/src/platforms/px4_subscriber.h
index 234b72f5b..59c0ef70b 100644
--- a/src/platforms/px4_subscriber.h
+++ b/src/platforms/px4_subscriber.h
@@ -50,14 +50,36 @@
namespace px4
{
+
+/**
+ * Untemplated subscriber base class
+ * */
+class SubscriberBase
+{
+public:
+ SubscriberBase() {};
+ ~SubscriberBase() {};
+
+};
+
/**
* Subscriber class which is used by nodehandle
*/
-class Subscriber
+template<typename M>
+class Subscriber :
+ public SubscriberBase
{
public:
- Subscriber() {};
+ Subscriber() :
+ SubscriberBase()
+ {};
~Subscriber() {};
+
+ /* Accessors*/
+ /**
+ * Get the last message value
+ */
+ virtual const M& get_msg() = 0;
};
#if defined(__linux) || (defined(__APPLE__) && defined(__MACH__))
@@ -66,7 +88,7 @@ public:
*/
template<typename M>
class SubscriberROS :
- public Subscriber
+ public Subscriber<M>
{
friend class NodeHandle;
@@ -75,7 +97,7 @@ public:
* Construct Subscriber by providing a callback function
*/
SubscriberROS(std::function<void(const M &)> cbf) :
- Subscriber(),
+ Subscriber<M>(),
_ros_sub(),
_cbf(cbf),
_msg_current()
@@ -85,7 +107,7 @@ public:
* Construct Subscriber without a callback function
*/
SubscriberROS() :
- Subscriber(),
+ Subscriber<M>(),
_ros_sub(),
_cbf(NULL),
_msg_current()
@@ -128,14 +150,14 @@ protected:
};
-#else
+#else // Building for NuttX
/**
* Subscriber class that is templated with the uorb subscription message type
*/
template<typename M>
class SubscriberUORB :
- public Subscriber,
+ public Subscriber<M>,
public uORB::Subscription<M>
{
public:
@@ -150,7 +172,7 @@ public:
unsigned interval,
std::function<void(const M &)> callback,
List<uORB::SubscriptionNode *> *list) :
- Subscriber(),
+ Subscriber<M>(),
uORB::Subscription<M>(meta, interval, list),
_callback(callback)
//XXX store callback