YARP
Yet Another Robot Platform
Contactable.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_CONTACTABLE_H
11 #define YARP_OS_CONTACTABLE_H
12 
13 #include <yarp/os/Contact.h>
14 #include <yarp/os/PortReader.h>
15 #include <yarp/os/PortReport.h>
16 #include <yarp/os/PortWriter.h>
17 
18 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3
19 #define YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE
20 # include <yarp/os/Mutex.h>
21 #undef YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE
22 #endif
23 
24 #include <mutex>
25 
26 // Forward declarations:
27 namespace yarp {
28 namespace os {
29 
30 class Property;
31 
38 {
39 
40 public:
44  virtual ~Contactable();
45 
56  virtual bool open(const std::string& name) = 0;
57 
69  virtual bool open(const Contact& contact, bool registerName = true) = 0;
70 
77  virtual bool addOutput(const std::string& name) = 0;
78 
87  virtual bool addOutput(const std::string& name, const std::string& carrier) = 0;
88 
96  virtual bool addOutput(const Contact& contact) = 0;
97 
101  virtual void close() = 0;
102 
110  virtual void interrupt() = 0;
111 
116  virtual void resume() = 0;
117 
123  virtual Contact where() const = 0;
124 
130  virtual std::string getName() const;
131 
132 
149  virtual bool setEnvelope(PortWriter& envelope) = 0;
150 
151 
165  virtual bool getEnvelope(PortReader& envelope) = 0;
166 
167 
175  virtual int getInputCount() = 0;
176 
182  virtual int getOutputCount() = 0;
183 
193  virtual void getReport(PortReport& reporter) = 0;
194 
195 
204  virtual void setReporter(PortReport& reporter) = 0;
205 
210  virtual void resetReporter() = 0;
211 
217  virtual bool isWriting() = 0;
218 
219 
225  virtual void setReader(PortReader& reader) = 0;
226 
232  virtual void setAdminReader(PortReader& reader) = 0;
233 
241  virtual void setInputMode(bool expectInput) = 0;
242 
250  virtual void setOutputMode(bool expectOutput) = 0;
251 
259  virtual void setRpcMode(bool expectRpc) = 0;
260 
268  virtual Type getType() = 0;
269 
275  virtual void promiseType(const Type& typ) = 0;
276 
285  virtual Property* acquireProperties(bool readOnly) = 0;
286 
293  virtual void releaseProperties(Property* prop) = 0;
294 
301  virtual void includeNodeInName(bool flag) = 0;
302 
306  void setReadOnly();
307 
311  void setWriteOnly();
312 
316  void setRpcServer();
317 
321  void setRpcClient();
322 
323 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3
339  YARP_DEPRECATED_MSG("Use setCallbackLock with std::mutex instead")
340  virtual bool setCallbackLock(yarp::os::Mutex* mutex) = 0;
342 #endif
343 
355  virtual bool setCallbackLock(std::mutex* mutex = nullptr) = 0;
356 
360  virtual bool removeCallbackLock() = 0;
361 
370  virtual bool lockCallback() = 0;
371 
381  virtual bool tryLockCallback() = 0;
382 
386  virtual void unlockCallback() = 0;
387 };
388 
389 } // namespace os
390 } // namespace yarp
391 
392 #endif // YARP_OS_CONTACTABLE_H
YARP_WARNING_PUSH
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition: system.h:334
yarp::os::Contactable::removeCallbackLock
virtual bool removeCallbackLock()=0
Remove a lock on callbacks added with setCallbackLock()
yarp::os::Contactable::addOutput
virtual bool addOutput(const Contact &contact)=0
Add an output connection to the specified port, using specified network parameters.
yarp::os::Contactable::getInputCount
virtual int getInputCount()=0
Determine how many connections are arriving into this port.
yarp::os::Contactable::addOutput
virtual bool addOutput(const std::string &name)=0
Add an output connection to the specified port.
yarp::os::Contactable::setOutputMode
virtual void setOutputMode(bool expectOutput)=0
Configure the port to allow or forbid outputs.
yarp::os::Contactable::setReporter
virtual void setReporter(PortReport &reporter)=0
Set a callback to be called upon any future connections and disconnections to/from the port.
yarp::os::Type
Definition: Type.h:24
yarp::os::Contactable::getReport
virtual void getReport(PortReport &reporter)=0
Get information on the state of the port - connections etc.
yarp::os::Contactable::releaseProperties
virtual void releaseProperties(Property *prop)=0
End access unstructured port properties.
yarp::os::Contactable::promiseType
virtual void promiseType(const Type &typ)=0
Commit the port to a particular type of data.
YARP_os_API
#define YARP_os_API
Definition: api.h:19
yarp::os::PortReport
A base class for objects that want information about port status changes.
Definition: PortReport.h:31
yarp::os::Contactable::interrupt
virtual void interrupt()=0
Interrupt any current reads or writes attached to the port.
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::Contactable::tryLockCallback
virtual bool tryLockCallback()=0
Try to lock callbacks until unlockCallback() is called.
yarp::os::Contactable::~Contactable
virtual ~Contactable()
Destructor.
yarp::os::Contactable::where
virtual Contact where() const =0
Returns information about how this port can be reached.
PortWriter.h
yarp::os::Contactable::setInputMode
virtual void setInputMode(bool expectInput)=0
Configure the port to allow or forbid inputs.
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::Contactable::setEnvelope
virtual bool setEnvelope(PortWriter &envelope)=0
Set an envelope (e.g., a timestamp) to the next message which will be sent.
yarp::os::Contactable::open
virtual bool open(const Contact &contact, bool registerName=true)=0
Start port operation with user-chosen network parameters.
yarp::os::Contactable::unlockCallback
virtual void unlockCallback()=0
Unlock callbacks.
yarp::os::Contactable::setRpcMode
virtual void setRpcMode(bool expectRpc)=0
Configure the port to be RPC only.
yarp::os::Contactable::acquireProperties
virtual Property * acquireProperties(bool readOnly)=0
Access unstructured port properties.
yarp::os::Contactable::open
virtual bool open(const std::string &name)=0
Start port operation, with a specific name, with automatically-chosen network parameters.
yarp::os::Contactable::setReader
virtual void setReader(PortReader &reader)=0
Set an external reader for port data.
yarp::os::Contactable::setAdminReader
virtual void setAdminReader(PortReader &reader)=0
Set an external reader for unrecognized administrative port messages.
yarp::os::Contactable::resume
virtual void resume()=0
Put the port back in an operative state after interrupt() has been called.
yarp::os::Contactable::lockCallback
virtual bool lockCallback()=0
Lock callbacks until unlockCallback() is called.
yarp::os::Contactable::includeNodeInName
virtual void includeNodeInName(bool flag)=0
Choose whether to prepend a node name (if one is available) to the port's name.
yarp::os::Contactable::setCallbackLock
virtual bool setCallbackLock(std::mutex *mutex=nullptr)=0
Add a lock to use when invoking callbacks.
YARP_WARNING_POP
#define YARP_WARNING_POP
Ends a temporary alteration of the enabled warnings.
Definition: system.h:335
yarp::os::Contactable::getOutputCount
virtual int getOutputCount()=0
Determine how many output connections this port has.
Mutex.h
YARP_DEPRECATED_MSG
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2883
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::Contact
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
yarp::os::Contactable::getEnvelope
virtual bool getEnvelope(PortReader &envelope)=0
Get the envelope information (e.g., a timestamp) from the last message received on the port.
PortReader.h
yarp::os::Contactable::resetReporter
virtual void resetReporter()=0
Remove the callback which is called upon any future connections and disconnections to/from the port.
yarp::os::Mutex
Basic wrapper for mutual exclusion.
Definition: Mutex.h:35
yarp::os::Contactable::getType
virtual Type getType()=0
Get the type of data the port has committed to send/receive.
Contact.h
yarp::os::Contactable::close
virtual void close()=0
Stop port activity.
YARP_DISABLE_DEPRECATED_WARNING
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition: system.h:336
yarp::os::Contactable::addOutput
virtual bool addOutput(const std::string &name, const std::string &carrier)=0
Add an output connection to the specified port, using a specified carrier.
PortReport.h
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37
yarp::os::Contactable
An abstract port.
Definition: Contactable.h:38
yarp::os::Contactable::isWriting
virtual bool isWriting()=0
Report whether the port is currently writing data.