YARP
Yet Another Robot Platform
PortCoreOutputUnit.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_IMPL_PORTCOREOUTPUTUNIT_H
11 #define YARP_OS_IMPL_PORTCOREOUTPUTUNIT_H
12 
13 #include <yarp/os/OutputProtocol.h>
14 #include <yarp/os/Semaphore.h>
15 #include <yarp/os/impl/PortCore.h>
17 
18 #include <mutex>
19 
20 namespace yarp {
21 namespace os {
22 namespace impl {
23 
29  public PortCoreUnit
30 {
31 public:
40  PortCoreOutputUnit(PortCore& owner, int index, OutputProtocol* op);
41 
45  ~PortCoreOutputUnit() override;
46 
51  bool start() override;
52 
56  void run() override;
57 
61  virtual void runSingleThreaded();
62 
63  // documented in PortCoreUnit
64  bool isOutput() override
65  {
66  return true;
67  }
68 
69  // documented in PortCoreUnit
70  void close() override
71  {
72  closeMain();
73  }
74 
75  // documented in PortCoreUnit
76  bool isFinished() override
77  {
78  return finished;
79  }
80 
81  // documented in PortCoreUnit
82  Route getRoute() override;
83 
84  // documented in PortCoreUnit
85  void* send(const yarp::os::PortWriter& writer,
86  yarp::os::PortReader* reader,
87  const yarp::os::PortWriter* callback,
88  void* tracker,
89  const std::string& envelopeString,
90  bool waitAfter,
91  bool waitBefore,
92  bool* gotReply) override;
93 
94  // documented in PortCoreUnit
95  void* takeTracker() override;
96 
97  // documented in PortCoreUnit
98  bool isBusy() override;
99 
100  // documented in PortCoreUnit
101  void setCarrierParams(const yarp::os::Property& params) override;
102 
103  // documented in PortCoreUnit
104  void getCarrierParams(yarp::os::Property& params) override;
105 
106  // return the protocol object
108 
109 private:
110  OutputProtocol *op;
111  bool closing;
112  bool finished;
113  bool running;
114  bool threaded;
115  bool sending;
116  yarp::os::Semaphore phase;
117  yarp::os::Semaphore activate;
118  std::mutex trackerMutex;
119  const yarp::os::PortWriter* cachedWriter;
120  yarp::os::PortReader *cachedReader;
121  const yarp::os::PortWriter* cachedCallback;
122  void *cachedTracker;
124  std::string cachedEnvelope;
125 
129  bool sendHelper();
130 
134  void closeBasic();
135 
139  void closeMain();
140 };
141 
142 } // namespace impl
143 } // namespace os
144 } // namespace yarp
145 
146 #endif // YARP_OS_IMPL_PORTCOREOUTPUTUNIT_H
PortCoreUnit.h
yarp::os::Semaphore
A class for thread synchronization and mutual exclusion.
Definition: Semaphore.h:29
yarp::os::impl::PortCoreOutputUnit::isFinished
bool isFinished() override
Definition: PortCoreOutputUnit.h:76
yarp::os::impl::PortCoreUnit
This manages a single threaded resource related to a single input or output connection.
Definition: PortCoreUnit.h:30
yarp::os::impl::PortCoreOutputUnit::run
void run() override
The body of a thread managing background sends.
Definition: PortCoreOutputUnit.cpp:77
yarp::os::OutputProtocol
The output side of an active connection between two ports.
Definition: OutputProtocol.h:33
yarp::os::impl::PortCoreOutputUnit::getRoute
Route getRoute() override
Definition: PortCoreOutputUnit.cpp:245
yarp::os::impl::PortCoreOutputUnit::getCarrierParams
void getCarrierParams(yarp::os::Property &params) override
Definition: PortCoreOutputUnit.cpp:433
yarp::os::impl::PortCoreOutputUnit::start
bool start() override
Prepare to serve this output.
Definition: PortCoreOutputUnit.cpp:53
yarp::os::impl::PortCoreOutputUnit::isOutput
bool isOutput() override
Definition: PortCoreOutputUnit.h:64
yarp::os::impl::PortCore
Definition: PortCore.h:155
yarp::os::Route
Information about a connection between two ports.
Definition: Route.h:32
yarp::os::PortWriter
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:27
yarp::os::impl::PortCoreOutputUnit::runSingleThreaded
virtual void runSingleThreaded()
Perform send operations without a separate thread.
Definition: PortCoreOutputUnit.cpp:119
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
yarp::os::impl::PortCoreOutputUnit::send
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.
Definition: PortCoreOutputUnit.cpp:346
yarp::os::impl::PortCoreOutputUnit::getOutPutProtocol
OutputProtocol * getOutPutProtocol()
Definition: PortCoreOutputUnit.cpp:440
yarp::os::impl::PortCoreOutputUnit::takeTracker
void * takeTracker() override
Reacquire a tracker previously passed via send().
Definition: PortCoreOutputUnit.cpp:409
Semaphore.h
yarp::os::impl::PortCoreOutputUnit::~PortCoreOutputUnit
~PortCoreOutputUnit() override
Destructor.
Definition: PortCoreOutputUnit.cpp:47
yarp::os::impl::PortCoreOutputUnit
Manager for a single output from a port.
Definition: PortCoreOutputUnit.h:30
yarp::os::impl::PortCoreOutputUnit::setCarrierParams
void setCarrierParams(const yarp::os::Property &params) override
Set arbitrary parameters for this connection.
Definition: PortCoreOutputUnit.cpp:426
PortCore.h
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::impl::PortCoreOutputUnit::isBusy
bool isBusy() override
Definition: PortCoreOutputUnit.cpp:421
yarp::os::impl::PortCoreOutputUnit::close
void close() override
Definition: PortCoreOutputUnit.h:70
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
OutputProtocol.h
yarp::os::impl::PortCoreOutputUnit::PortCoreOutputUnit
PortCoreOutputUnit(PortCore &owner, int index, OutputProtocol *op)
Constructor.
Definition: PortCoreOutputUnit.cpp:28