| {{/* |
| // Copyright 2021 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| */}} |
| |
| {{- define "Method:Response:WireMessagingHeader" }} |
| {{- EnsureNamespace "" }} |
| {{- if .Response.IsResource }} |
| {{- IfdefFuchsia -}} |
| {{- end }} |
| |
| {{- if .HasResponsePayload }} |
| template<> |
| struct {{ .WireResponse }} final {{- if .HasResponsePayload }} : public {{ .ResponsePayload }}{{ end }} { |
| {{- range .ResponseAnonymousChildren }} |
| using {{ .ScopedName }} = {{ .FlattenedName }}; |
| {{- end }} |
| |
| {{ if (and .ResponseFlattened .HasResponsePayload) }} |
| explicit {{ .WireResponse.Self }}({{ .ResponsePayload }} base) : {{ .ResponsePayload }}(std::move(base)) {} |
| {{- end }} |
| |
| {{- if .ResponseArgs }} |
| explicit {{ .WireResponse.Self }}({{ RenderParams .ResponseArgs }}) : {{ .ResponsePayload }} |
| {{- if .ResponseFlattened -}} |
| {{- "{ " }}{{ RenderForwardStructParams .ResponseArgs }}} |
| {{- else -}} |
| ({{ RenderForwardParams .ResponseArgs }}) |
| {{- end -}}{} |
| {{- end }} |
| {{ .WireResponse.Self }}() = default; |
| }; |
| {{- end }} |
| |
| {{ if .HasResponsePayload }} |
| template <bool IsRecursive> |
| struct ::fidl::internal::WireCodingTraits<{{ .WireResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> |
| : public WireStructCodingTraitsBase<{{ .WireResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> { |
| static constexpr size_t kInlineSize = {{ .Response.TypeShapeV2.InlineSize }}; |
| |
| static void Encode( |
| internal::WireEncoder* encoder, {{ .WireResponse }}* value, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| fidl::internal::WireCodingTraits<{{ .ResponsePayload }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>::Encode( |
| encoder, value, position, recursion_depth); |
| } |
| static void Decode( |
| internal::WireDecoder* decoder, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| fidl::internal::WireCodingTraits<{{ .ResponsePayload }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive>::Decode( |
| decoder, position, recursion_depth); |
| } |
| }; |
| {{- end }} |
| |
| template<> |
| struct {{ .WireTransactionalResponse }} final { |
| FIDL_ALIGNDECL |
| fidl_message_header_t header; |
| {{ if .ResponseArgs }} |
| {{ .WireResponse }} body; |
| explicit {{ .WireTransactionalResponse.Self }}({{ RenderParams .ResponseArgs }}) |
| : body({{ .WireResponse }}({{ RenderForwardParams .ResponseArgs }})) { |
| _InitHeader(); |
| } |
| {{- end }} |
| {{ .WireTransactionalResponse.Self }}() { |
| _InitHeader(); |
| } |
| |
| {{- if .Response.IsResource }} |
| void _CloseHandles() { |
| {{- if .ResponseArgs }} |
| body._CloseHandles(); |
| {{- end }} |
| } |
| {{- end }} |
| |
| private: |
| void _InitHeader(); |
| }; |
| |
| template <bool IsRecursive> |
| struct ::fidl::internal::WireCodingTraits<{{ .WireTransactionalResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> |
| : public WireStructCodingTraitsBase<{{ .WireTransactionalResponse }}, ::fidl::internal::WireCodingConstraintEmpty, IsRecursive> { |
| static constexpr size_t kInlineSize = {{ .Response.TypeShapeV2.InlineSize }} + sizeof(fidl_message_header_t); |
| |
| static void Encode(internal::WireEncoder* encoder, {{ .WireTransactionalResponse }}* value, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| *position.As<fidl_message_header_t>() = value->header; |
| {{- if .HasResponsePayload }} |
| WireCodingTraits<{{ .WireResponse }}, WireCodingConstraintEmpty, IsRecursive>::Encode( |
| encoder, &value->body, position + sizeof(fidl_message_header_t), recursion_depth); |
| {{- end }} |
| } |
| static void Decode( |
| internal::WireDecoder* decoder, ::fidl::internal::WirePosition position, RecursionDepth<IsRecursive> recursion_depth) { |
| {{- if .HasResponsePayload }} |
| WireCodingTraits<{{ .WireResponse }}, WireCodingConstraintEmpty, IsRecursive>::Decode( |
| decoder, position + sizeof(fidl_message_header_t), recursion_depth); |
| {{- end }} |
| } |
| }; |
| {{- if .Response.IsResource }} |
| {{- EndifFuchsia -}} |
| {{- end }} |
| {{- end }} |
| |
| |
| |
| |
| {{- define "Method:Response:WireMessagingSource" }} |
| {{- EnsureNamespace "" }} |
| {{- if .Response.IsResource }} |
| {{- IfdefFuchsia -}} |
| {{- end }} |
| void {{ .WireTransactionalResponse }}::_InitHeader() { |
| ::fidl::InitTxnHeader(&header, 0, {{ .OrdinalName }}, {{ .DynamicFlagsName }}); |
| } |
| |
| {{- if .Response.IsResource }} |
| {{- EndifFuchsia -}} |
| {{- end }} |
| {{- end }} |
| |
| |
| |
| {{- define "Method:Response:NaturalMessagingHeader" }} |
| {{- IfdefFuchsia -}} |
| {{- EnsureNamespace "" }} |
| |
| template <> |
| class {{ .NaturalResponse }} final |
| {{- if .ResponseMessageBase }} : public {{ .ResponseMessageBase }} {{ end }} { |
| public: |
| {{- if .HasResponsePayload }} |
| {{- if .Result }} |
| {{- if .Result.HasError }} |
| using {{ .ResponseMessageBase }}::result; |
| {{ .NaturalResponse.Self }}({{ .ResponseMessageBase }} v) : result(std::move(v)) {} |
| {{ .NaturalResponse.Self }}() = delete; |
| {{- else if .Result.ValueParameters }} |
| using {{ .Result.ValueTypeDecl }}::{{ .Result.ValueTypeDecl.Self }}; |
| {{ .NaturalResponse.Self }}({{ .ResponseMessageBase }} v) : {{ .Result.ValueTypeDecl.Self }}(std::move(v)) {} |
| {{- end }} |
| {{- else }} |
| using {{ .ResponsePayload }}::{{ .ResponsePayload.Self }}; |
| {{ .NaturalResponse.Self }}({{ .ResponseMessageBase }} v) : {{ .ResponsePayload.Self }}(std::move(v)) {} |
| {{- end }} |
| {{- end }} |
| }; |
| |
| {{- if .Result }} |
| template <> |
| class {{ .NaturalResponseConverter }} { |
| using DomainObject = {{ .ResponsePayload }}; |
| |
| public: |
| static DomainObject IntoDomainObject({{ .NaturalResponseArg "m" }}) { |
| {{ if .Result.HasError -}} |
| if (m.is_error()) { |
| return DomainObject::WithErr(m.error_value()); |
| } else { |
| {{- if .Result.ValueParameters }} |
| return DomainObject::WithResponse(std::move(m.value())); |
| {{- else }} |
| return DomainObject::WithResponse({}); |
| {{- end }} |
| } |
| {{- else -}} |
| {{- if .Result.ValueParameters }} |
| return DomainObject::WithResponse(std::move(m)); |
| {{- else }} |
| return DomainObject::WithResponse({}); |
| {{- end }} |
| {{- end }} |
| } |
| }; |
| {{- end }} |
| |
| |
| {{- EndifFuchsia -}} |
| {{- end }} |
| |
| |
| |
| {{- define "Method:Response:NaturalMessagingSource" }} |
| |
| {{- end }} |
| |
| {{- define "Method:Response:Traits:TypeConversionsHeader" }} |
| {{- if .HasResponsePayload }} |
| {{- if not .HasFrameworkError }} |
| template <> |
| struct WireNaturalConversionTraits<{{ .WireResponse }}, {{ .NaturalResponse }}> { |
| static {{ .NaturalResponse }} ToNatural({{ .WireResponse }} src); |
| static {{ .WireResponse }} ToWire(fidl::AnyArena& arena, {{ .NaturalResponse }} src); |
| }; |
| |
| template <> |
| struct NaturalTypeForWireType<{{ .WireResponse }}> { |
| using type = {{ .NaturalResponse }}; |
| }; |
| template <> |
| struct WireTypeForNaturalType<{{ .NaturalResponse }}> { |
| using type = {{ .WireResponse }}; |
| }; |
| {{- end }} |
| {{- end }} |
| {{- end }} |
| |
| {{- define "Method:Response:Traits:TypeConversionsSource" }} |
| {{- if .HasResponsePayload }} |
| {{- if not .HasFrameworkError }} |
| {{ .NaturalResponse }} WireNaturalConversionTraits<{{ .WireResponse }}, {{ .NaturalResponse }}>::ToNatural({{ .WireResponse }} src) { |
| {{- if and .HasResponsePayload .ResponseMessageBase }} |
| return {{ .NaturalResponse }}( |
| WireNaturalConversionTraits<{{ .ResponsePayload.Wire }}, {{ .ResponseMessageBase }}>::ToNatural(std::move(src))); |
| {{- else }} |
| return {{ .NaturalResponse }}(); |
| {{- end }} |
| } |
| {{ .WireResponse }} WireNaturalConversionTraits<{{ .WireResponse }}, {{ .NaturalResponse }}>::ToWire(fidl::AnyArena& arena, {{ .NaturalResponse }} src) { |
| {{- if and .HasResponsePayload .ResponseMessageBase }} |
| return {{ .WireResponse }}( |
| WireNaturalConversionTraits<{{ .ResponsePayload.Wire }}, {{ .ResponseMessageBase }}>::ToWire(arena, std::move(src))); |
| {{- else }} |
| return {{ .WireResponse }}(); |
| {{- end }} |
| } |
| {{- end }} |
| {{- end }} |
| {{- end }} |