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
YARP_WARNING_PUSH
#define YARP_WARNING_PUSH
Starts a temporary alteration of the enabled warnings.
Definition: system.h:334
yarp::os::impl::PortCoreAdapter::commitToRpc
bool commitToRpc
Definition: PortCoreAdapter.h:60
yarp::os::impl::PortCoreAdapter::setWriteOnly
void setWriteOnly()
Definition: PortCoreAdapter.cpp:53
yarp::os::impl::PortCoreAdapter::PortCoreAdapter
PortCoreAdapter(Port &owner)
Definition: PortCoreAdapter.cpp:20
yarp::os::impl::PortCoreAdapter::openable
void openable()
Definition: PortCoreAdapter.cpp:25
yarp::os::Semaphore
A class for thread synchronization and mutual exclusion.
Definition: Semaphore.h:29
yarp::os::impl::PortCoreAdapter::configAdminReader
void configAdminReader(PortReader &reader)
Definition: PortCoreAdapter.cpp:247
yarp::os::impl::PortCoreAdapter::recCallbackLock
std::mutex * recCallbackLock
Definition: PortCoreAdapter.h:62
yarp::os::impl::PortCoreAdapter
Definition: PortCoreAdapter.h:31
Port.h
yarp::os::impl::PortCoreAdapter::checkReadCreator
PortReaderCreator * checkReadCreator()
Definition: PortCoreAdapter.cpp:313
YARP_DEPRECATED
#define YARP_DEPRECATED
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2882
yarp::os::impl::PortCoreAdapter::configReadCreator
void configReadCreator(PortReaderCreator &creator)
Definition: PortCoreAdapter.cpp:255
yarp::os::impl::PortCoreAdapter::setOpen
void setOpen(bool opened)
Definition: PortCoreAdapter.cpp:329
yarp::os::impl::PortCoreAdapter::finishWriting
void finishWriting()
Definition: PortCoreAdapter.cpp:74
yarp::os::impl::PortCore
Definition: PortCore.h:155
yarp::os::PortWriter
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:27
yarp::os::impl::PortCoreAdapter::isOpened
bool isOpened()
Definition: PortCoreAdapter.cpp:324
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::impl::PortCoreAdapter::alertOnWrite
void alertOnWrite()
Definition: PortCoreAdapter.cpp:38
yarp::os::impl::PortCoreAdapter::alertOnRpc
void alertOnRpc()
Definition: PortCoreAdapter.cpp:43
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::impl::PortCoreAdapter::alertOnRead
void alertOnRead()
Definition: PortCoreAdapter.cpp:33
yarp::os::PortReaderCreator
A creator for readers.
Definition: PortReaderCreator.h:34
yarp::os::impl::PortCoreAdapter::old_recCallbackLock
yarp::os::Mutex * old_recCallbackLock
Definition: PortCoreAdapter.h:66
yarp::os::impl::PortCoreAdapter::setReadOnly
void setReadOnly()
Definition: PortCoreAdapter.cpp:48
yarp::os::impl::PortCoreAdapter::finishReading
void finishReading()
Definition: PortCoreAdapter.cpp:63
yarp::os::impl::PortCoreAdapter::checkWaitAfterSend
int checkWaitAfterSend()
Definition: PortCoreAdapter.cpp:318
Semaphore.h
yarp::os::impl::PortCoreAdapter::read
bool read(ConnectionReader &reader) override
Callback for data.
Definition: PortCoreAdapter.cpp:100
YARP_WARNING_POP
#define YARP_WARNING_POP
Ends a temporary alteration of the enabled warnings.
Definition: system.h:335
yarp::os::impl::PortCoreAdapter::resumeFull
void resumeFull()
Definition: PortCoreAdapter.cpp:90
yarp::os::impl::PortCoreAdapter::unconfigCallbackLock
bool unconfigCallbackLock()
Definition: PortCoreAdapter.cpp:293
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::impl::PortCoreAdapter::includeNodeInName
void includeNodeInName(bool flag)
Definition: PortCoreAdapter.cpp:334
Mutex.h
yarp::os::impl::PortCoreAdapter::checkAdminPortReader
PortReader * checkAdminPortReader()
Definition: PortCoreAdapter.cpp:308
yarp::os::impl::PortCoreAdapter::commitToWrite
bool commitToWrite
Definition: PortCoreAdapter.h:59
PortCore.h
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::impl::PortCoreAdapter::active
bool active
Definition: PortCoreAdapter.h:61
yarp::os::Mutex
Basic wrapper for mutual exclusion.
Definition: Mutex.h:35
yarp::os::impl::PortCoreAdapter::setRpc
void setRpc()
Definition: PortCoreAdapter.cpp:58
yarp::os::impl::PortCoreAdapter::checkPortReader
PortReader * checkPortReader()
Definition: PortCoreAdapter.cpp:303
yarp::os::impl::PortCoreAdapter::commitToRead
bool commitToRead
Definition: PortCoreAdapter.h:58
yarp::os::impl::PortCoreAdapter::configCallbackLock
bool configCallbackLock(Mutex *lock)
Definition: PortCoreAdapter.cpp:273
yarp::os::impl::PortCoreAdapter::includeNode
bool includeNode
Definition: PortCoreAdapter.h:57
YARP_DISABLE_DEPRECATED_WARNING
#define YARP_DISABLE_DEPRECATED_WARNING
Disable deprecated warnings in the following code.
Definition: system.h:336
yarp::os::impl::PortCoreAdapter::configWaitAfterSend
void configWaitAfterSend(bool waitAfterSend)
Definition: PortCoreAdapter.cpp:261
yarp::os::impl::PortCoreAdapter::configReader
void configReader(PortReader &reader)
Definition: PortCoreAdapter.cpp:235
yarp::os::impl::PortCoreAdapter::haveCallbackLock
bool haveCallbackLock
Definition: PortCoreAdapter.h:69
yarp::os::impl::PortCoreAdapter::reply
bool reply(PortWriter &writer, bool drop, bool interrupted)
Definition: PortCoreAdapter.cpp:214