mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-29 12:34:07 +08:00
Simplified service types: the nested types Request/Response are templates now, but the containing type is not, so using 'typename' to refer to Request or Response is no longer necessary.
This commit is contained in:
parent
7bc7269e37
commit
beaba20749
@ -40,12 +40,14 @@ namespace ${nsc}
|
||||
UAVCAN_PACKED_BEGIN
|
||||
#endif
|
||||
|
||||
% if t.kind != t.KIND_SERVICE:
|
||||
template <int I>
|
||||
% endif
|
||||
struct ${t.cpp_type_name}
|
||||
{
|
||||
<%def name="generate_primary_body(typedef_name, ctor_name, max_bitlen, fields, constants)" buffered="True">
|
||||
typedef const ${typedef_name}& ParameterType;
|
||||
typedef ${typedef_name}& ReferenceType;
|
||||
<%def name="generate_primary_body(type_name, max_bitlen, fields, constants)" buffered="True">
|
||||
typedef const ${type_name}<I>& ParameterType;
|
||||
typedef ${type_name}<I>& ReferenceType;
|
||||
|
||||
<%def name="expand_attr_types(group_name, attrs)">
|
||||
struct ${group_name}
|
||||
@ -87,7 +89,7 @@ struct ${t.cpp_type_name}
|
||||
typename ::uavcan::StorageType< typename FieldTypes::${a.name} >::Type ${a.name};
|
||||
% endfor
|
||||
|
||||
${ctor_name}()
|
||||
${type_name}()
|
||||
% for idx,a in enumerate(fields):
|
||||
${':' if idx == 0 else ','} ${a.name}()
|
||||
% endfor
|
||||
@ -96,6 +98,7 @@ struct ${t.cpp_type_name}
|
||||
::uavcan::StaticAssert<int(MaxByteLen) <= int(::uavcan::MaxTransferPayloadLen)>::check();
|
||||
|
||||
::uavcan::StaticAssert<I == 0>::check(); // Usage check
|
||||
|
||||
#if UAVCAN_DEBUG
|
||||
/*
|
||||
* Cross-checking MaxBitLen provided by the DSDL compiler.
|
||||
@ -137,17 +140,22 @@ ${'::uavcan::TailArrayOptDisabled' if (idx + 1) < len(fields) else 'tao_mode'});
|
||||
${generate_codec_calls_per_field('decode', 'ReferenceType')}
|
||||
</%def>
|
||||
% if t.kind == t.KIND_SERVICE:
|
||||
struct Request
|
||||
template <int I>
|
||||
struct Request_
|
||||
{
|
||||
${generate_primary_body('Request', 'Request', t.get_max_bitlen_request(), t.request_fields, t.request_constants) | indent}
|
||||
${generate_primary_body('Request_', t.get_max_bitlen_request(), t.request_fields, t.request_constants) | indent}
|
||||
};
|
||||
|
||||
struct Response
|
||||
template <int I>
|
||||
struct Response_
|
||||
{
|
||||
${generate_primary_body('Response', 'Response', t.get_max_bitlen_response(), t.response_fields, t.response_constants) | indent}
|
||||
${generate_primary_body('Response_', t.get_max_bitlen_response(), t.response_fields, t.response_constants) | indent}
|
||||
};
|
||||
|
||||
typedef Request_<0> Request;
|
||||
typedef Response_<0> Response;
|
||||
% else:
|
||||
${generate_primary_body(t.cpp_type_name + '<I>', t.cpp_type_name, t.get_max_bitlen(), t.fields, t.constants)}
|
||||
${generate_primary_body(t.cpp_type_name, t.get_max_bitlen(), t.fields, t.constants)}
|
||||
% endif
|
||||
|
||||
/*
|
||||
@ -197,24 +205,28 @@ private:
|
||||
% for a in constants:
|
||||
% if not a.cpp_use_enum:
|
||||
template <int I>
|
||||
const typename ::uavcan::StorageType< typename ${scope_prefix}::ConstantTypes::${a.name} >::Type
|
||||
${scope_prefix}::${a.name} = ${a.cpp_value}; // ${a.init_expression}
|
||||
const typename ::uavcan::StorageType< typename ${scope_prefix}<I>::ConstantTypes::${a.name} >::Type
|
||||
${scope_prefix}<I>::${a.name} = ${a.cpp_value}; // ${a.init_expression}
|
||||
|
||||
%endif
|
||||
% endfor
|
||||
</%def>
|
||||
% if t.kind == t.KIND_SERVICE:
|
||||
${define_out_of_line_constants(t.cpp_type_name + '<I>::Request', t.request_constants)}
|
||||
${define_out_of_line_constants(t.cpp_type_name + '<I>::Response', t.response_constants)}
|
||||
${define_out_of_line_constants(t.cpp_type_name + '::Request_', t.request_constants)}
|
||||
${define_out_of_line_constants(t.cpp_type_name + '::Response_', t.response_constants)}
|
||||
% else:
|
||||
${define_out_of_line_constants(t.cpp_type_name + '<I>', t.constants)}
|
||||
${define_out_of_line_constants(t.cpp_type_name, t.constants)}
|
||||
% endif
|
||||
|
||||
#if UAVCAN_PACK_STRUCTS
|
||||
UAVCAN_PACKED_END
|
||||
#endif
|
||||
|
||||
% if t.kind == t.KIND_SERVICE:
|
||||
typedef ${t.cpp_type_name} ${t.short_name};
|
||||
% else:
|
||||
typedef ${t.cpp_type_name}<0> ${t.short_name};
|
||||
% endif
|
||||
|
||||
% if t.has_default_dtid:
|
||||
namespace
|
||||
|
||||
@ -18,21 +18,23 @@ class Server : public GenericSubscriber<DataType_, typename DataType_::Request,
|
||||
{
|
||||
public:
|
||||
typedef DataType_ DataType;
|
||||
typedef typename DataType::Request RequestType;
|
||||
typedef typename DataType::Response ResponseType;
|
||||
|
||||
private:
|
||||
typedef GenericSubscriber<DataType, typename DataType::Request, NumStaticReceivers, NumStaticBufs> SubscriberType;
|
||||
typedef GenericPublisher<DataType, typename DataType::Response> PublisherType;
|
||||
typedef GenericSubscriber<DataType, RequestType, NumStaticReceivers, NumStaticBufs> SubscriberType;
|
||||
typedef GenericPublisher<DataType, ResponseType> PublisherType;
|
||||
|
||||
PublisherType publisher_;
|
||||
Callback callback_;
|
||||
uint32_t response_failure_count_;
|
||||
typename DataType::Response response_;
|
||||
ResponseType response_;
|
||||
|
||||
void handleReceivedDataStruct(ReceivedDataStructure<typename DataType::Request>& request)
|
||||
void handleReceivedDataStruct(ReceivedDataStructure<RequestType>& request)
|
||||
{
|
||||
if (try_implicit_cast<bool>(callback_, true))
|
||||
{
|
||||
response_ = typename DataType::Response(); // The application needs newly initialized structure
|
||||
response_ = ResponseType(); // The application needs newly initialized structure
|
||||
callback_(request, response_);
|
||||
}
|
||||
else
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
bool TRUE = true
|
||||
bool NOT_TRUE = false * true
|
||||
uint64 BIG = (1 << 64) - 1
|
||||
float64 FLOAT_CONSTANT = 3.14
|
||||
uint8[<128] string_request
|
||||
---
|
||||
float64 FLOAT_CONSTANT = 1.79769313486231570815e+308
|
||||
|
||||
@ -16,8 +16,8 @@ struct ServerImpl
|
||||
|
||||
ServerImpl(const char* string_response) : string_response(string_response) { }
|
||||
|
||||
void handleRequest(const uavcan::ReceivedDataStructure<typename root_ns_a::StringService::Request>& request,
|
||||
typename root_ns_a::StringService::Response& response)
|
||||
void handleRequest(const uavcan::ReceivedDataStructure<root_ns_a::StringService::Request>& request,
|
||||
root_ns_a::StringService::Response& response)
|
||||
{
|
||||
std::cout << request << std::endl;
|
||||
response.string_response = request.string_request;
|
||||
@ -27,8 +27,8 @@ struct ServerImpl
|
||||
}
|
||||
|
||||
typedef uavcan::MethodBinder<ServerImpl*,
|
||||
void (ServerImpl::*)(const uavcan::ReceivedDataStructure<typename root_ns_a::StringService::Request>&,
|
||||
typename root_ns_a::StringService::Response&)> Binder;
|
||||
void (ServerImpl::*)(const uavcan::ReceivedDataStructure<root_ns_a::StringService::Request>&,
|
||||
root_ns_a::StringService::Response&)> Binder;
|
||||
|
||||
Binder bind() { return Binder(this, &ServerImpl::handleRequest); }
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user