The MAUVE Toolchain
Publisher.hpp
1 /*
2  * Copyright 2017 ONERA
3  *
4  * This file is part of the MAUVE ROS project.
5  *
6  * MAUVE ROS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License version 3 as
8  * published by the Free Software Foundation.
9  *
10  * MAUVE ROS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with MAUVE. If not, see <https://www.gnu.org/licenses/lgpl-3.0>.
17  */
18 #ifndef MAUVE_ROS_PUBLISHER_HPP
19 #define MAUVE_ROS_PUBLISHER_HPP
20 
21 #include <string>
22 #include <functional>
23 
24 #include <ros/ros.h>
25 
26 #include <mauve/runtime.hpp>
27 #include <mauve/base/PeriodicStateMachine.hpp>
28 
29 #include "Connector.hpp"
30 #include "Shell.hpp"
31 
32 namespace mauve
33 {
34  namespace ros
35  {
36 
42  template <typename T, typename ROS_T>
43  struct Publisher
44  : public Connector
45  , virtual public runtime::WithLogger
46  {
47  protected:
51  virtual void shutdown() final;
56  virtual bool open(const std::string& topic) final;
60  ROS_T msg;
63  };
64 
70  template <typename T, typename ROS_T>
72  : public runtime::Core< RosShell<T, ROS_T> >
73  , public Publisher<T, ROS_T>
74  {
75  virtual bool configure_hook() override {
76  return this->open(this->shell().topic);
77  }
78  virtual void cleanup_hook() override {
79  return this->shutdown();
80  }
84  void publish(T value);
86  void update();
87 
88  };
89 
95  template <typename T, typename ROS_T>
97  : public runtime::Interface< RosShell<T, ROS_T>,
98  PublisherCore<T, ROS_T> >
99  {
101  runtime::WriteService<T> & write = this->template mk_write_service<T>("write", &PublisherCore<T, ROS_T>::publish);
102  };
103 
104  template <typename T, typename ROS_T>
109 
110  template <typename T, typename ROS_T>
112  RosShell<T, ROS_T>,
113  PublisherCore<T, ROS_T>,
114  base::PeriodicStateMachine<RosShell<T, ROS_T>, PublisherCore<T, ROS_T>>>;
115 
116 }} // namespaces
117 
118 #include "ipp/Publisher.ipp"
119 
120 #endif
Definition: Interface.hpp:34
Core of the ROS Publisher Resource.
Definition: Publisher.hpp:71
Interface of the ROS Publisher Resource.
Definition: Publisher.hpp:96
::ros::Publisher publisher
The ROS publisher.
Definition: Publisher.hpp:58
virtual void cleanup_hook() override
Hook function called when cleaning the shell.
Definition: Publisher.hpp:78
virtual bool open(const std::string &topic) final
Open publisher on topic topic.
Definition: Publisher.ipp:30
ROS Connector interface.
Definition: Connector.hpp:31
Definition: RtMutex.hpp:26
runtime::RtMutex mutex
A mutex to protect the msg.
Definition: Publisher.hpp:62
Object with a Logger.
Definition: WithLogger.hpp:27
virtual void shutdown() final
Shutdown the publisher.
Definition: Publisher.ipp:40
Component class.
Definition: Architecture.hpp:34
ROS Shell for conversion.
Definition: Shell.hpp:47
virtual bool configure_hook() override
Hook function called when configuring the shell.
Definition: Publisher.hpp:75
The MAUVE namespace.
Definition: tracing.hpp:24
Definition: Architecture.hpp:38
ROS_T msg
The ROS message owned by the resource.
Definition: Publisher.hpp:60
Defines a Periodic State Machine.
Definition: PeriodicStateMachine.hpp:32
The Core defines the methods of the component.
Definition: Core.hpp:38
Definition: WritePort.hpp:27
Adapter of the ROS Publisher.
Definition: Publisher.hpp:43