SHM
Shared-memorybasedHandy-communicationManager
shm_pub_sub_python.cpp
Go to the documentation of this file.
1 
9 #include <iostream>
10 #include <boost/python.hpp>
11 
12 #include "shm_pub_sub.hpp"
13 
15 {
16 public:
17  PublisherBool(std::string name = "", bool arg = false, int buffer_num = 3)
18  : Publisher<bool>(name, buffer_num)
19  {};
20 
21  // ! pythonでは参照渡しができないための変換関数
22  void _publish(bool data)
23  {
24  publish(data);
25  };
26 };
27 
29 {
30 public:
31  PublisherInt(std::string name = "", int arg = 0, int buffer_num = 3)
32  : Publisher<int>(name, buffer_num)
33  {};
34 
35  // ! pythonでは参照渡しができないための変換関数
36  void _publish(int data)
37  {
38  publish(data);
39  };
40 };
41 
43 {
44 public:
45  PublisherFloat(std::string name = "", float arg = 0.0f, int buffer_num = 3)
46  : Publisher<float>(name, buffer_num)
47  {};
48 
49  // ! pythonでは参照渡しができないための変換関数
50  void _publish(float data)
51  {
52  publish(data);
53  };
54 };
55 
57 {
58 public:
59  SubscriberBool(std::string name = "", bool arg = false)
60  : Subscriber<bool>(name)
61  {};
62 
63  boost::python::tuple _subscribe()
64  {
65  bool is_success;
66  bool result = subscribe(&is_success);
67  return boost::python::make_tuple(result, is_success);
68  };
69 };
70 
72 {
73 public:
74  SubscriberInt(std::string name = "", int arg = 0)
75  : Subscriber<int>(name)
76  {};
77 
78  boost::python::tuple _subscribe()
79  {
80  bool is_success;
81  int result = subscribe(&is_success);
82  return boost::python::make_tuple(result, is_success);
83  };
84 };
85 
87 {
88 public:
89  SubscriberFloat(std::string name = "", float arg = 0.0f)
90  : Subscriber<float>(name)
91  {};
92 
93  boost::python::tuple _subscribe()
94  {
95  bool is_success;
96  float result = subscribe(&is_success);
97  return boost::python::make_tuple(result, is_success);
98  };
99 };
100 
101 BOOST_PYTHON_MODULE(shm_pub_sub) {
102  boost::python::class_<PublisherBool>("Publisher")
103  .def(boost::python::init<std::string, bool, int>())
104  .def("publish", &PublisherInt::_publish)
105  ;
106  boost::python::class_<PublisherInt>("Publisher")
107  .def(boost::python::init<std::string, int, int>())
108  .def("publish", &PublisherInt::_publish)
109  ;
110  boost::python::class_<PublisherFloat>("Publisher")
111  .def(boost::python::init<std::string, float, int>())
112  .def("publish", &PublisherFloat::_publish)
113  ;
114 
115  boost::python::class_<SubscriberBool>("Subscriber")
116  .def(boost::python::init<std::string, bool>())
117  .def("subscribe", &SubscriberBool::_subscribe)
118  ;
119  boost::python::class_<SubscriberInt>("Subscriber")
120  .def(boost::python::init<std::string, int>())
121  .def("subscribe", &SubscriberInt::_subscribe)
122  ;
123  boost::python::class_<SubscriberFloat>("Subscriber")
124  .def(boost::python::init<std::string, float>())
125  .def("subscribe", &SubscriberFloat::_subscribe)
126  ;
127 }
128 
irlab::shm::Subscriber
Class representing a subscriber that retrieves topics from shared memory This class is used to load a...
Definition: shm_pub_sub.hpp:91
PublisherBool
Definition: shm_pub_sub_python.cpp:14
PublisherInt
Definition: shm_pub_sub_python.cpp:28
irlab::shm::Publisher< bool >::publish
void publish(const bool &data)
Publish a topic None Writes the topic to the buffer with the oldest timestamp and updates the timesta...
Definition: shm_pub_sub.hpp:207
SubscriberInt
Definition: shm_pub_sub_python.cpp:71
SubscriberBool
Definition: shm_pub_sub_python.cpp:56
shm_pub_sub.hpp
Class definitions for topic communication with publisher/subscriber model. The notation is compliante...
PublisherFloat
Definition: shm_pub_sub_python.cpp:42
SubscriberFloat
Definition: shm_pub_sub_python.cpp:86
irlab::shm::Subscriber< bool >::subscribe
const bool subscribe(bool *state)
Subscribe a topic Const reference to the loaded topic. The topic with the most recent timestamp is lo...
Definition: shm_pub_sub.hpp:301
irlab::shm::Publisher
Class representing a publisher that outputs topics to shared memory This class is used to output the ...
Definition: shm_pub_sub.hpp:59