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
27
31
32#if !YARP_RETURNVALUE_DISABLE_BOOL_INPUT
33ReturnValue::ReturnValue(const bool& val)
34{
35 if (val)
36 {
38 }
39 else
40 {
42 }
43}
44#endif
45
47{
48 // THIS IS THE IMPLEMENTATION RULE:
49 // OP1 OP2 RESULT
50 // 1) True True True
51 // 2) FalseType1 FalseType1 FalseType1
52 // 3) FalseType1 FalseType2 FalseGeneric
53 // 4) True FalseType1 FalseGeneric
54 // 5) FalseType1 True FalseGeneric
55
56 if (this->value_b == other.value_b)
57 {
58 //cases 1 and 2
59 return *this;
60 }
61
63 return *this;
64}
65
67{
68 // THIS IS THE IMPLEMENTATION RULE:
69 // OP1 OP2 RESULT
70 // 1) True True True
71 // 2) FalseType1 FalseType1 FalseType1
72 // 3) FalseType1 FalseType2 FalseGeneric
73 // 4) True FalseType1 FalseGeneric
74 // 5) FalseType1 True FalseGeneric
75
76 if (this->value_b == other.value_b)
77 {
78 //cases 1 and 2
79 return *this;
80 }
81
83 return *this;
84}
85
86#if !YARP_RETURNVALUE_DISABLE_BOOL_INPUT
87ReturnValue& ReturnValue::operator=(const bool& bool_val)
88{
89 if (bool_val)
90 {
92 }
93 else
94 {
96 }
97 return *this;
98}
99#endif
100
102{
103 switch (value_b)
104 {
106 return std::string("ok");
108 return std::string("return_value_error_deprecated");
110 return std::string("return_value_error_generic");
112 return std::string("return_value_error_method_fail");
114 return std::string("return_value_error_not_implemented_by_device");
116 return std::string("return_value_error_nws_nwc_communication_error");
118 return std::string("return_value_error_not_ready");
119 default:
121 return std::string("unknown/uninitialized");
122 }
123}
124
125ReturnValue::operator bool() const
126{
127 return value_b == return_code::return_value_ok;
128}
129
131{
132 value_b = code;
133}
134
136{
137 if (code == this->value_b) return true;
138 return false;
139}
140
142{
143 if (value == this->value_b) return true;
144 return false;
145}
146
148{
149 connection.convertTextMode();
150 ReturnValueHeader header;
151
152 bool ok = connection.expectBlock((char*)&header, sizeof(header));
153 if (!ok) {
154 return false;
155 }
156 this->value_b = (ReturnValue::return_code)(header.data);
157 return true;
158}
159
161{
162 ReturnValueHeader header;
164 header.outerListLen = 1;
166 header.data = (int32_t)(this->value_b);
167 connection.appendBlock((char*)&header, sizeof(header));
168 connection.convertTextMode();
169 return true;
170}
#define BOTTLE_TAG_LIST
Definition Bottle.h:29
#define BOTTLE_TAG_VOCAB32
Definition Bottle.h:23
yarp::os::NetInt32 data
ReturnValueHeader()=default
yarp::os::NetInt32 outerListLen
yarp::os::NetInt32 dataTag
yarp::os::NetInt32 outerListTag
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