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 
284  virtual Property* acquireProperties(bool readOnly) = 0;
285 
291  virtual void releaseProperties(Property* prop) = 0;
292 
299  virtual void includeNodeInName(bool flag) = 0;
300 
304  void setReadOnly();
305 
309  void setWriteOnly();
310 
314  void setRpcServer();
315 
319  void setRpcClient();
320 
321 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3
337  YARP_DEPRECATED_MSG("Use setCallbackLock with std::mutex instead")
338  virtual bool setCallbackLock(yarp::os::Mutex* mutex) = 0;
340 #endif
341 
353  virtual bool setCallbackLock(std::mutex* mutex = nullptr) = 0;
354 
358  virtual bool removeCallbackLock() = 0;
359 
368  virtual bool lockCallback() = 0;
369 
379  virtual bool tryLockCallback() = 0;
380 
384  virtual void unlockCallback() = 0;
385 };
386 
387 } // namespace os
388 } // namespace yarp
389 
390 #endif // YARP_OS_CONTACTABLE_H
Represents how to reach a part of a YARP network.
Definition: Contact.h:39
An abstract port.
Definition: Contactable.h:38
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:35
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
A base class for objects that want information about port status changes.
Definition: PortReport.h:31
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:27
A class for storing options and configuration information.
Definition: Property.h:37
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2883
The main, catch-all namespace for YARP.
Definition: environment.h:18
#define YARP_WARNING_POP
Ends a temporary alteration of the enabled warnings.
Definition: system.h:335
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition: system.h:334
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition: system.h:336
#define YARP_os_API
Definition: api.h:19