YARP
Yet Another Robot Platform
PortCoreAdapter.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_IMPL_PORTCOREADAPTER_H
8 #define YARP_OS_IMPL_PORTCOREADAPTER_H
9 
10 #include <yarp/os/Port.h>
11 #include <yarp/os/Semaphore.h>
12 #include <yarp/os/impl/PortCore.h>
13 
14 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3
15 #define YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE
16 #include <yarp/os/Mutex.h>
17 #undef YARP_INCLUDING_DEPRECATED_HEADER_ON_PURPOSE
18 #endif // YARP_NO_DEPRECATED
19 
20 #include <mutex>
21 
22 namespace yarp {
23 namespace os {
24 namespace impl {
25 
27  public PortCore
28 {
29 private:
30  std::mutex stateMutex;
31  PortReader* readDelegate { nullptr };
32  PortReader* permanentReadDelegate { nullptr };
33  PortReader* adminReadDelegate { nullptr };
34  PortWriter* writeDelegate { nullptr };
35  //PortReaderCreator *readCreatorDelegate { nullptr };
36  bool readResult { false };
37  bool readActive { false };
38  bool readBackground { false };
39  bool willReply { false };
40  bool closed { false };
41  bool opened { false };
42  bool replyDue { false };
43  bool dropDue { false };
44  yarp::os::Semaphore produce { 0 };
45  yarp::os::Semaphore consume { 0 };
46  yarp::os::Semaphore readBlock { 1 };
47  PortReaderCreator* recReadCreator { nullptr };
48  int recWaitAfterSend { -1 };
49  bool usedForRead { false };
50  bool usedForWrite { false };
51  bool usedForRpc { false };
52 
53 public:
54  bool includeNode { false };
55  bool commitToRead { false };
56  bool commitToWrite { false };
57  bool commitToRpc { false };
58  bool active { false };
59  std::mutex* recCallbackLock { nullptr };
60 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3
65 #endif
66  bool haveCallbackLock { false };
67 
68  PortCoreAdapter(Port& owner);
69  void openable();
70  void alertOnRead();
71  void alertOnWrite();
72  void alertOnRpc();
73  void setReadOnly();
74  void setWriteOnly();
75  void setRpc();
76  void finishReading();
77  void finishWriting();
78  void resumeFull();
79  bool read(ConnectionReader& reader) override;
80  bool read(PortReader& reader, bool willReply = false);
81  bool reply(PortWriter& writer, bool drop, bool interrupted);
82  void configReader(PortReader& reader);
83  void configAdminReader(PortReader& reader);
84  void configReadCreator(PortReaderCreator& creator);
85  void configWaitAfterSend(bool waitAfterSend);
86 #ifndef YARP_NO_DEPRECATED // Since YARP 3.3
90  bool configCallbackLock(Mutex* lock);
92 #endif
93  bool configCallbackLock(std::mutex* lock);
94  bool unconfigCallbackLock();
98  int checkWaitAfterSend();
99  bool isOpened();
100  void setOpen(bool opened);
101  void includeNodeInName(bool flag);
102 };
103 
104 } // namespace impl
105 } // namespace os
106 } // namespace yarp
107 
108 #endif // YARP_OS_IMPL_PORTCOREADAPTER_H
An interface for reading from a network connection.
Basic wrapper for mutual exclusion.
Definition: Mutex.h:32
A creator for readers.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
A mini-server for network communication.
Definition: Port.h:47
A class for thread synchronization and mutual exclusion.
Definition: Semaphore.h:26
PortReaderCreator * checkReadCreator()
void configWaitAfterSend(bool waitAfterSend)
void configReadCreator(PortReaderCreator &creator)
void configAdminReader(PortReader &reader)
bool reply(PortWriter &writer, bool drop, bool interrupted)
yarp::os::Mutex * old_recCallbackLock
void configReader(PortReader &reader)
bool read(ConnectionReader &reader) override
Callback for data.
#define YARP_DEPRECATED
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2884
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