YARP
Yet Another Robot Platform
Port.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_PORT_H
11 #define YARP_OS_PORT_H
12 
13 #include <yarp/os/api.h>
14 
15 #include <yarp/os/PortReader.h>
17 #include <yarp/os/PortWriter.h>
18 #include <yarp/os/Portable.h>
20 
21 
22 namespace yarp {
23 namespace os {
24 
50 {
51 
52 public:
59  Port();
60 
64  ~Port() override;
65 
66  // Documented in Contactable
67  bool open(const std::string& name) override;
68 
69  // Documented in Contactable
70  bool open(const Contact& contact, bool registerName = true) override;
71 
75  bool sharedOpen(Port& port);
76 
86  bool openFake(const std::string& name);
87 
88  // Documented in Contactable
89  bool addOutput(const std::string& name) override;
90 
91  // Documented in Contactable
92  bool addOutput(const std::string& name, const std::string& carrier) override;
93 
94  // Documented in Contactable
95  bool addOutput(const Contact& contact) override;
96 
97  // Documented in Contactable
98  void close() override;
99 
100  // Documented in Contactable
101  void interrupt() override;
102 
103  // Documented in Contactable
104  void resume() override;
105 
106  // Documented in Contactable
107  Contact where() const override;
108 
109  // Documented in UnbufferedContactable
110  bool write(const PortWriter& writer,
111  const PortWriter* callback = nullptr) const override;
112 
113  // Documented in UnbufferedContactable
114  bool write(const PortWriter& writer,
115  PortReader& reader,
116  const PortWriter* callback = nullptr) const override;
117 
118  // Documented in UnbufferedContactable
119  bool read(PortReader& reader, bool willReply = false) override;
120 
121  // Documented in UnbufferedContactable
122  bool reply(PortWriter& writer) override;
123 
124  // Documented in UnbufferedContactable
125  bool replyAndDrop(PortWriter& writer) override;
126 
127  // Documented in Contactable
128  void setReader(PortReader& reader) override;
129 
130  // Documented in Contactable
131  void setAdminReader(PortReader& reader) override;
132 
142  void setReaderCreator(PortReaderCreator& creator);
143 
150  void enableBackgroundWrite(bool backgroundFlag);
151 
152 
153  // Documented in Contactable
154  bool isWriting() override;
155 
156  // Documented in Contactable
157  bool setEnvelope(PortWriter& envelope) override;
158 
159  // Documented in Contactable
160  bool getEnvelope(PortReader& envelope) override;
161 
162  // Documented in Contactable
163  int getInputCount() override;
164 
165  // Documented in Contactable
166  int getOutputCount() override;
167 
168  // Documented in Contactable
169  void getReport(PortReport& reporter) override;
170 
171  // Documented in Contactable
172  void setReporter(PortReport& reporter) override;
173 
174  // Documented in Contactable
175  void resetReporter() override;
176 
186  void setAdminMode(bool adminMode = true);
187 
188  // Documented in Contactable
189  void setInputMode(bool expectInput) override;
190 
191  // Documented in Contactable
192  void setOutputMode(bool expectOutput) override;
193 
194  // Documented in Contactable
195  void setRpcMode(bool expectRpc) override;
196 
207  bool setTimeout(float timeout);
208 
209 #ifndef YARP_NO_DEPRECATED // Since YARP 3.4
210 
216  YARP_DEPRECATED_MSG("Use LogComponent instead")
217  void setVerbosity(int level);
218 
226  int getVerbosity();
227 #endif
228 
229  // Documented in Contactable
230  Type getType() override;
231 
232  // Documented in Contactable
233  void promiseType(const Type& typ) override;
234 
235  // Documented in Contactable
236  Property* acquireProperties(bool readOnly) override;
237 
238  // Documented in Contactable
239  void releaseProperties(Property* prop) override;
240 
241  // Documented in Contactable
242  void includeNodeInName(bool flag) override;
243 
247  bool isOpen() const;
248 
249 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3
252  // Documented in Contactable
253  YARP_DEPRECATED_MSG("Use setCallbackLock with std::mutex instead")
254  bool setCallbackLock(yarp::os::Mutex* mutex) override;
256 #endif
257 
258  // Documented in Contactable
259  bool setCallbackLock(std::mutex* mutex = nullptr) override;
260 
261  // Documented in Contactable
262  bool removeCallbackLock() override;
263 
264  // Documented in Contactable
265  bool lockCallback() override;
266 
267  // Documented in Contactable
268  bool tryLockCallback() override;
269 
270  // Documented in Contactable
271  void unlockCallback() override;
272 
273 private:
274  void* implementation;
275  bool owned;
276 
277  void* needImplementation() const;
278 
279  bool open(const Contact& contact,
280  bool registerName,
281  const char* fakeName);
282 };
283 
284 } // namespace os
285 } // namespace yarp
286 
287 #endif // YARP_OS_PORT_H
YARP_WARNING_PUSH
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition: system.h:334
yarp::sig::file::read
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:827
yarp::os::Type
Definition: Type.h:24
yarp::os::UnbufferedContactable
An abstract unbuffered port.
Definition: UnbufferedContactable.h:22
Portable.h
YARP_DEPRECATED
#define YARP_DEPRECATED
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2882
api.h
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::PortWriter
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:27
PortWriter.h
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
PortReaderCreator.h
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::PortReaderCreator
A creator for readers.
Definition: PortReaderCreator.h:34
UnbufferedContactable.h
YARP_WARNING_POP
#define YARP_WARNING_POP
Ends a temporary alteration of the enabled warnings.
Definition: system.h:335
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
PortReader.h
implementation
RandScalar * implementation(void *t)
Definition: RandnScalar.cpp:20
yarp::os::Mutex
Basic wrapper for mutual exclusion.
Definition: Mutex.h:35
yarp::sig::file::write
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:971
YARP_DISABLE_DEPRECATED_WARNING
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition: system.h:336
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37