YARP
Yet Another Robot Platform
PortMonitor.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef PORTMONITOR_INC
7 #define PORTMONITOR_INC
8 
10 #include <yarp/os/DummyConnector.h>
11 #include <yarp/os/Election.h>
13 #include <yarp/os/Things.h>
14 
15 #include "MonitorBinding.h"
16 #include "MonitorEvent.h"
17 
18 #include <mutex>
19 
20 
21 class PortMonitor;
22 
27  public yarp::os::PeerRecord<PortMonitor>
28 {
29 public:
30  virtual ~PortMonitorGroup() {}
31  virtual bool acceptIncomingData(PortMonitor *source);
32 };
33 
34 
35 
49 class PortMonitor :
51 {
52 
53 public:
54  PortMonitor() = default;
55  PortMonitor(const PortMonitor&) = delete;
56  PortMonitor(PortMonitor&&) = delete;
57  PortMonitor& operator=(const PortMonitor&) = delete;
59 
60  ~PortMonitor() override
61  {
62  if (!portName.empty()) {
63  getPeers().remove(portName,this);
64  }
65  delete binder;
66  }
67 
68  Carrier *create() const override
69  {
70  return new PortMonitor();
71  }
72 
73  std::string getName() const override
74  {
75  return "portmonitor";
76  }
77 
78  std::string toString() const override
79  {
80  return "portmonitor_carrier";
81  }
82 
83  bool configure(yarp::os::ConnectionState& proto) override;
84  bool configureFromProperty(yarp::os::Property& options) override;
85 
86  //bool modifiesIncomingData() override;
87  bool acceptIncomingData(yarp::os::ConnectionReader& reader) override;
88 
90 
91  const yarp::os::PortWriter& modifyOutgoingData(const yarp::os::PortWriter& writer) override;
92 
93  bool acceptOutgoingData(const yarp::os::PortWriter& writer) override;
94 
96 
97  void setCarrierParams(const yarp::os::Property& params) override;
98 
99  void getCarrierParams(yarp::os::Property& params) const override;
100 
101 
102  void lock() const { mutex.lock(); }
103  void unlock() const { mutex.unlock(); }
104 
106  {
107  if(!bReady) {
108  return nullptr;
109  }
110  return binder;
111  }
112 
113 public:
114  std::string portName;
115  std::string sourceName;
116 
117 private:
119  static yarp::os::ElectionOf<PortMonitorGroup>& getPeers();
120 
121 
122 private:
123  bool bReady {false};
125  yarp::os::ConnectionReader* localReader {nullptr};
126  yarp::os::Things thing;
127  MonitorBinding* binder {nullptr};
128  PortMonitorGroup *group {nullptr};
129  mutable std::mutex mutex;
130 };
131 
132 #endif //PORTMONITOR_INC
Manager for arbitration-aware inputs to a given port.
Definition: PortMonitor.h:28
virtual ~PortMonitorGroup()
Definition: PortMonitor.h:30
virtual bool acceptIncomingData(PortMonitor *source)
Allow to monitor and modify port data from Lua script Under development.
Definition: PortMonitor.h:51
~PortMonitor() override
Definition: PortMonitor.h:60
void lock() const
Definition: PortMonitor.h:102
void getCarrierParams(yarp::os::Property &params) const override
Get carrier configuration and deliver it by port administrative commands.
yarp::os::ConnectionReader & modifyIncomingData(yarp::os::ConnectionReader &reader) override
Modify incoming payload data, if appropriate.
Carrier * create() const override
Factory method.
Definition: PortMonitor.h:68
PortMonitor & operator=(const PortMonitor &)=delete
void unlock() const
Definition: PortMonitor.h:103
const yarp::os::PortWriter & modifyOutgoingData(const yarp::os::PortWriter &writer) override
Modify outgoing payload data, if appropriate.
PortMonitor(const PortMonitor &)=delete
std::string getName() const override
Get the name of this connection type ("tcp", "mcast", "shmem", ...)
Definition: PortMonitor.h:73
std::string toString() const override
Get name of carrier.
Definition: PortMonitor.h:78
PortMonitor(PortMonitor &&)=delete
yarp::os::PortReader & modifyReply(yarp::os::PortReader &reader) override
Modify reply payload data, if appropriate.
void setCarrierParams(const yarp::os::Property &params) override
Configure carrier from port administrative commands.
bool configureFromProperty(yarp::os::Property &options) override
Definition: PortMonitor.cpp:52
PortMonitor & operator=(PortMonitor &&)=delete
bool acceptIncomingData(yarp::os::ConnectionReader &reader) override
Determine whether incoming data should be accepted.
std::string sourceName
Definition: PortMonitor.h:115
bool acceptOutgoingData(const yarp::os::PortWriter &writer) override
Determine whether outgoing data should be accepted.
MonitorBinding * getBinder()
Definition: PortMonitor.h:105
std::string portName
Definition: PortMonitor.h:114
bool configure(yarp::os::ConnectionState &proto) override
Class PortMonitor.
Definition: PortMonitor.cpp:28
PortMonitor()=default
An interface for reading from a network connection.
The basic state of a connection - route, streams in use, etc.
A dummy connection to test yarp::os::Portable implementations.
void remove(const std::string &key, typename PR::peer_type *entity)
Definition: Election.h:99
A starter class for implementing simple modifying carriers.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
A class for storing options and configuration information.
Definition: Property.h:34
Base class for generic things.
Definition: Things.h:19