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::os::impl {
17 
23 class PortCoreUnit :
24  public ThreadImpl
25 {
26 public:
33  PortCoreUnit(PortCore& owner, int index) :
34  owner(owner),
35  doomed(false),
36  hasMode(false),
37  pupped(false),
38  index(index)
39  {
40  }
41 
45  virtual ~PortCoreUnit()
46  {
47  }
48 
52  virtual bool isInput()
53  {
54  return false;
55  }
56 
60  virtual bool isOutput()
61  {
62  return false;
63  }
64 
69  virtual bool isFinished()
70  {
71  return false;
72  }
73 
78  virtual Route getRoute()
79  {
80  return Route("null", "null", "null");
81  }
82 
87  bool isDoomed()
88  {
89  return doomed;
90  }
91 
95  void setDoomed()
96  {
97  doomed = true;
98  }
99 
125  virtual void* send(const yarp::os::PortWriter& writer,
126  yarp::os::PortReader* reader,
127  const yarp::os::PortWriter* callback,
128  void* tracker,
129  const std::string& envelope,
130  bool waitAfter = true,
131  bool waitBefore = true,
132  bool* gotReply = nullptr)
133  {
134  // do nothing
135  YARP_UNUSED(writer);
136  YARP_UNUSED(reader);
137  YARP_UNUSED(callback);
138  YARP_UNUSED(envelope);
139  YARP_UNUSED(waitAfter);
140  YARP_UNUSED(waitBefore);
141  YARP_UNUSED(gotReply);
142  return tracker;
143  }
144 
154  virtual void* takeTracker()
155  {
156  return nullptr;
157  }
158 
162  virtual bool isBusy()
163  {
164  return false;
165  }
166 
172  virtual bool interrupt()
173  {
174  return false;
175  }
176 
184  void setMode()
185  {
186  Name name(getRoute().getCarrierName() + std::string("://test"));
187  mode = name.getCarrierModifier("log", &hasMode);
188  }
189 
193  int getIndex()
194  {
195  return index;
196  }
197 
206  std::string getMode(bool* hasMode = nullptr)
207  {
208  if (hasMode != nullptr) {
209  *hasMode = this->hasMode;
210  }
211  return (this->hasMode) ? mode : "";
212  }
213 
220  bool isPupped() const
221  {
222  return pupped;
223  }
224 
232  std::string getPupString() const
233  {
234  return pupString;
235  }
236 
246  void setPupped(const std::string& pupString)
247  {
248  pupped = true;
249  this->pupString = pupString;
250  }
251 
256  virtual void setCarrierParams(const yarp::os::Property& params)
257  {
258  YARP_UNUSED(params);
259  }
260 
264  virtual void getCarrierParams(yarp::os::Property& params)
265  {
266  YARP_UNUSED(params);
267  }
268 
269 
270 protected:
275  {
276  return owner;
277  }
278 
279 private:
280  PortCore& owner;
281  bool doomed;
282  std::string mode;
283  bool hasMode;
284  bool pupped;
285  int index;
286  std::string pupString;
287 };
288 
289 } // namespace yarp::os::impl
290 
291 #endif // YARP_OS_IMPL_PORTCOREUNIT_H
Simple abstraction for a YARP port name.
Definition: Name.h:18
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:24
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:23
A class for storing options and configuration information.
Definition: Property.h:33
Information about a connection between two ports.
Definition: Route.h:28
This manages a single threaded resource related to a single input or output connection.
Definition: PortCoreUnit.h:25
PortCoreUnit(PortCore &owner, int index)
Constructor.
Definition: PortCoreUnit.h:33
std::string getPupString() const
Definition: PortCoreUnit.h:232
virtual bool interrupt()
Interrupt the connection.
Definition: PortCoreUnit.h:172
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:246
virtual void * takeTracker()
Reacquire a tracker previously passed via send().
Definition: PortCoreUnit.h:154
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:125
std::string getMode(bool *hasMode=nullptr)
Read the "mode" of the connection - basically, whether it is used for logging or not.
Definition: PortCoreUnit.h:206
virtual void getCarrierParams(yarp::os::Property &params)
Definition: PortCoreUnit.h:264
void setMode()
Check the carrier used for the connection, and see if it has a "log" modifier.
Definition: PortCoreUnit.h:184
virtual ~PortCoreUnit()
Destructor.
Definition: PortCoreUnit.h:45
void setDoomed()
Request that this connection be shut down as soon as possible.
Definition: PortCoreUnit.h:95
virtual void setCarrierParams(const yarp::os::Property &params)
Set arbitrary parameters for this connection.
Definition: PortCoreUnit.h:256
An abstraction for a thread of execution.
Definition: ThreadImpl.h:21
The components from which ports and connections are built.
#define YARP_UNUSED(var)
Definition: api.h:162