YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ReturnValue.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
9#include <yarp/os/Bottle.h>
10#include <yarp/os/NetInt32.h>
11
12using namespace yarp::dev;
13using namespace yarp::os;
14
25
29
30#if !YARP_RETURNVALUE_DISABLE_BOOL_INPUT
31ReturnValue::ReturnValue(const bool& val)
32{
33 if (val)
34 {
36 }
37 else
38 {
40 }
41}
42#endif
43
45{
46 // THIS IS THE IMPLEMENTATION RULE:
47 // OP1 OP2 RESULT
48 // 1) True True True
49 // 2) FalseType1 FalseType1 FalseType1
50 // 3) FalseType1 FalseType2 FalseGeneric
51 // 4) True FalseType1 FalseGeneric
52 // 5) FalseType1 True FalseGeneric
53
54 if (this->value_b == other.value_b)
55 {
56 //cases 1 and 2
57 return *this;
58 }
59
61 return *this;
62}
63
65{
66 // THIS IS THE IMPLEMENTATION RULE:
67 // OP1 OP2 RESULT
68 // 1) True True True
69 // 2) FalseType1 FalseType1 FalseType1
70 // 3) FalseType1 FalseType2 FalseGeneric
71 // 4) True FalseType1 FalseGeneric
72 // 5) FalseType1 True FalseGeneric
73
74 if (this->value_b == other.value_b)
75 {
76 //cases 1 and 2
77 return *this;
78 }
79
81 return *this;
82}
83
84#if !YARP_RETURNVALUE_DISABLE_BOOL_INPUT
85ReturnValue& ReturnValue::operator=(const bool& bool_val)
86{
87 if (bool_val)
88 {
90 }
91 else
92 {
94 }
95 return *this;
96}
97#endif
98
100{
101 switch (value_b)
102 {
104 return std::string("ok");
106 return std::string("return_value_error_deprecated");
108 return std::string("return_value_error_generic");
110 return std::string("return_value_error_method_fail");
112 return std::string("return_value_error_not_implemented_by_device");
114 return std::string("return_value_error_nws_nwc_communication_error");
116 return std::string("return_value_error_not_ready");
117 default:
119 return std::string("unknown/uninitialized");
120 }
121}
122
123ReturnValue::operator bool() const
124{
125 return value_b == return_code::return_value_ok;
126}
127
129{
130 value_b = code;
131}
132
134{
135 if (code == this->value_b) return true;
136 return false;
137}
138
140{
141 if (value == this->value_b) return true;
142 return false;
143}
144
146{
147 connection.convertTextMode();
148 ReturnValueHeader header;
149 bool ok = connection.expectBlock((char*)&header, sizeof(header));
150 if (!ok) {
151 return false;
152 }
153 this->value_b = (ReturnValue::return_code)(header.data);
154 return true;
155}
156
158{
159 ReturnValueHeader header;
160 header.dataTag = BOTTLE_TAG_INT32;
161 header.data = (int32_t)(this->value_b);
162 connection.appendBlock((char*)&header, sizeof(header));
163 connection.convertTextMode();
164 return true;
165}
#define BOTTLE_TAG_INT32
Definition Bottle.h:21
yarp::os::NetInt32 data
ReturnValueHeader()=default
yarp::os::NetInt32 dataTag
bool operator==(const return_code &code) const
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
ReturnValue & operator&&(const ReturnValue &other)
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
ReturnValue & operator&=(const ReturnValue &other)
@ return_value_error_nws_nwc_communication_error
Method is not (yet) implemented.
@ return_value_error_deprecated
Command answer lost during network transmission. Status unknown.
@ return_value_error_generic
Method was successfully executed.
@ return_value_uninitialized
Method failed because some initialization is missing.
@ return_value_error_not_ready
Method failed due to invalid internal status/invalid request.
@ return_value_error_method_failed
Method is deprecated.
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
An interface for writing to a network connection.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
std::int32_t NetInt32
Definition of the NetInt32 type.
Definition NetInt32.h:29
#define YARP_END_PACK
Ends 1 byte packing for structs/classes.
Definition system.h:193
#define YARP_BEGIN_PACK
Starts 1 byte packing for structs/classes.
Definition system.h:192