YARP
Yet Another Robot Platform
PortCoreUnit.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_PORTCOREUNIT_H
8 #define YARP_OS_IMPL_PORTCOREUNIT_H
9 
10 #include <yarp/os/Name.h>
11 #include <yarp/os/impl/PortCore.h>
13 
14 #include <string>
15 
16 namespace yarp {
17 namespace os {
18 namespace impl {
19 
25 class PortCoreUnit :
26  public ThreadImpl
27 {
28 public:
35  PortCoreUnit(PortCore& owner, int index) :
36  owner(owner),
37  doomed(false),
38  hasMode(false),
39  pupped(false),
40  index(index)
41  {
42  }
43 
47  virtual ~PortCoreUnit()
48  {
49  }
50 
54  virtual bool isInput()
55  {
56  return false;
57  }
58 
62  virtual bool isOutput()
63  {
64  return false;
65  }
66 
71  virtual bool isFinished()
72  {
73  return false;
74  }
75 
80  virtual Route getRoute()
81  {
82  return Route("null", "null", "null");
83  }
84 
89  bool isDoomed()
90  {
91  return doomed;
92  }
93 
97  void setDoomed()
98  {
99  doomed = true;
100  }
101 
127  virtual void* send(const yarp::os::PortWriter& writer,
128  yarp::os::PortReader* reader,
129  const yarp::os::PortWriter* callback,
130  void* tracker,
131  const std::string& envelope,
132  bool waitAfter = true,
133  bool waitBefore = true,
134  bool* gotReply = nullptr)
135  {
136  // do nothing
137  YARP_UNUSED(writer);
138  YARP_UNUSED(reader);
139  YARP_UNUSED(callback);
140  YARP_UNUSED(envelope);
141  YARP_UNUSED(waitAfter);
142  YARP_UNUSED(waitBefore);
143  YARP_UNUSED(gotReply);
144  return tracker;
145  }
146 
156  virtual void* takeTracker()
157  {
158  return nullptr;
159  }
160 
164  virtual bool isBusy()
165  {
166  return false;
167  }
168 
174  virtual bool interrupt()
175  {
176  return false;
177  }
178 
186  void setMode()
187  {
188  Name name(getRoute().getCarrierName() + std::string("://test"));
189  mode = name.getCarrierModifier("log", &hasMode);
190  }
191 
195  int getIndex()
196  {
197  return index;
198  }
199 
208  std::string getMode(bool* hasMode = nullptr)
209  {
210  if (hasMode != nullptr) {
211  *hasMode = this->hasMode;
212  }
213  return (this->hasMode) ? mode : "";
214  }
215 
222  bool isPupped() const
223  {
224  return pupped;
225  }
226 
234  std::string getPupString() const
235  {
236  return pupString;
237  }
238 
248  void setPupped(const std::string& pupString)
249  {
250  pupped = true;
251  this->pupString = pupString;
252  }
253 
258  virtual void setCarrierParams(const yarp::os::Property& params)
259  {
260  YARP_UNUSED(params);
261  }
262 
266  virtual void getCarrierParams(yarp::os::Property& params)
267  {
268  YARP_UNUSED(params);
269  }
270 
271 
272 protected:
277  {
278  return owner;
279  }
280 
281 private:
282  PortCore& owner;
283  bool doomed;
284  std::string mode;
285  bool hasMode;
286  bool pupped;
287  int index;
288  std::string pupString;
289 };
290 
291 } // namespace impl
292 } // namespace os
293 } // namespace yarp
294 
295 #endif // YARP_OS_IMPL_PORTCOREUNIT_H
Simple abstraction for a YARP port name.
Definition: Name.h:19
std::string getCarrierModifier(const char *mod, bool *hasModifier=nullptr)
Definition: Name.cpp:44
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
This manages a single threaded resource related to a single input or output connection.
Definition: PortCoreUnit.h:27
PortCoreUnit(PortCore &owner, int index)
Constructor.
Definition: PortCoreUnit.h:35
std::string getPupString() const
Definition: PortCoreUnit.h:234
virtual bool interrupt()
Interrupt the connection.
Definition: PortCoreUnit.h:174
void setPupped(const std::string &pupString)
Tag this connection as having been created by a publisherUpdate message to the port's administrative ...
Definition: PortCoreUnit.h:248
virtual void * takeTracker()
Reacquire a tracker previously passed via send().
Definition: PortCoreUnit.h:156
virtual void * send(const yarp::os::PortWriter &writer, yarp::os::PortReader *reader, const yarp::os::PortWriter *callback, void *tracker, const std::string &envelope, bool waitAfter=true, bool waitBefore=true, bool *gotReply=nullptr)
Send a message on the connection.
Definition: PortCoreUnit.h:127
std::string getMode(bool *hasMode=nullptr)
Read the "mode" of the connection - basically, whether it is used for logging or not.
Definition: PortCoreUnit.h:208
virtual void getCarrierParams(yarp::os::Property &params)
Definition: PortCoreUnit.h:266
void setMode()
Check the carrier used for the connection, and see if it has a "log" modifier.
Definition: PortCoreUnit.h:186
virtual ~PortCoreUnit()
Destructor.
Definition: PortCoreUnit.h:47
void setDoomed()
Request that this connection be shut down as soon as possible.
Definition: PortCoreUnit.h:97
virtual void setCarrierParams(const yarp::os::Property &params)
Set arbitrary parameters for this connection.
Definition: PortCoreUnit.h:258
An abstraction for a thread of execution.
Definition: ThreadImpl.h:23
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_UNUSED(var)
Definition: api.h:162