Skip to content

Commit e143c3b

Browse files
Remove @feed operations from example (#256)
* Refs #23701. Remove feed operations from example. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23703. Apply suggestion. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> --------- Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 57a5541 commit e143c3b

16 files changed

Lines changed: 207 additions & 6432 deletions

fastdds_python_examples/RPCExample/CalculatorExample.py

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -50,38 +50,6 @@ def representation_limits(self, info):
5050
ret_val.max_value = 2147483647
5151
return ret_val
5252

53-
def fibonacci_seq(self, info, n_results, result_writer):
54-
self.operation_call_print(info, "fibonacci_seq")
55-
a = 1
56-
b = 1
57-
c = 0
58-
59-
while n_results > 0:
60-
n_results = n_results - 1
61-
62-
result_writer.write(a)
63-
c = a + b
64-
a = b
65-
b = c
66-
67-
def sum_all(self, info, value):
68-
self.operation_call_print(info, "sum_all")
69-
ret = 0
70-
has_value, n = value.read()
71-
while has_value:
72-
ret = ret + n
73-
has_value, n = value.read()
74-
return ret
75-
76-
def accumulator(self, info, value, result_writer):
77-
self.operation_call_print(info, "accumulator")
78-
ret = 0
79-
has_value, n = value.read()
80-
while has_value:
81-
ret = ret + n
82-
result_writer.write(ret)
83-
has_value, n = value.read()
84-
8553
### Server application ###
8654

8755
def run_server(server):
@@ -134,9 +102,6 @@ def run(self):
134102
self.perform_addition()
135103
self.perform_subtraction()
136104
self.perform_representation_limits()
137-
self.perform_fibonacci_seq()
138-
self.perform_sum_all()
139-
self.perform_accumulator()
140105

141106
def perform_addition(self):
142107
try:
@@ -180,51 +145,6 @@ def perform_representation_limits(self):
180145
print("Exception: {}".format(type(e).__name__))
181146
print("Exception message: {}".format(e))
182147

183-
def perform_fibonacci_seq(self):
184-
try:
185-
print("Performing fibonacci_seq(10)")
186-
result = self.client.fibonacci_seq(10)
187-
has_value, n = result.read()
188-
while has_value:
189-
print("Result: {}".format(n))
190-
has_value, n = result.read()
191-
except Exception as e:
192-
print("Exception: {}".format(type(e).__name__))
193-
print("Exception message: {}".format(e))
194-
195-
def perform_sum_all(self):
196-
try:
197-
print("Performing sum_all([1, 2, 3, 4, 5])")
198-
result, value = self.client.sum_all()
199-
value.write(1)
200-
value.write(2)
201-
value.write(3)
202-
value.write(4)
203-
value.write(5)
204-
value.finish()
205-
print("Result: {}".format(result.get()))
206-
except Exception as e:
207-
print("Exception: {}".format(type(e).__name__))
208-
print("Exception message: {}".format(e))
209-
210-
def perform_accumulator(self):
211-
try:
212-
print("Performing accumulator([1, 2, 3, 4, 5])")
213-
result, value = self.client.accumulator()
214-
value.write(1)
215-
value.write(2)
216-
value.write(3)
217-
value.write(4)
218-
value.write(5)
219-
value.finish()
220-
has_value, n = result.read()
221-
while has_value:
222-
print("Result: {}".format(n))
223-
has_value, n = result.read()
224-
except Exception as e:
225-
print("Exception: {}".format(type(e).__name__))
226-
print("Exception message: {}".format(e))
227-
228148
def parse_options():
229149
""""
230150
Parse arguments.

fastdds_python_examples/RPCExample/calculator.idl

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,10 @@ module calculator_base
3232
// Returns the result of value1 - value2
3333
long subtraction(in long value1, in long value2) raises(OverflowException);
3434
};
35-
36-
interface BasicCalculator : Adder, Subtractor
37-
{
38-
// Returns the minimum and maximum representable values
39-
void representation_limits(out long min_value, out long max_value);
40-
};
4135
};
4236

43-
interface Calculator : calculator_base::BasicCalculator
37+
interface Calculator : calculator_base::Adder, calculator_base::Subtractor
4438
{
45-
// Returns a feed of results with the n_results first elements of the Fibonacci sequence
46-
// E.g. for an input of 5, returns a feed with {1, 1, 2, 3, 5}
47-
@feed long fibonacci_seq(in unsigned long n_results) raises (calculator_base::OverflowException);
48-
49-
// Waits for an input feed to finish and returns the sum of all the received values
50-
// E.g. for an input of {1, 2, 3, 4, 5} returns 15
51-
long sum_all(@feed in long value) raises (calculator_base::OverflowException);
52-
53-
// Returns a feed of results with the sum of all received values
54-
// E.g. for an input of {1, 2, 3, 4, 5}, returns a feed with {1, 3, 6, 10, 15}
55-
@feed long accumulator(@feed in long value) raises (calculator_base::OverflowException);
39+
// Returns the minimum and maximum representable values
40+
void representation_limits(out long min_value, out long max_value);
5641
};

fastdds_python_examples/RPCExample/generated_code/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ find_package(fastdds 3 REQUIRED)
4141

4242
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
4343

44-
if(NOT WIN32)
45-
# Default values for shared library suffix in MacOS
46-
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
47-
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
48-
endif()
49-
endif()
50-
5144
#Create library for C++ types
5245
add_library(${PROJECT_NAME} SHARED
5346
calculatorTypeObjectSupport.cxx

fastdds_python_examples/RPCExample/generated_code/calculator.hpp

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@
2323
#define FAST_DDS_GENERATED__CALCULATOR_HPP
2424

2525
#include <cstdint>
26-
#include <memory>
2726
#include <string>
2827
#include <utility>
2928
#include <fastcdr/cdr/fixed_size_string.hpp>
3029
#include <fastcdr/xcdr/optional.hpp>
3130
#include <fastdds/dds/rpc/exceptions/RpcOperationError.hpp>
32-
#include <fastdds/dds/rpc/interfaces/RpcClientReader.hpp>
33-
#include <fastdds/dds/rpc/interfaces/RpcClientWriter.hpp>
3431
#include <fastdds/dds/rpc/interfaces/RpcFuture.hpp>
3532

3633

@@ -155,30 +152,32 @@ class eProsima_user_DllExport Subtractor
155152

156153

157154

155+
} // namespace calculator_base
156+
158157
namespace detail {
159158

160-
struct BasicCalculator_representation_limits_Out;
159+
struct Calculator_representation_limits_Out;
161160

162161
} // namespace detail
163162

164163
/*!
165-
* @brief This class represents the interface BasicCalculator defined by the user in the IDL file.
164+
* @brief This class represents the interface Calculator defined by the user in the IDL file.
166165
* @ingroup calculator
167166
*/
168-
class eProsima_user_DllExport BasicCalculator : public calculator_base::Adder, public calculator_base::Subtractor
167+
class eProsima_user_DllExport Calculator : public calculator_base::Adder, public calculator_base::Subtractor
169168
{
170169
public:
171-
virtual ~BasicCalculator() = default;
170+
virtual ~Calculator() = default;
172171

173172

174-
virtual eprosima::fastdds::dds::rpc::RpcFuture<calculator_base::detail::BasicCalculator_representation_limits_Out> representation_limits(
173+
virtual eprosima::fastdds::dds::rpc::RpcFuture<detail::Calculator_representation_limits_Out> representation_limits(
175174
) = 0;
176175

177176
};
178177

179178
namespace detail {
180179

181-
struct BasicCalculator_representation_limits_Out
180+
struct Calculator_representation_limits_Out
182181
{
183182
int32_t min_value;
184183
int32_t max_value;
@@ -188,33 +187,6 @@ struct BasicCalculator_representation_limits_Out
188187
} // namespace detail
189188

190189

191-
} // namespace calculator_base
192-
193-
/*!
194-
* @brief This class represents the interface Calculator defined by the user in the IDL file.
195-
* @ingroup calculator
196-
*/
197-
class eProsima_user_DllExport Calculator : public calculator_base::BasicCalculator
198-
{
199-
public:
200-
virtual ~Calculator() = default;
201-
202-
203-
virtual std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientReader<int32_t> > fibonacci_seq(
204-
/*in*/ uint32_t n_results) = 0;
205-
206-
207-
virtual eprosima::fastdds::dds::rpc::RpcFuture<int32_t> sum_all(
208-
/*in*/ std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientWriter<int32_t>>& value) = 0;
209-
210-
211-
virtual std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientReader<int32_t> > accumulator(
212-
/*in*/ std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientWriter<int32_t>>& value) = 0;
213-
214-
};
215-
216-
217-
218190
#endif // _FAST_DDS_GENERATED_CALCULATOR_HPP_
219191

220192

fastdds_python_examples/RPCExample/generated_code/calculator.i

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -102,33 +102,6 @@
102102
}
103103
}
104104

105-
%import(module="fastdds") "fastdds/dds/rpc/interfaces/RpcServerWriter.hpp"
106-
%ignore eprosima::fastdds::dds::rpc::RpcClientReader::read(T&);
107-
%ignore eprosima::fastdds::dds::rpc::RpcClientReader::read(T&,eprosima::fastdds::dds::Duration_t&);
108-
%import(module="fastdds") "fastdds/dds/rpc/interfaces/RpcClientReader.hpp"
109-
%extend eprosima::fastdds::dds::rpc::RpcClientReader {
110-
std::pair<bool, T> read(
111-
const eprosima::fastdds::dds::Duration_t& timeout = eprosima::fastdds::dds::c_TimeInfinite)
112-
{
113-
std::pair<bool, T> ret_val{};
114-
if (eprosima::fastdds::dds::c_TimeInfinite == timeout)
115-
{
116-
ret_val.first = self->read(ret_val.second);
117-
}
118-
else
119-
{
120-
ret_val.first = self->read(ret_val.second, timeout);
121-
}
122-
return ret_val;
123-
}
124-
}
125-
126-
%shared_ptr(eprosima::fastdds::dds::rpc::RpcClientReader<int32_t>);
127-
%template(int32_t_client_reader_result) std::pair<bool, int32_t>;
128-
%template(int32_t_client_reader) eprosima::fastdds::dds::rpc::RpcClientReader<int32_t>;
129-
130-
%template(int32_t_server_writer) eprosima::fastdds::dds::rpc::RpcServerWriter<int32_t>;
131-
132105
// Code for std::future taken from https://github.com/swig/swig/issues/1828#issuecomment-648449092
133106
namespace eprosima::fastdds::dds::rpc
134107
{
@@ -159,12 +132,12 @@ class RpcFuture {
159132

160133
}
161134

162-
%shared_ptr(eprosima::fastdds::dds::rpc::RpcFuture<calculator_base::detail::BasicCalculator_representation_limits_Out>);
163-
%template(calculator_base_detail_BasicCalculator_representation_limits_Out_rpc_future) eprosima::fastdds::dds::rpc::RpcFuture<calculator_base::detail::BasicCalculator_representation_limits_Out>;
135+
%shared_ptr(eprosima::fastdds::dds::rpc::RpcFuture<detail::Calculator_representation_limits_Out>);
136+
%template(detail_Calculator_representation_limits_Out_rpc_future) eprosima::fastdds::dds::rpc::RpcFuture<detail::Calculator_representation_limits_Out>;
164137

165-
%typemap(out, optimal="1") eprosima::fastdds::dds::rpc::RpcFuture<calculator_base::detail::BasicCalculator_representation_limits_Out> {
138+
%typemap(out, optimal="1") eprosima::fastdds::dds::rpc::RpcFuture<detail::Calculator_representation_limits_Out> {
166139
std::shared_ptr<$1_ltype> *smartresult = new std::shared_ptr<$1_ltype>(new $1_ltype($1));
167-
$result = SWIG_NewPointerObj(SWIG_as_voidptr(smartresult), $descriptor(std::shared_ptr< eprosima::fastdds::dds::rpc::RpcFuture<calculator_base::detail::BasicCalculator_representation_limits_Out>> *), SWIG_POINTER_OWN);
140+
$result = SWIG_NewPointerObj(SWIG_as_voidptr(smartresult), $descriptor(std::shared_ptr< eprosima::fastdds::dds::rpc::RpcFuture<detail::Calculator_representation_limits_Out>> *), SWIG_POINTER_OWN);
168141
}
169142

170143
%shared_ptr(eprosima::fastdds::dds::rpc::RpcFuture<int32_t>);
@@ -175,42 +148,6 @@ class RpcFuture {
175148
$result = SWIG_NewPointerObj(SWIG_as_voidptr(smartresult), $descriptor(std::shared_ptr< eprosima::fastdds::dds::rpc::RpcFuture<int32_t>> *), SWIG_POINTER_OWN);
176149
}
177150

178-
%import(module="fastdds") "fastdds/dds/rpc/interfaces/RpcClientWriter.hpp"
179-
%import(module="fastdds") "fastdds/dds/rpc/interfaces/RpcStatusCode.hpp"
180-
181-
%ignore eprosima::fastdds::dds::rpc::RpcServerReader::read(T&);
182-
%ignore eprosima::fastdds::dds::rpc::RpcServerReader::read(T&,eprosima::fastdds::dds::Duration_t&);
183-
%import(module="fastdds") "fastdds/dds/rpc/interfaces/RpcServerReader.hpp"
184-
%extend eprosima::fastdds::dds::rpc::RpcServerReader {
185-
std::pair<bool, T> read(
186-
const eprosima::fastdds::dds::Duration_t& timeout = eprosima::fastdds::dds::c_TimeInfinite)
187-
{
188-
std::pair<bool, T> ret_val{};
189-
if (eprosima::fastdds::dds::c_TimeInfinite == timeout)
190-
{
191-
ret_val.first = self->read(ret_val.second);
192-
}
193-
else
194-
{
195-
ret_val.first = self->read(ret_val.second, timeout);
196-
}
197-
return ret_val;
198-
}
199-
}
200-
201-
%template(int32_t_server_reader_result) std::pair<bool, int32_t>;
202-
%template(int32_t_server_reader) eprosima::fastdds::dds::rpc::RpcServerReader<int32_t>;
203-
204-
%shared_ptr(eprosima::fastdds::dds::rpc::RpcClientWriter<int32_t>);
205-
%template(int32_t_rpc_client_writer) eprosima::fastdds::dds::rpc::RpcClientWriter<int32_t>;
206-
%typemap(in,numinputs=0) std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientWriter<int32_t>>& %{
207-
$1 = new std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientWriter<int32_t>>();
208-
%}
209-
%typemap(argout) std::shared_ptr<eprosima::fastdds::dds::rpc::RpcClientWriter<int32_t>>& (PyObject* tmp) %{
210-
tmp = SWIG_NewPointerObj($1, $1_descriptor, SWIG_POINTER_OWN);
211-
$result = SWIG_Python_AppendOutput($result, tmp);
212-
%}
213-
214151
%exception;
215152

216153
%define %traits_penumn(Type...)
@@ -235,13 +172,6 @@ namespace swig {
235172

236173

237174

238-
%shared_ptr(calculator_base::BasicCalculator);
239-
%shared_ptr(calculator_base::BasicCalculatorServer_IServerImplementation);
240-
%shared_ptr(calculator_base::BasicCalculatorServerImplementation);
241-
%feature("director") calculator_base::BasicCalculatorServerImplementation;
242-
243-
244-
245175
%shared_ptr(Calculator);
246176
%shared_ptr(CalculatorServer_IServerImplementation);
247177
%shared_ptr(CalculatorServerImplementation);

0 commit comments

Comments
 (0)