YARP
Yet Another Robot Platform
PortCoreUnit.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_PORTCOREUNIT_H
11 #define YARP_OS_IMPL_PORTCOREUNIT_H
12 
13 #include <yarp/os/Name.h>
14 #include <yarp/os/impl/PortCore.h>
16 
17 #include <string>
18 
19 namespace yarp {
20 namespace os {
21 namespace impl {
22 
28 class PortCoreUnit :
29  public ThreadImpl
30 {
31 public:
38  PortCoreUnit(PortCore& owner, int index) :
39  owner(owner),
40  doomed(false),
41  hasMode(false),
42  pupped(false),
43  index(index)
44  {
45  }
46 
50  virtual ~PortCoreUnit()
51  {
52  }
53 
57  virtual bool isInput()
58  {
59  return false;
60  }
61 
65  virtual bool isOutput()
66  {
67  return false;
68  }
69 
74  virtual bool isFinished()
75  {
76  return false;
77  }
78 
83  virtual Route getRoute()
84  {
85  return Route("null", "null", "null");
86  }
87 
92  bool isDoomed()
93  {
94  return doomed;
95  }
96 
100  void setDoomed()
101  {
102  doomed = true;
103  }
104 
130  virtual void* send(const yarp::os::PortWriter& writer,
131  yarp::os::PortReader* reader,
132  const yarp::os::PortWriter* callback,
133  void* tracker,
134  const std::string& envelope,
135  bool waitAfter = true,
136  bool waitBefore = true,
137  bool* gotReply = nullptr)
138  {
139  // do nothing
140  YARP_UNUSED(writer);
141  YARP_UNUSED(reader);
142  YARP_UNUSED(callback);
143  YARP_UNUSED(envelope);
144  YARP_UNUSED(waitAfter);
145  YARP_UNUSED(waitBefore);
146  YARP_UNUSED(gotReply);
147  return tracker;
148  }
149 
159  virtual void* takeTracker()
160  {
161  return nullptr;
162  }
163 
167  virtual bool isBusy()
168  {
169  return false;
170  }
171 
177  virtual bool interrupt()
178  {
179  return false;
180  }
181 
189  void setMode()
190  {
191  Name name(getRoute().getCarrierName() + std::string("://test"));
192  mode = name.getCarrierModifier("log", &hasMode);
193  }
194 
198  int getIndex()
199  {
200  return index;
201  }
202 
211  std::string getMode(bool* hasMode = nullptr)
212  {
213  if (hasMode != nullptr) {
214  *hasMode = this->hasMode;
215  }
216  return (this->hasMode) ? mode : "";
217  }
218 
225  bool isPupped() const
226  {
227  return pupped;
228  }
229 
237  std::string getPupString() const
238  {
239  return pupString;
240  }
241 
251  void setPupped(const std::string& pupString)
252  {
253  pupped = true;
254  this->pupString = pupString;
255  }
256 
261  virtual void setCarrierParams(const yarp::os::Property& params)
262  {
263  YARP_UNUSED(params);
264  }
265 
269  virtual void getCarrierParams(yarp::os::Property& params)
270  {
271  YARP_UNUSED(params);
272  }
273 
274 
275 protected:
280  {
281  return owner;
282  }
283 
284 private:
285  PortCore& owner;
286  bool doomed;
287  std::string mode;
288  bool hasMode;
289  bool pupped;
290  int index;
291  std::string pupString;
292 };
293 
294 } // namespace impl
295 } // namespace os
296 } // namespace yarp
297 
298 #endif // YARP_OS_IMPL_PORTCOREUNIT_H
yarp::os::impl::PortCoreUnit::setDoomed
void setDoomed()
Request that this connection be shut down as soon as possible.
Definition: PortCoreUnit.h:100
yarp::os::impl::PortCoreUnit::PortCoreUnit
PortCoreUnit(PortCore &owner, int index)
Constructor.
Definition: PortCoreUnit.h:38
yarp::os::impl::PortCoreUnit::isFinished
virtual bool isFinished()
Definition: PortCoreUnit.h:74
yarp::os::impl::PortCoreUnit::setPupped
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:251
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::PortCoreUnit::getRoute
virtual Route getRoute()
Definition: PortCoreUnit.h:83
ThreadImpl.h
yarp::os::impl::PortCoreUnit::interrupt
virtual bool interrupt()
Interrupt the connection.
Definition: PortCoreUnit.h:177
YARP_UNUSED
#define YARP_UNUSED(var)
Definition: api.h:159
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
Name.h
yarp::os::impl::PortCoreUnit::isInput
virtual bool isInput()
Definition: PortCoreUnit.h:57
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::Name::getCarrierModifier
std::string getCarrierModifier(const char *mod, bool *hasModifier=nullptr)
Definition: Name.cpp:47
yarp::os::impl::PortCoreUnit::isOutput
virtual bool isOutput()
Definition: PortCoreUnit.h:65
yarp::os::impl::PortCoreUnit::isPupped
bool isPupped() const
Definition: PortCoreUnit.h:225
yarp::os::impl::PortCoreUnit::isDoomed
bool isDoomed()
Definition: PortCoreUnit.h:92
yarp::os::Name
Simple abstraction for a YARP port name.
Definition: Name.h:22
yarp::os::impl::PortCoreUnit::getIndex
int getIndex()
Definition: PortCoreUnit.h:198
yarp::os::impl::PortCoreUnit::getMode
std::string getMode(bool *hasMode=nullptr)
Read the "mode" of the connection - basically, whether it is used for logging or not.
Definition: PortCoreUnit.h:211
yarp::os::impl::PortCoreUnit::send
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:130
yarp::os::impl::ThreadImpl
An abstraction for a thread of execution.
Definition: ThreadImpl.h:26
yarp::os::impl::PortCoreUnit::takeTracker
virtual void * takeTracker()
Reacquire a tracker previously passed via send().
Definition: PortCoreUnit.h:159
PortCore.h
yarp::os::impl::PortCoreUnit::setCarrierParams
virtual void setCarrierParams(const yarp::os::Property &params)
Set arbitrary parameters for this connection.
Definition: PortCoreUnit.h:261
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::impl::PortCoreUnit::getOwner
PortCore & getOwner()
Definition: PortCoreUnit.h:279
yarp::os::impl::PortCoreUnit::~PortCoreUnit
virtual ~PortCoreUnit()
Destructor.
Definition: PortCoreUnit.h:50
yarp::os::impl::PortCoreUnit::getCarrierParams
virtual void getCarrierParams(yarp::os::Property &params)
Definition: PortCoreUnit.h:269
yarp::os::impl::PortCoreUnit::isBusy
virtual bool isBusy()
Definition: PortCoreUnit.h:167
yarp::os::impl::PortCoreUnit::setMode
void setMode()
Check the carrier used for the connection, and see if it has a "log" modifier.
Definition: PortCoreUnit.h:189
yarp::os::impl::PortCoreUnit::getPupString
std::string getPupString() const
Definition: PortCoreUnit.h:237
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37