| {{/* |
| // Copyright 2018 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 "Protocol:ForwardDeclaration:WireMessagingHeader" }} |
| {{ EnsureNamespace . }} |
| class {{ .Name }}; |
| {{- end }} |
| |
| |
| |
| {{- define "Method:ClientAllocationComment:Helper" -}} |
| {{- if SyncCallTotalStackSizeV2 . -}} |
| Allocates {{ SyncCallTotalStackSizeV2 . }} bytes of {{ "" -}} |
| {{- if not .Request.ClientAllocationV2.IsStack -}} |
| response |
| {{- else -}} |
| {{- if not .Response.ClientAllocationV2.IsStack -}} |
| request |
| {{- else -}} |
| message |
| {{- end -}} |
| {{- end }} buffer on the stack. |
| {{- end }} |
| {{- if and .Request.ClientAllocationV2.IsStack .Response.ClientAllocationV2.IsStack -}} |
| {{ "" }} No heap allocation necessary. |
| {{- else }} |
| {{- if not .Request.ClientAllocationV2.IsStack }} Request is heap-allocated. {{- end }} |
| {{- if not .Response.ClientAllocationV2.IsStack }} Response is heap-allocated. {{- end }} |
| {{- end }} |
| {{- end }} |
| |
| |
| |
| {{- define "Protocol:WireMessagingHeader" }} |
| {{- $protocol := . }} |
| {{ "" }} |
| {{- range .Methods }} |
| {{ EnsureCodingTableDecl .Request.WireCodingTable }} |
| {{ EnsureCodingTableDecl .Response.WireCodingTable }} |
| {{- end }} |
| {{ "" }} |
| |
| {{- range .Methods }} |
| {{- EnsureNamespace "" }} |
| template<> |
| struct {{ .WireOrdinal }} final { static constexpr uint64_t value = {{ .Ordinal }}lu; }; |
| {{- end }} |
| |
| {{ EnsureNamespace . }} |
| |
| {{- template "Protocol:Details:WireMessagingHeader" . }} |
| {{- template "Protocol:Dispatcher:WireMessagingHeader" . }} |
| |
| {{- range .Methods }} |
| {{- if .HasRequest }} |
| {{- template "Method:Request:WireMessagingHeader" . }} |
| {{- end }} |
| {{- if .HasResponse }} |
| {{- if .IsEvent }} |
| {{- template "Method:Event:WireMessagingHeader" . }} |
| {{- else }} |
| {{- template "Method:Response:WireMessagingHeader" . }} |
| {{- end }} |
| {{- end }} |
| {{- end }} |
| |
| {{- range .TwoWayMethods }} |
| {{- template "Method:Types:WireMessagingHeader" . }} |
| {{- end }} |
| |
| {{ EnsureNamespace "fidl" }} |
| {{ template "Protocol:Traits:WireMessagingHeader" . }} |
| |
| {{ EnsureNamespace . }} |
| |
| {{- IfdefFuchsia -}} |
| {{- range .ClientMethods -}} |
| {{- if .Transport.HasSyncClient }} |
| {{- if eq .Transport.Name "Channel" }} |
| {{- template "Method:Result:WireMessagingHeader" . }} |
| {{- end }} |
| {{- end }} |
| {{- if eq .Transport.Name "Driver" }} |
| {{- template "driver/Method:UnownedResult:MessagingHeader" . }} |
| {{- else }} |
| {{- template "Method:UnownedResult:WireMessagingHeader" . }} |
| {{- end }} |
| {{- end }} |
| |
| {{- template "Protocol:EventHandler:WireMessagingHeader" . }} |
| {{- if .Transport.HasSyncClient }} |
| {{- if eq .Transport.Name "Driver" }} |
| {{- template "driver/Protocol:Caller:MessagingHeader" . }} |
| {{- else }} |
| {{- template "Protocol:Caller:WireMessagingHeader" . }} |
| {{- end }} |
| {{- end }} |
| {{- template "Protocol:Interface:WireMessagingHeader" . }} |
| {{- EndifFuchsia -}} |
| |
| {{- end }} |
| |
| |
| |
| {{- define "Protocol:Traits:WireMessagingHeader" -}} |
| {{ $protocol := . -}} |
| {{ range .Methods -}} |
| {{ $method := . -}} |
| {{- if .HasRequest }} |
| |
| template <> |
| struct IsFidlType<{{ .WireTransactionalRequest }}> : public std::true_type {}; |
| template <> |
| struct IsFidlType<{{ .WireRequest }}> : public std::true_type {}; |
| template <> |
| struct IsFidlTransactionalMessage<{{ .WireTransactionalRequest }}> : public std::true_type {}; |
| template <> |
| struct IsFidlTransactionalMessage<{{ .WireRequest }}> : public std::false_type {}; |
| {{- if .Request.IsResource }} |
| {{- IfdefFuchsia -}} |
| template <> |
| struct IsResource<{{ .WireTransactionalRequest }}> : public std::true_type {}; |
| template <> |
| struct IsResource<{{ .WireRequest }}> : public std::true_type {}; |
| {{- end }} |
| |
| |
| template <> |
| struct TypeTraits<{{ .WireTransactionalRequest }}> { |
| static constexpr const fidl_type_t* kType = |
| {{- if .RequestArgs }} |
| &{{ .Request.WireCodingTable }}; |
| {{- else }} |
| nullptr; |
| {{- end }} |
| static constexpr uint32_t kMaxNumHandles = {{ .Request.TypeShapeV2.MaxHandles }}; |
| static constexpr uint32_t kPrimarySize = FIDL_ALIGN({{ .Request.TypeShapeV2.InlineSize }} + sizeof(fidl_message_header_t)); |
| static constexpr uint32_t kPrimarySizeV1 = FIDL_ALIGN({{ .Request.TypeShapeV1.InlineSize }} + sizeof(fidl_message_header_t)); |
| static constexpr uint32_t kMaxOutOfLine = {{ .Request.TypeShapeV2.MaxOutOfLine }}; |
| static constexpr uint32_t kMaxOutOfLineV1 = {{ .Request.TypeShapeV1.MaxOutOfLine }}; |
| static constexpr bool kHasFlexibleEnvelope = {{ .Request.TypeShapeV2.HasFlexibleEnvelope }}; |
| static constexpr bool kHasPointer = {{ .Request.TypeShapeV2.HasPointer }}; |
| static constexpr ::fidl::internal::TransactionalMessageKind kMessageKind = |
| ::fidl::internal::TransactionalMessageKind::kRequest; |
| }; |
| |
| static_assert(sizeof({{ .WireTransactionalRequest }}) |
| == TypeTraits<{{ .WireTransactionalRequest }}>::kPrimarySize); |
| static_assert(offsetof({{ .WireTransactionalRequest }}, header) == 0); |
| {{- if .RequestArgs }} |
| static_assert(offsetof({{ .WireTransactionalRequest }}, body) == sizeof(fidl_message_header_t)); |
| {{- end }} |
| |
| template <> |
| struct TypeTraits<{{ .WireRequest }}> { |
| static constexpr const fidl_type_t* kType = |
| {{- if .RequestArgs }} |
| &{{ .Request.WireCodingTable }}; |
| {{- else }} |
| nullptr; |
| {{- end }} |
| static constexpr uint32_t kMaxNumHandles = {{ .Request.TypeShapeV2.MaxHandles }}; |
| static constexpr uint32_t kPrimarySize = {{ .Request.TypeShapeV2.InlineSize }}; |
| static constexpr uint32_t kPrimarySizeV1 = {{ .Request.TypeShapeV1.InlineSize }}; |
| static constexpr uint32_t kMaxOutOfLine = {{ .Request.TypeShapeV2.MaxOutOfLine }}; |
| static constexpr uint32_t kMaxOutOfLineV1 = {{ .Request.TypeShapeV1.MaxOutOfLine }}; |
| static constexpr bool kHasFlexibleEnvelope = {{ .Request.TypeShapeV2.HasFlexibleEnvelope }}; |
| static constexpr bool kHasPointer = {{ .Request.TypeShapeV2.HasPointer }}; |
| static constexpr ::fidl::internal::TransactionalMessageKind kMessageKind = |
| ::fidl::internal::TransactionalMessageKind::kRequest; |
| }; |
| |
| {{- if .RequestArgs }} |
| static_assert(sizeof({{ .WireRequest }}) |
| == TypeTraits<{{ .WireRequest }}>::kPrimarySize); |
| {{- if .RequestFlattened }} |
| {{- range $index, $param := .RequestArgs }} |
| static_assert(offsetof({{ $method.WireRequest }}, {{ $param.Name }}) == {{ $param.OffsetV2 }}); |
| {{- end }} |
| {{- end }} |
| {{- end }} |
| {{- if .Request.IsResource }} |
| {{- EndifFuchsia -}} |
| {{- end }} |
| {{- end }} |
| {{- if .HasResponse }} |
| |
| {{- if .IsEvent }} |
| |
| template <> |
| struct IsFidlType<{{ .WireTransactionalEvent }}> : public std::true_type {}; |
| template <> |
| struct IsFidlType<{{ .WireEvent }}> : public std::true_type {}; |
| template <> |
| struct IsFidlTransactionalMessage<{{ .WireTransactionalEvent }}> : public std::true_type {}; |
| template <> |
| struct IsFidlTransactionalMessage<{{ .WireEvent }}> : public std::false_type {}; |
| {{- if .Response.IsResource }} |
| {{- IfdefFuchsia -}} |
| template <> |
| struct IsResource<{{ .WireTransactionalEvent }}> : public std::true_type {}; |
| template <> |
| struct IsResource<{{ .WireEvent }}> : public std::true_type {}; |
| {{- end }} |
| |
| |
| template <> |
| struct TypeTraits<{{ .WireTransactionalEvent }}> { |
| static constexpr const fidl_type_t* kType = |
| {{- if .ResponseArgs }} |
| &{{ .Response.WireCodingTable }}; |
| {{- else }} |
| nullptr; |
| {{- end }} |
| static constexpr uint32_t kMaxNumHandles = {{ .Response.TypeShapeV2.MaxHandles }}; |
| static constexpr uint32_t kPrimarySize = FIDL_ALIGN({{ .Response.TypeShapeV2.InlineSize }} + sizeof(fidl_message_header_t)); |
| static constexpr uint32_t kPrimarySizeV1 = FIDL_ALIGN({{ .Response.TypeShapeV1.InlineSize }} + sizeof(fidl_message_header_t)); |
| static constexpr uint32_t kMaxOutOfLine = {{ .Response.TypeShapeV2.MaxOutOfLine }}; |
| static constexpr uint32_t kMaxOutOfLineV1 = {{ .Response.TypeShapeV1.MaxOutOfLine }}; |
| static constexpr bool kHasFlexibleEnvelope = {{ .Response.TypeShapeV2.HasFlexibleEnvelope }}; |
| static constexpr bool kHasPointer = {{ .Response.TypeShapeV2.HasPointer }}; |
| static constexpr ::fidl::internal::TransactionalMessageKind kMessageKind = |
| ::fidl::internal::TransactionalMessageKind::kResponse; |
| }; |
| |
| static_assert(sizeof({{ .WireTransactionalEvent }}) |
| == TypeTraits<{{ .WireTransactionalEvent }}>::kPrimarySize); |
| static_assert(offsetof({{ .WireTransactionalEvent }}, header) == 0); |
| {{- if .ResponseArgs }} |
| static_assert(offsetof({{ .WireTransactionalEvent }}, body) == sizeof(fidl_message_header_t)); |
| {{- end }} |
| |
| template <> |
| struct TypeTraits<{{ .WireEvent }}> { |
| static constexpr const fidl_type_t* kType = |
| {{- if .ResponseArgs }} |
| &{{ .Response.WireCodingTable }}; |
| {{- else }} |
| nullptr; |
| {{- end }} |
| static constexpr uint32_t kMaxNumHandles = {{ .Response.TypeShapeV2.MaxHandles }}; |
| static constexpr uint32_t kPrimarySize = {{ .Response.TypeShapeV2.InlineSize }}; |
| static constexpr uint32_t kPrimarySizeV1 = {{ .Response.TypeShapeV1.InlineSize }}; |
| static constexpr uint32_t kMaxOutOfLine = {{ .Response.TypeShapeV2.MaxOutOfLine }}; |
| static constexpr uint32_t kMaxOutOfLineV1 = {{ .Response.TypeShapeV1.MaxOutOfLine }}; |
| static constexpr bool kHasFlexibleEnvelope = {{ .Response.TypeShapeV2.HasFlexibleEnvelope }}; |
| static constexpr bool kHasPointer = {{ .Response.TypeShapeV2.HasPointer }}; |
| static constexpr ::fidl::internal::TransactionalMessageKind kMessageKind = |
| ::fidl::internal::TransactionalMessageKind::kResponse; |
| }; |
| |
| {{- if .ResponseArgs }} |
| static_assert(sizeof({{ .WireEvent }}) |
| == TypeTraits<{{ .WireEvent }}>::kPrimarySize); |
| {{- if .ResponseFlattened }} |
| {{- range $index, $param := .ResponseArgs }} |
| static_assert(offsetof({{ $method.WireEvent }}, {{ $param.Name }}) == {{ $param.OffsetV2 }}); |
| {{- end }} |
| {{- end }} |
| {{- end }} |
| {{- if .Response.IsResource }} |
| {{- EndifFuchsia -}} |
| {{- end }} |
| |
| {{- else }} |
| |
| template <> |
| struct IsFidlType<{{ .WireTransactionalResponse }}> : public std::true_type {}; |
| template <> |
| struct IsFidlType<{{ .WireResponse }}> : public std::true_type {}; |
| template <> |
| struct IsFidlTransactionalMessage<{{ .WireTransactionalResponse }}> : public std::true_type {}; |
| template <> |
| struct IsFidlTransactionalMessage<{{ .WireResponse }}> : public std::false_type {}; |
| {{- if .Response.IsResource }} |
| {{- IfdefFuchsia -}} |
| template <> |
| struct IsResource<{{ .WireTransactionalResponse }}> : public std::true_type {}; |
| template <> |
| struct IsResource<{{ .WireResponse }}> : public std::true_type {}; |
| {{- end }} |
| |
| |
| template <> |
| struct TypeTraits<{{ .WireTransactionalResponse }}> { |
| static constexpr const fidl_type_t* kType = |
| {{- if .ResponseArgs }} |
| &{{ .Response.WireCodingTable }}; |
| {{- else }} |
| nullptr; |
| {{- end }} |
| static constexpr uint32_t kMaxNumHandles = {{ .Response.TypeShapeV2.MaxHandles }}; |
| static constexpr uint32_t kPrimarySize = FIDL_ALIGN({{ .Response.TypeShapeV2.InlineSize }} + sizeof(fidl_message_header_t)); |
| static constexpr uint32_t kPrimarySizeV1 = FIDL_ALIGN({{ .Response.TypeShapeV1.InlineSize }} + sizeof(fidl_message_header_t)); |
| static constexpr uint32_t kMaxOutOfLine = {{ .Response.TypeShapeV2.MaxOutOfLine }}; |
| static constexpr uint32_t kMaxOutOfLineV1 = {{ .Response.TypeShapeV1.MaxOutOfLine }}; |
| static constexpr bool kHasFlexibleEnvelope = {{ .Response.TypeShapeV2.HasFlexibleEnvelope }}; |
| static constexpr bool kHasPointer = {{ .Response.TypeShapeV2.HasPointer }}; |
| static constexpr ::fidl::internal::TransactionalMessageKind kMessageKind = |
| ::fidl::internal::TransactionalMessageKind::kResponse; |
| }; |
| |
| static_assert(sizeof({{ .WireTransactionalResponse }}) |
| == TypeTraits<{{ .WireTransactionalResponse }}>::kPrimarySize); |
| static_assert(offsetof({{ .WireTransactionalResponse }}, header) == 0); |
| {{- if .ResponseArgs }} |
| static_assert(offsetof({{ .WireTransactionalResponse }}, body) == sizeof(fidl_message_header_t)); |
| {{- end }} |
| |
| template <> |
| struct TypeTraits<{{ .WireResponse }}> { |
| static constexpr const fidl_type_t* kType = |
| {{- if .ResponseArgs }} |
| &{{ .Response.WireCodingTable }}; |
| {{- else }} |
| nullptr; |
| {{- end }} |
| static constexpr uint32_t kMaxNumHandles = {{ .Response.TypeShapeV2.MaxHandles }}; |
| static constexpr uint32_t kPrimarySize = {{ .Response.TypeShapeV2.InlineSize }}; |
| static constexpr uint32_t kPrimarySizeV1 = {{ .Response.TypeShapeV1.InlineSize }}; |
| static constexpr uint32_t kMaxOutOfLine = {{ .Response.TypeShapeV2.MaxOutOfLine }}; |
| static constexpr uint32_t kMaxOutOfLineV1 = {{ .Response.TypeShapeV1.MaxOutOfLine }}; |
| static constexpr bool kHasFlexibleEnvelope = {{ .Response.TypeShapeV2.HasFlexibleEnvelope }}; |
| static constexpr bool kHasPointer = {{ .Response.TypeShapeV2.HasPointer }}; |
| static constexpr ::fidl::internal::TransactionalMessageKind kMessageKind = |
| ::fidl::internal::TransactionalMessageKind::kResponse; |
| }; |
| |
| {{- if .ResponseArgs }} |
| static_assert(sizeof({{ .WireResponse }}) |
| == TypeTraits<{{ .WireResponse }}>::kPrimarySize); |
| {{- if .ResponseFlattened }} |
| {{- range $index, $param := .ResponseArgs }} |
| static_assert(offsetof({{ $method.WireResponse }}, {{ $param.Name }}) == {{ $param.OffsetV2 }}); |
| {{- end }} |
| {{- end }} |
| {{- end }} |
| {{- if .Response.IsResource }} |
| {{- EndifFuchsia -}} |
| {{- end }} |
| {{- end }} |
| |
| {{- end }} |
| {{- end }} |
| {{- end }} |
| |
| |
| |
| {{- define "Protocol:WireMessagingSource" }} |
| {{ $protocol := . -}} |
| |
| {{- range .Methods }} |
| {{ EnsureNamespace .OrdinalName }} |
| [[maybe_unused]] |
| constexpr uint64_t {{ .OrdinalName.Name }} = {{ .Ordinal }}lu; |
| {{ EnsureNamespace .DynamicFlagsName }} |
| [[maybe_unused]] |
| constexpr ::fidl::MessageDynamicFlags {{ .DynamicFlagsName.Name }} = {{ .DynamicFlags }}; |
| {{- if .HasRequestPayload }} |
| {{ EnsureNamespace .Request.WireCodingTable }} |
| extern "C" const fidl_type_t {{ .Request.WireCodingTable.Name }}; |
| {{- end }} |
| {{- if .HasResponsePayload }} |
| {{ EnsureNamespace .Response.WireCodingTable }} |
| extern "C" const fidl_type_t {{ .Response.WireCodingTable.Name }}; |
| {{- end }} |
| {{- end }} |
| |
| {{- /* Client-calling functions do not apply to events. */}} |
| {{- range .ClientMethods -}} |
| {{ "" }} |
| {{- if .Transport.HasSyncClient }} |
| {{- if eq .Transport.Name "Channel" }} |
| {{- template "Method:Result:WireMessagingSource" . }} |
| {{- end }} |
| {{- end }} |
| {{ "" }} |
| {{- if eq .Transport.Name "Driver" }} |
| {{- template "driver/Method:UnownedResult:MessagingSource" . }} |
| {{- else }} |
| {{- template "Method:UnownedResult:WireMessagingSource" . }} |
| {{- end }} |
| {{ "" }} |
| {{- end }} |
| |
| {{- if eq .Transport.Name "Driver" }} |
| {{ template "Protocol:ClientImpl:driver/MessagingSource" . }} |
| {{- else }} |
| {{ template "Protocol:ClientImpl:WireMessagingSource" . }} |
| {{- end }} |
| |
| {{ template "Protocol:EventHandler:WireMessagingSource" . }} |
| |
| {{- /* Server implementation */}} |
| {{ template "Protocol:Dispatcher:WireMessagingSource" . }} |
| |
| {{- if .Methods }} |
| {{- range .TwoWayMethods -}} |
| {{- if eq .Transport.Name "Driver" }} |
| {{- template "Method:CompleterBase:driver/WireMessagingSource" . }} |
| {{- else }} |
| {{- template "Method:CompleterBase:WireMessagingSource" . }} |
| {{- end }} |
| {{- end }} |
| |
| {{- range .Methods }} |
| |
| {{- if .HasRequest }}{{ template "Method:Request:WireMessagingSource" . }}{{ end }} |
| {{ "" }} |
| |
| {{- if .HasResponse }} |
| {{- if .IsEvent }} |
| {{ template "Method:Event:WireMessagingSource" . }} |
| {{- else }} |
| {{ template "Method:Response:WireMessagingSource" . }} |
| {{- end }} |
| {{ end }} |
| {{ "" }} |
| |
| {{- end }} |
| {{- end }} |
| |
| {{- end }} |
| |
| |
| |
| {{- define "Protocol:NaturalMessagingHeader" }} |
| {{- range .TwoWayMethods }} |
| {{- template "Method:Types:NaturalMessagingHeader" . }} |
| {{- end }} |
| |
| {{- /* This decouples the natural messaging header from the messaging header. */}} |
| {{- /* For example, we could transition one of them off of coding tables independently. */}} |
| {{- range .Methods }} |
| {{ EnsureCodingTableDecl .Request.WireCodingTable }} |
| {{ EnsureCodingTableDecl .Response.WireCodingTable }} |
| {{- end }} |
| {{- end }} |