YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Things.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_OS_THINGS_H
7#define YARP_OS_THINGS_H
8
10#include <yarp/os/Portable.h>
11
12namespace yarp::os {
13
18{
19public:
20 Things();
21
22 virtual ~Things();
23
27 void setPortWriter(yarp::os::PortWriter* writer);
28
29 yarp::os::PortWriter* getPortWriter();
30
34 void setPortReader(yarp::os::PortReader* reader);
35
36 yarp::os::PortReader* getPortReader();
37
41 bool setConnectionReader(yarp::os::ConnectionReader& reader);
42
43 /*
44 * Things writer
45 */
47
48 void reset();
49
50 bool hasBeenRead();
51
52 template <typename T>
54 {
55 if (this->writer) {
56 return dynamic_cast<T*>(this->writer);
57 }
58 if (this->reader) {
59 return dynamic_cast<T*>(this->reader);
60 }
61 if (!this->portable) {
62 if (!this->conReader) {
63 return nullptr;
64 }
65 this->portable = new T();
66 if (!this->portable->read(*this->conReader)) {
67 delete this->portable;
68 this->portable = nullptr;
69 return nullptr;
70 }
71 beenRead = true;
72 }
73 return dynamic_cast<T*>(this->portable);
74 }
75
76private:
77 bool beenRead;
81 yarp::os::Portable* portable;
82};
83
84} // namespace yarp::os
85
86#endif // YARP_OS_THINGS_H
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An interface for writing to a network connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition PortWriter.h:23
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
Base class for generic things.
Definition Things.h:18
T * cast_as()
Definition Things.h:53
An interface to the operating system, including Port based communication.
#define YARP_os_API
Definition api.h:18