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