YARP
Yet Another Robot Platform
PortCoreOutputUnit.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_OS_IMPL_PORTCOREOUTPUTUNIT_H
8 #define YARP_OS_IMPL_PORTCOREOUTPUTUNIT_H
9 
10 #include <yarp/os/OutputProtocol.h>
11 #include <yarp/os/Semaphore.h>
12 #include <yarp/os/impl/PortCore.h>
14 
15 #include <mutex>
16 
17 namespace yarp {
18 namespace os {
19 namespace impl {
20 
26  public PortCoreUnit
27 {
28 public:
37  PortCoreOutputUnit(PortCore& owner, int index, OutputProtocol* op);
38 
42  ~PortCoreOutputUnit() override;
43 
48  bool start() override;
49 
53  void run() override;
54 
58  virtual void runSingleThreaded();
59 
60  // documented in PortCoreUnit
61  bool isOutput() override
62  {
63  return true;
64  }
65 
66  // documented in PortCoreUnit
67  void close() override
68  {
69  closeMain();
70  }
71 
72  // documented in PortCoreUnit
73  bool isFinished() override
74  {
75  return finished;
76  }
77 
78  // documented in PortCoreUnit
79  Route getRoute() override;
80 
81  // documented in PortCoreUnit
82  void* send(const yarp::os::PortWriter& writer,
83  yarp::os::PortReader* reader,
84  const yarp::os::PortWriter* callback,
85  void* tracker,
86  const std::string& envelopeString,
87  bool waitAfter,
88  bool waitBefore,
89  bool* gotReply) override;
90 
91  // documented in PortCoreUnit
92  void* takeTracker() override;
93 
94  // documented in PortCoreUnit
95  bool isBusy() override;
96 
97  // documented in PortCoreUnit
98  void setCarrierParams(const yarp::os::Property& params) override;
99 
100  // documented in PortCoreUnit
101  void getCarrierParams(yarp::os::Property& params) override;
102 
103  // return the protocol object
105 
106 private:
107  OutputProtocol *op;
108  bool closing;
109  bool finished;
110  bool running;
111  bool threaded;
112  bool sending;
113  yarp::os::Semaphore phase;
114  yarp::os::Semaphore activate;
115  std::mutex trackerMutex;
116  const yarp::os::PortWriter* cachedWriter;
117  yarp::os::PortReader *cachedReader;
118  const yarp::os::PortWriter* cachedCallback;
120  void *cachedTracker;
121  std::string cachedEnvelope;
122 
126  bool sendHelper();
127 
131  void closeBasic();
132 
136  void closeMain();
137 };
138 
139 } // namespace impl
140 } // namespace os
141 } // namespace yarp
142 
143 #endif // YARP_OS_IMPL_PORTCOREOUTPUTUNIT_H
The output side of an active connection between two ports.
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
Information about a connection between two ports.
Definition: Route.h:29
A class for thread synchronization and mutual exclusion.
Definition: Semaphore.h:26
Manager for a single output from a port.
void getCarrierParams(yarp::os::Property &params) override
void * takeTracker() override
Reacquire a tracker previously passed via send().
void setCarrierParams(const yarp::os::Property &params) override
Set arbitrary parameters for this connection.
void * send(const yarp::os::PortWriter &writer, yarp::os::PortReader *reader, const yarp::os::PortWriter *callback, void *tracker, const std::string &envelopeString, bool waitAfter, bool waitBefore, bool *gotReply) override
Send a message on the connection.
PortCoreOutputUnit(PortCore &owner, int index, OutputProtocol *op)
Constructor.
bool start() override
Prepare to serve this output.
void run() override
The body of a thread managing background sends.
virtual void runSingleThreaded()
Perform send operations without a separate thread.
This manages a single threaded resource related to a single input or output connection.
Definition: PortCoreUnit.h:27
The main, catch-all namespace for YARP.
Definition: dirs.h:16