The MAUVE Toolchain
Shell.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_SHELL_HPP
19 #define MAUVE_ROS_SHELL_HPP
20 
21 #include <string>
22 #include <functional>
23 #include <ros/ros.h>
24 #include <mauve/runtime.hpp>
25 #include "Connector.hpp"
26 
27 namespace mauve {
28 
29  namespace ros {
30 
33  : public runtime::Shell
34  , virtual public Connector
35  {
37  runtime::Property<std::string>& topic = mk_property<std::string>("topic", "");
39  virtual bool configure_hook();
40  };
41 
46  template <typename T, typename U>
47  struct RosShell : public RosAbstractShell
48  {
50  using conversion_t = std::function<bool(const T&, U&)>;
52  runtime::Property<conversion_t>& conversion = mk_property<conversion_t>(
53  "conversion", nullptr
54  //[](const T&, U&) { return false; }
55  );
56 
59  this->template mk_read_port<runtime::StatusValue<T>>("read",
60  { runtime::DataStatus::NO_DATA, T() });
62  runtime::WritePort<U> & write_port =
63  this->template mk_write_port<U>("write");
64 
66  virtual bool configure_hook() {
67  if (this->conversion.get_value() == nullptr) {
68  this->logger().error("conversion function not implemented");
69  return false;
70  }
72  };
73 
77  RosShell() {};
82  RosShell(const std::string& topic) { this->topic = topic; };
87  RosShell(const conversion_t& convert) { this->conversion.set_value(convert); };
93  RosShell(const std::string& topic, const conversion_t& convert) {
94  this->topic = topic; this->conversion.set_value(convert); };
95  };
96 
97  }
98 }
99 
100 #endif
runtime::Property< std::string > & topic
Topic property.
Definition: Shell.hpp:37
virtual bool configure_hook()
Configure shell: init ROS node.
Definition: Shell.hpp:66
Definition: HasPort.hpp:33
ROS Connector interface.
Definition: Connector.hpp:31
void error(const char *fmt, const Args &...args)
Log a message at ERROR level.
Definition: logger.ipp:59
RosShell(const std::string &topic, const conversion_t &convert)
Constructor with conversion and topic.
Definition: Shell.hpp:93
ROS Abstract Shell.
Definition: Shell.hpp:32
RosShell(const conversion_t &convert)
Constructor with conversion.
Definition: Shell.hpp:87
AbstractLogger & logger() const override
Get the logger.
Definition: Shell.hpp:77
ROS Shell for conversion.
Definition: Shell.hpp:47
RosShell(const std::string &topic)
Constructor with topic.
Definition: Shell.hpp:82
The MAUVE namespace.
Definition: tracing.hpp:24
A Shell is the interface of a component.
Definition: Shell.hpp:48
std::function< bool(const T &, U &)> conversion_t
Type of the conversion functions.
Definition: Shell.hpp:50
RosShell()
Default constructor.
Definition: Shell.hpp:77
virtual bool configure_hook()
Configure shell: init ROS node.