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:
24 namespace yarp {
25 namespace os {
26 
27 class Property;
28 
35 {
36 
37 public:
41  virtual ~Contactable();
42 
53  virtual bool open(const std::string& name) = 0;
54 
66  virtual bool open(const Contact& contact, bool registerName = true) = 0;
67 
74  virtual bool addOutput(const std::string& name) = 0;
75 
84  virtual bool addOutput(const std::string& name, const std::string& carrier) = 0;
85 
93  virtual bool addOutput(const Contact& contact) = 0;
94 
98  virtual void close() = 0;
99 
107  virtual void interrupt() = 0;
108 
113  virtual void resume() = 0;
114 
120  virtual Contact where() const = 0;
121 
127  virtual std::string getName() const;
128 
129 
146  virtual bool setEnvelope(PortWriter& envelope) = 0;
147 
148 
162  virtual bool getEnvelope(PortReader& envelope) = 0;
163 
164 
172  virtual int getInputCount() = 0;
173 
179  virtual int getOutputCount() = 0;
180 
190  virtual void getReport(PortReport& reporter) = 0;
191 
192 
201  virtual void setReporter(PortReport& reporter) = 0;
202 
207  virtual void resetReporter() = 0;
208 
214  virtual bool isWriting() = 0;
215 
216 
222  virtual void setReader(PortReader& reader) = 0;
223 
229  virtual void setAdminReader(PortReader& reader) = 0;
230 
238  virtual void setInputMode(bool expectInput) = 0;
239 
247  virtual void setOutputMode(bool expectOutput) = 0;
248 
256  virtual void setRpcMode(bool expectRpc) = 0;
257 
265  virtual Type getType() = 0;
266 
272  virtual void promiseType(const Type& typ) = 0;
273 
282  virtual Property* acquireProperties(bool readOnly) = 0;
283 
290  virtual void releaseProperties(Property* prop) = 0;
291 
298  virtual void includeNodeInName(bool flag) = 0;
299 
303  void setReadOnly();
304 
308  void setWriteOnly();
309 
313  void setRpcServer();
314 
318  void setRpcClient();
319 
320 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3
336  YARP_DEPRECATED_MSG("Use setCallbackLock with std::mutex instead")
337  virtual bool setCallbackLock(yarp::os::Mutex* mutex) = 0;
339 #endif
340 
352  virtual bool setCallbackLock(std::mutex* mutex = nullptr) = 0;
353 
357  virtual bool removeCallbackLock() = 0;
358 
367  virtual bool lockCallback() = 0;
368 
378  virtual bool tryLockCallback() = 0;
379 
383  virtual void unlockCallback() = 0;
384 };
385 
386 } // namespace os
387 } // namespace yarp
388 
389 #endif // YARP_OS_CONTACTABLE_H
Represents how to reach a part of a YARP network.
Definition: Contact.h:36
An abstract port.
Definition: Contactable.h:35
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 Property * acquireProperties(bool readOnly)=0
Access unstructured port properties.
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 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:32
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
A base class for objects that want information about port status changes.
Definition: PortReport.h:28
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
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2885
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:332
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition: system.h:331
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition: system.h:333
#define YARP_os_API
Definition: api.h:18