YARP
Yet Another Robot Platform
Port.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_PORT_H
8 #define YARP_OS_PORT_H
9 
10 #include <yarp/os/api.h>
11 
12 #include <yarp/os/PortReader.h>
14 #include <yarp/os/PortWriter.h>
15 #include <yarp/os/Portable.h>
17 
18 
19 namespace yarp::os {
20 
46 {
47 
48 public:
55  Port();
56 
60  ~Port() override;
61 
62  // Documented in Contactable
63  bool open(const std::string& name) override;
64 
65  // Documented in Contactable
66  bool open(const Contact& contact, bool registerName = true) override;
67 
71  bool sharedOpen(Port& port);
72 
82  bool openFake(const std::string& name);
83 
84  // Documented in Contactable
85  bool addOutput(const std::string& name) override;
86 
87  // Documented in Contactable
88  bool addOutput(const std::string& name, const std::string& carrier) override;
89 
90  // Documented in Contactable
91  bool addOutput(const Contact& contact) override;
92 
93  // Documented in Contactable
94  void close() override;
95 
96  // Documented in Contactable
97  void interrupt() override;
98 
99  // Documented in Contactable
100  void resume() override;
101 
102  // Documented in Contactable
103  Contact where() const override;
104 
105  // Documented in UnbufferedContactable
106  bool write(const PortWriter& writer,
107  const PortWriter* callback = nullptr) const override;
108 
109  // Documented in UnbufferedContactable
110  bool write(const PortWriter& writer,
111  PortReader& reader,
112  const PortWriter* callback = nullptr) const override;
113 
114  // Documented in UnbufferedContactable
115  bool read(PortReader& reader, bool willReply = false) override;
116 
117  // Documented in UnbufferedContactable
118  bool reply(PortWriter& writer) override;
119 
120  // Documented in UnbufferedContactable
121  bool replyAndDrop(PortWriter& writer) override;
122 
123  // Documented in Contactable
124  void setReader(PortReader& reader) override;
125 
126  // Documented in Contactable
127  void setAdminReader(PortReader& reader) override;
128 
138  void setReaderCreator(PortReaderCreator& creator);
139 
146  void enableBackgroundWrite(bool backgroundFlag);
147 
148 
149  // Documented in Contactable
150  bool isWriting() override;
151 
152  // Documented in Contactable
153  bool setEnvelope(PortWriter& envelope) override;
154 
155  // Documented in Contactable
156  bool getEnvelope(PortReader& envelope) override;
157 
158  // Documented in Contactable
159  int getInputCount() override;
160 
161  // Documented in Contactable
162  int getOutputCount() override;
163 
164  // Documented in Contactable
165  void getReport(PortReport& reporter) override;
166 
167  // Documented in Contactable
168  void setReporter(PortReport& reporter) override;
169 
170  // Documented in Contactable
171  void resetReporter() override;
172 
182  void setAdminMode(bool adminMode = true);
183 
184  // Documented in Contactable
185  void setInputMode(bool expectInput) override;
186 
187  // Documented in Contactable
188  void setOutputMode(bool expectOutput) override;
189 
190  // Documented in Contactable
191  void setRpcMode(bool expectRpc) override;
192 
203  bool setTimeout(float timeout);
204 
205 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
212  YARP_DEPRECATED_MSG("Use LogComponent instead")
213  void setVerbosity(int level);
214 
222  int getVerbosity();
223 #endif
224 
225  // Documented in Contactable
226  Type getType() override;
227 
228  // Documented in Contactable
229  void promiseType(const Type& typ) override;
230 
231  // Documented in Contactable
232  Property* acquireProperties(bool readOnly) override;
233 
234  // Documented in Contactable
235  void releaseProperties(Property* prop) override;
236 
237  // Documented in Contactable
238  void includeNodeInName(bool flag) override;
239 
243  bool isOpen() const;
244 
245 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3
248  // Documented in Contactable
249  YARP_DEPRECATED_MSG("Use setCallbackLock with std::mutex instead")
250  bool setCallbackLock(yarp::os::Mutex* mutex) override;
252 #endif
253 
254  // Documented in Contactable
255  bool setCallbackLock(std::mutex* mutex = nullptr) override;
256 
257  // Documented in Contactable
258  bool removeCallbackLock() override;
259 
260  // Documented in Contactable
261  bool lockCallback() override;
262 
263  // Documented in Contactable
264  bool tryLockCallback() override;
265 
266  // Documented in Contactable
267  void unlockCallback() override;
268 
269 private:
270  void* implementation;
271  bool owned;
272 
273  void* needImplementation() const;
274 
275  bool open(const Contact& contact,
276  bool registerName,
277  const char* fakeName);
278 };
279 
280 } // namespace yarp::os
281 
282 #endif // YARP_OS_PORT_H
RandScalar * implementation(void *t)
Definition: RandnScalar.cpp:17
Represents how to reach a part of a YARP network.
Definition: Contact.h:33
Basic wrapper for mutual exclusion.
Definition: Mutex.h:31
A creator for readers.
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 mini-server for network communication.
Definition: Port.h:46
A class for storing options and configuration information.
Definition: Property.h:33
An abstract unbuffered port.
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2885
#define YARP_DEPRECATED
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2884
An interface to the operating system, including Port based communication.
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:915
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:1091
#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