SMACC
Loading...
Searching...
No Matches
smacc_publisher_client.h
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
6
7#pragma once
8
10#include <boost/optional/optional_io.hpp>
11
12namespace smacc
13{
14namespace client_bases
15{
17{
18public:
19 boost::optional<std::string> topicName;
20 boost::optional<int> queueSize;
21
23 {
24 initialized_ = false;
25 }
26
28 {
29 pub_.shutdown();
30 }
31
32 template <typename MessageType>
33 void configure(std::string topicName)
34 {
35 this->topicName = topicName;
36 if (!initialized_)
37 {
38 if (!this->topicName)
39 {
40 ROS_ERROR("topic publisher with no topic name set. Skipping advertising.");
41 return;
42 }
43 if (!queueSize)
44 queueSize = 1;
45
46 ROS_INFO_STREAM("[" << this->getName() << "] Client Publisher to topic: " << topicName);
47 pub_ = nh_.advertise<MessageType>(*(this->topicName), *queueSize);
48
49 this->initialized_ = true;
50 }
51 }
52
53 template <typename MessageType>
54 void publish(const MessageType &msg)
55 {
56 pub_.publish(msg);
57 }
58
59protected:
60 ros::NodeHandle nh_;
61 ros::Publisher pub_;
62
63private:
65};
66} // namespace client_bases
67} // namespace smacc
virtual std::string getName() const
Definition: client.cpp:34