YARP
Yet Another Robot Platform
Contactable.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_CONTACTABLE_H
8#define YARP_OS_CONTACTABLE_H
9
10#include <yarp/os/Contact.h>
11#include <yarp/os/PortReader.h>
12#include <yarp/os/PortReport.h>
13#include <yarp/os/PortWriter.h>
14
15#ifndef YARP_NO_DEPRECATED // Since YARP 3.3
16#define YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE
17# include <yarp/os/Mutex.h>
18#undef YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE
19#endif
20
21#include <mutex>
22
23// Forward declarations:
24namespace yarp::os {
25
26class Property;
27
34{
35
36public:
40 virtual ~Contactable();
41
52 virtual bool open(const std::string& name) = 0;
53
65 virtual bool open(const Contact& contact, bool registerName = true) = 0;
66
73 virtual bool addOutput(const std::string& name) = 0;
74
83 virtual bool addOutput(const std::string& name, const std::string& carrier) = 0;
84
92 virtual bool addOutput(const Contact& contact) = 0;
93
97 virtual void close() = 0;
98
106 virtual void interrupt() = 0;
107
112 virtual void resume() = 0;
113
119 virtual Contact where() const = 0;
120
126 virtual std::string getName() const;
127
128
145 virtual bool setEnvelope(PortWriter& envelope) = 0;
146
147
161 virtual bool getEnvelope(PortReader& envelope) = 0;
162
163
171 virtual int getInputCount() = 0;
172
178 virtual int getOutputCount() = 0;
179
189 virtual void getReport(PortReport& reporter) = 0;
190
191
200 virtual void setReporter(PortReport& reporter) = 0;
201
206 virtual void resetReporter() = 0;
207
213 virtual bool isWriting() = 0;
214
215
221 virtual void setReader(PortReader& reader) = 0;
222
228 virtual void setAdminReader(PortReader& reader) = 0;
229
237 virtual void setInputMode(bool expectInput) = 0;
238
246 virtual void setOutputMode(bool expectOutput) = 0;
247
255 virtual void setRpcMode(bool expectRpc) = 0;
256
264 virtual Type getType() = 0;
265
271 virtual void promiseType(const Type& typ) = 0;
272
281 virtual Property* acquireProperties(bool readOnly) = 0;
282
289 virtual void releaseProperties(Property* prop) = 0;
290
297 virtual void includeNodeInName(bool flag) = 0;
298
302 void setReadOnly();
303
307 void setWriteOnly();
308
312 void setRpcServer();
313
317 void setRpcClient();
318
319#ifndef YARP_NO_DEPRECATED // Since YARP 3.3
335 YARP_DEPRECATED_MSG("Use setCallbackLock with std::mutex instead")
336 virtual bool setCallbackLock(yarp::os::Mutex* mutex) = 0;
338#endif
339
351 virtual bool setCallbackLock(std::mutex* mutex = nullptr) = 0;
352
356 virtual bool removeCallbackLock() = 0;
357
366 virtual bool lockCallback() = 0;
367
377 virtual bool tryLockCallback() = 0;
378
382 virtual void unlockCallback() = 0;
383};
384
385} // namespace yarp::os
386
387#endif // YARP_OS_CONTACTABLE_H
Represents how to reach a part of a YARP network.
Definition: Contact.h:33
An abstract port.
Definition: Contactable.h:34
virtual bool tryLockCallback()=0
Try to lock callbacks until unlockCallback() is called.
virtual void close()=0
Stop port activity.
virtual void setAdminReader(PortReader &reader)=0
Set an external reader for unrecognized administrative port messages.
virtual void includeNodeInName(bool flag)=0
Choose whether to prepend a node name (if one is available) to the port's name.
virtual bool getEnvelope(PortReader &envelope)=0
Get the envelope information (e.g., a timestamp) from the last message received on the port.
virtual int getOutputCount()=0
Determine how many output connections this port has.
virtual bool setEnvelope(PortWriter &envelope)=0
Set an envelope (e.g., a timestamp) to the next message which will be sent.
virtual void releaseProperties(Property *prop)=0
End access unstructured port properties.
virtual bool lockCallback()=0
Lock callbacks until unlockCallback() is called.
virtual void setReporter(PortReport &reporter)=0
Set a callback to be called upon any future connections and disconnections to/from the port.
virtual int getInputCount()=0
Determine how many connections are arriving into this port.
virtual Type getType()=0
Get the type of data the port has committed to send/receive.
virtual void setReader(PortReader &reader)=0
Set an external reader for port data.
virtual Property * acquireProperties(bool readOnly)=0
Access unstructured port properties.
virtual void getReport(PortReport &reporter)=0
Get information on the state of the port - connections etc.
virtual Contact where() const =0
Returns information about how this port can be reached.
virtual bool setCallbackLock(std::mutex *mutex=nullptr)=0
Add a lock to use when invoking callbacks.
virtual void setInputMode(bool expectInput)=0
Configure the port to allow or forbid inputs.
virtual bool open(const std::string &name)=0
Start port operation, with a specific name, with automatically-chosen network parameters.
virtual void unlockCallback()=0
Unlock callbacks.
virtual void resetReporter()=0
Remove the callback which is called upon any future connections and disconnections to/from the port.
virtual void setOutputMode(bool expectOutput)=0
Configure the port to allow or forbid outputs.
virtual bool addOutput(const std::string &name)=0
Add an output connection to the specified port.
virtual void resume()=0
Put the port back in an operative state after interrupt() has been called.
virtual bool open(const Contact &contact, bool registerName=true)=0
Start port operation with user-chosen network parameters.
virtual void setRpcMode(bool expectRpc)=0
Configure the port to be RPC only.
virtual bool addOutput(const std::string &name, const std::string &carrier)=0
Add an output connection to the specified port, using a specified carrier.
virtual ~Contactable()
Destructor.
virtual bool isWriting()=0
Report whether the port is currently writing data.
virtual void promiseType(const Type &typ)=0
Commit the port to a particular type of data.
virtual void interrupt()=0
Interrupt any current reads or writes attached to the port.
virtual bool removeCallbackLock()=0
Remove a lock on callbacks added with setCallbackLock()
virtual bool addOutput(const Contact &contact)=0
Add an output connection to the specified port, using specified network parameters.
Basic wrapper for mutual exclusion.
Definition: Mutex.h:31
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:24
A base class for objects that want information about port status changes.
Definition: PortReport.h:25
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
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2895
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_WARNING_POP
Ends a temporary alteration of the enabled warnings.
Definition: system.h:334
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition: system.h:333
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition: system.h:335
#define YARP_os_API
Definition: api.h:18