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