aboutsummaryrefslogtreecommitdiff
path: root/src/platforms/px4_publisher.h
diff options
context:
space:
mode:
authorThomas Gubler <thomasgubler@gmail.com>2015-01-22 09:30:43 +0100
committerThomas Gubler <thomasgubler@gmail.com>2015-01-22 09:30:43 +0100
commit8c4fce3654bbf4cb31314f1fb596f4fd17772589 (patch)
treebaf3d096173055675b1fbc7362e0756eec69918c /src/platforms/px4_publisher.h
parent2af44f5995dd121a7ce2aefd3ab1c7d8dcf3fb8d (diff)
downloadpx4-firmware-8c4fce3654bbf4cb31314f1fb596f4fd17772589.tar.gz
px4-firmware-8c4fce3654bbf4cb31314f1fb596f4fd17772589.tar.bz2
px4-firmware-8c4fce3654bbf4cb31314f1fb596f4fd17772589.zip
multiplatform: better publisher base class
Diffstat (limited to 'src/platforms/px4_publisher.h')
-rw-r--r--src/platforms/px4_publisher.h44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/platforms/px4_publisher.h b/src/platforms/px4_publisher.h
index 7195777f5..afedbbee7 100644
--- a/src/platforms/px4_publisher.h
+++ b/src/platforms/px4_publisher.h
@@ -61,29 +61,44 @@ public:
~PublisherBase() {};
};
+/**
+ * Publisher base class, templated with the message type
+ * */
+template <typename T>
+class __EXPORT Publisher
+{
+public:
+ Publisher() {};
+ ~Publisher() {};
+
+ virtual int publish(const T &msg) = 0;
+};
+
#if defined(__PX4_ROS)
-class Publisher :
- public PublisherBase
+template <typename T>
+class PublisherROS :
+ public Publisher<T>
{
public:
/**
* Construct Publisher by providing a ros::Publisher
* @param ros_pub the ros publisher which will be used to perform the publications
*/
- Publisher(ros::Publisher ros_pub) :
- PublisherBase(),
+ PublisherROS(ros::Publisher ros_pub) :
+ Publisher<T>(),
_ros_pub(ros_pub)
{}
- ~Publisher() {};
+ ~PublisherROS() {};
/** Publishes msg
* @param msg the message which is published to the topic
*/
- template <typename T>
- int publish(T &msg) {
+ int publish(const T &msg)
+ {
_ros_pub.publish(msg.data());
- return 0;}
+ return 0;
+ }
private:
ros::Publisher _ros_pub; /**< Handle to the ros publisher */
};
@@ -104,8 +119,9 @@ public:
virtual void update() = 0;
};
-class __EXPORT Publisher :
- public PublisherBase,
+template <typename T>
+class __EXPORT PublisherUORB :
+ public Publisher<T>,
public PublisherNode
{
@@ -113,17 +129,17 @@ public:
/**
* Construct Publisher by providing orb meta data
*/
- Publisher(uORB::PublicationBase * uorb_pub) :
- PublisherBase(),
+ PublisherUORB(uORB::PublicationBase * uorb_pub) :
+ Publisher<T>(),
+ PublisherNode(),
_uorb_pub(uorb_pub)
{}
- ~Publisher() {};
+ ~PublisherUORB() {};
/** Publishes msg
* @param msg the message which is published to the topic
*/
- template<typename T>
int publish(const T &msg)
{
_uorb_pub->update((void *)&(msg.data()));