| {{/* |
| // 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 "Protocol:EventHandler:WireMessagingHeader" }} |
| {{- EnsureNamespace "" }} |
| {{- IfdefFuchsia }} |
| template<> |
| class {{ .WireEventHandlerInterface }} : public ::fidl::internal::BaseEventHandlerInterface { |
| public: |
| {{ .WireEventHandlerInterface.Self }}() = default; |
| virtual ~{{ .WireEventHandlerInterface.Self }}() = default; |
| {{- range .Events -}} |
| {{- .Docs }} |
| virtual void {{ .Name }}({{ .WireEvent }}* event) = 0; |
| {{- end }} |
| }; |
| |
| template<> |
| class {{ .WireAsyncEventHandler }} |
| : public {{ .WireEventHandlerInterface }}, public ::fidl::internal::AsyncEventHandler { |
| public: |
| {{ .WireAsyncEventHandler.Self }}() = default; |
| {{- range .Events -}} |
| {{- .Docs }} |
| void {{ .Name }}({{ .WireEvent }}* event) override {} |
| {{- end }} |
| }; |
| |
| {{ if .Transport.HasEvents }} |
| template<> |
| class {{ .WireSyncEventHandler }} |
| : public {{ .WireEventHandlerInterface }}, public ::fidl::internal::SyncEventHandler { |
| public: |
| {{ .WireSyncEventHandler.Self }}() = default; |
| |
| {{- range .Events }} |
| {{- if .Transitional }} |
| void {{ .Name }}({{ .WireEvent }}* event) override { OnTransitionalEvent_(); } |
| {{- end }} |
| {{- end }} |
| |
| // Handle all possible events defined in this protocol. |
| // Blocks to consume exactly one message from the channel, then call the corresponding virtual |
| // method. |
| ::fidl::Status HandleOneEvent( |
| ::{{ .Transport.Namespace }}::UnownedClientEnd<{{ . }}> client_end); |
| }; |
| {{- end }} |
| |
| template <> |
| class {{ .WireEventDispatcher }} final : |
| public ::fidl::internal::IncomingEventDispatcher<{{ .WireEventHandlerInterface }}> { |
| public: |
| explicit {{ .WireEventDispatcher.Self }}({{ .WireEventHandlerInterface }}* event_handler) |
| : IncomingEventDispatcher(event_handler) {} |
| |
| {{- if .Events }} |
| ::fidl::Status DispatchEvent( |
| ::fidl::IncomingMessage& msg, |
| ::fidl::internal::MessageStorageViewBase* storage_view) override; |
| {{- end }} |
| }; |
| {{- EndifFuchsia }} |
| {{- end }} |
| |
| |
| |
| {{- define "Protocol:EventHandler:WireMessagingSource" }} |
| {{ EnsureNamespace "" }} |
| {{- IfdefFuchsia }} |
| |
| {{ if .Transport.HasEvents }} |
| ::fidl::Status {{ .WireSyncEventHandler.NoLeading }}::HandleOneEvent( |
| ::{{ .Transport.Namespace }}::UnownedClientEnd<{{ . }}> client_end) { |
| {{ .IncomingEventsStorage }} event_storage; |
| {{ .WireEventDispatcher.NoLeading }} dispatcher{this}; |
| return HandleOneEventImpl_(client_end.channel(), event_storage.view(), dispatcher); |
| } |
| {{- end }} |
| |
| {{- if .Events }} |
| ::fidl::Status |
| {{ .WireEventDispatcher.NoLeading }}::DispatchEvent( |
| ::fidl::IncomingMessage& msg, |
| ::fidl::internal::MessageStorageViewBase* storage_view) { |
| switch (msg.header()->ordinal) { |
| {{- range .Events }} |
| case {{ .OrdinalName }}: |
| { |
| ::fidl::unstable::DecodedMessage<{{ .WireTransactionalEvent }}> decoded{std::move(msg)}; |
| if (!decoded.ok()) { |
| return decoded; |
| } |
| if (event_handler()) { |
| {{- if .ResponseArgs }} |
| auto* primary = &decoded.PrimaryObject()->body; |
| {{- else }} |
| {{ .WireEvent }} empty_event; |
| auto* primary = &empty_event; |
| {{- end }} |
| event_handler()->{{ .Name }}(primary); |
| } |
| return ::fidl::Status::Ok(); |
| } |
| {{- end }} |
| default: |
| return ::fidl::Status::UnknownOrdinal(); |
| } |
| } |
| {{- end }} |
| |
| {{- EndifFuchsia }} |
| {{- end }} |
| |
| |
| |
| {{- define "Protocol:EventHandler:NaturalMessagingHeader" }} |
| {{- EnsureNamespace "" }} |
| {{- IfdefFuchsia }} |
| template<> |
| class {{ .NaturalEventHandlerInterface }} : public ::fidl::internal::BaseEventHandlerInterface { |
| public: |
| {{ .NaturalEventHandlerInterface.Self }}() = default; |
| virtual ~{{ .NaturalEventHandlerInterface.Self }}() = default; |
| {{- range .Events -}} |
| {{- .Docs }} |
| virtual void {{ .Name }}({{ .NaturalEvent }}&) = 0; |
| {{- end }} |
| }; |
| |
| template<> |
| class {{ .NaturalAsyncEventHandler }} |
| : public {{ .NaturalEventHandlerInterface }}, public ::fidl::internal::AsyncEventHandler { |
| public: |
| {{ .NaturalAsyncEventHandler.Self }}() = default; |
| |
| {{- range .Events -}} |
| {{- .Docs }} |
| void {{ .Name }}({{ .NaturalEvent }}&) override {} |
| {{- end }} |
| }; |
| |
| {{ if .Transport.HasEvents }} |
| template<> |
| class {{ .NaturalSyncEventHandler }} |
| : public {{ .NaturalEventHandlerInterface }}, public ::fidl::internal::SyncEventHandler { |
| public: |
| {{ .NaturalSyncEventHandler.Self }}() = default; |
| |
| {{- range .Events }} |
| {{- if .Transitional }} |
| void {{ .Name }}({{ .NaturalEvent }}&) override { OnTransitionalEvent_(); } |
| {{- end }} |
| {{- end }} |
| |
| // Handle all possible events defined in this protocol. |
| // Blocks to consume exactly one message from the channel, then call the corresponding virtual |
| // method. |
| ::fidl::Status HandleOneEvent( |
| ::{{ .Transport.Namespace }}::UnownedClientEnd<{{ . }}> client_end); |
| }; |
| {{- end }} |
| |
| template <> |
| class {{ .NaturalEventDispatcher }} final : |
| public ::fidl::internal::IncomingEventDispatcher<{{ .NaturalEventHandlerInterface }}> { |
| public: |
| explicit {{ .NaturalEventDispatcher.Self }}({{ .NaturalEventHandlerInterface }}* event_handler) |
| : IncomingEventDispatcher(event_handler) {} |
| |
| {{- if .Events }} |
| ::fidl::Status DispatchEvent( |
| ::fidl::IncomingMessage& msg, |
| internal::MessageStorageViewBase* storage_view) override; |
| {{- end }} |
| }; |
| {{- EndifFuchsia }} |
| {{- end }} |
| |
| |
| |
| {{- define "Protocol:EventHandler:NaturalMessagingSource" }} |
| {{- EnsureNamespace "" }} |
| {{- IfdefFuchsia }} |
| |
| {{ if .Transport.HasEvents }} |
| ::fidl::Status {{ .NaturalSyncEventHandler.NoLeading }}::HandleOneEvent( |
| ::{{ .Transport.Namespace }}::UnownedClientEnd<{{ . }}> client_end) { |
| {{ .IncomingEventsStorage }} event_storage; |
| {{ .NaturalEventDispatcher.NoLeading }} dispatcher{this}; |
| return HandleOneEventImpl_(client_end.channel(), event_storage.view(), dispatcher); |
| } |
| {{- end }} |
| |
| {{- if .Events }} |
| ::fidl::Status |
| {{ .NaturalEventDispatcher.NoLeading }}::DispatchEvent( |
| ::fidl::IncomingMessage& msg, |
| ::fidl::internal::MessageStorageViewBase* storage_view) { |
| switch (msg.header()->ordinal) { |
| {{- range .Events }} |
| case {{ .OrdinalName }}: |
| { |
| ::fitx::result decoded = ::fidl::internal::DecodeTransactionalMessage |
| {{- if .HasResponsePayload }}<{{ .ResponsePayload }}>{{ end -}}(std::move(msg)); |
| if (decoded.is_error()) { |
| return decoded.error_value(); |
| } |
| if (event_handler()) { |
| {{ .NaturalEvent }} event |
| {{- if .HasResponsePayload }} |
| = {{ .NaturalEventConverter }}::FromDomainObject(std::move(decoded.value())) |
| {{- end }}; |
| event_handler()->{{ .Name }}(event); |
| } |
| return ::fidl::Status::Ok(); |
| } |
| {{- end }} |
| default: |
| return ::fidl::Status::UnknownOrdinal(); |
| } |
| } |
| {{- end }} |
| |
| {{- EndifFuchsia }} |
| {{- end }} |