blob: 3a5723fcbd17e2eb78c18eeee4aca999733524d4 [file] [log] [blame]
{{/*
// Copyright 2019 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:Dispatcher:WireMessagingHeader" }}
{{- EnsureNamespace "" }}
template<>
struct {{ .WireServerDispatcher }} final {
{{ .WireServerDispatcher.Self }}() = delete;
static ::fidl::DispatchResult TryDispatch({{ .WireServer }}* impl, ::fidl::IncomingHeaderAndMessage& msg,
internal::MessageStorageViewBase* storage_view,
::fidl::Transaction* txn);
static void Dispatch({{ .WireServer }}* impl, ::fidl::IncomingHeaderAndMessage&& msg,
internal::MessageStorageViewBase* storage_view,
::fidl::Transaction* txn);
private:
static const ::fidl::internal::MethodEntry entries_[];
static const ::fidl::internal::MethodEntry* entries_end_;
{{- if .HandlesOneWayUnknownInteractions }}
static const ::fidl::internal::UnknownMethodHandlerEntry unknown_method_handler_entry_;
{{- else }}
static constexpr const ::fidl::internal::UnknownMethodHandlerEntry& unknown_method_handler_entry_ =
::fidl::internal::UnknownMethodHandlerEntry::kClosedProtocolHandlerEntry;
{{- end }}
};
{{- end }}
{{- define "Protocol:Dispatcher:WireMessagingSource" }}
{{ EnsureNamespace "" }}
constexpr ::fidl::internal::MethodEntry {{ .WireServerDispatcher.NoLeading }}::entries_[] = {
{{- range .ClientMethods }}
{ {{ .OrdinalName }},
[](void* interface, ::fidl::EncodedMessage& msg, ::fidl::WireFormatMetadata metadata,
internal::MessageStorageViewBase* storage_view, ::fidl::Transaction* txn) {
{{- if eq .Transport.Name "Driver" }}
{{/* |arena| needs to be declared before |decoded| so that |decoded| is destructed first.
This is for the case where handles used in |decoded| are stored in |arena|. */}}
fdf::Arena arena(::fidl::internal::TakeDriverArenaFromStorage(storage_view));
{{- end }}
{{- if .HasRequestPayload }}
::fit::result decoded = ::fidl::StandaloneInplaceDecode<{{ .RequestPayload }}>(
std::move(msg), metadata);
{{- else }}
::fit::result decoded = ::fidl::internal::DecodeTransactionalMessageWithoutBody(
msg, metadata);
{{- end }}
if (unlikely(!decoded.is_ok())) {
return decoded.error_value();
}
{{ .WireCompleter }}::Sync completer(txn);
reinterpret_cast<{{ $.WireServer }}*>(interface)->{{ .Name }}(
{{- if .HasRequestPayload }}
decoded.value().pointer(),
{{- end }}
{{- if eq .Transport.Name "Driver" }}
arena,
{{- end }}
completer
);
return ::fidl::Status::Ok();
},
},
{{- end }}
};
const ::fidl::internal::MethodEntry* {{ .WireServerDispatcher.NoLeading }}::entries_end_ =
&entries_[{{- len .ClientMethods -}}];
{{- if .HandlesOneWayUnknownInteractions }}
const ::fidl::internal::UnknownMethodHandlerEntry {{ .WireServerDispatcher.NoLeading }}::unknown_method_handler_entry_ = {
.openness = {{ .OpennessValue }},
.dispatch = [](void* interface, uint64_t method_ordinal,
::fidl::UnknownMethodType unknown_method_type, ::fidl::Transaction* txn) {
::fidl::UnknownMethodCompleter::Sync completer(txn);
static_cast<{{ .WireServer }}*>(interface)->handle_unknown_method(
{{ .UnknownMethodMetadata }} {
.method_ordinal = method_ordinal,
{{ if .HandlesTwoWayUnknownInteractions }}
.unknown_method_type = unknown_method_type,
{{ end }}
}, completer);
},
.send_reply = {{ .UnknownMethodReplySender }},
};
{{ end }}
::fidl::DispatchResult {{ .WireServerDispatcher.NoLeading }}::TryDispatch(
{{ .WireServer }}* impl, ::fidl::IncomingHeaderAndMessage& msg,
internal::MessageStorageViewBase* storage_view, ::fidl::Transaction* txn) {
return ::fidl::internal::TryDispatch(
impl, msg, storage_view, txn, entries_, entries_end_);
}
{{ EnsureNamespace "" }}
void {{ .WireServerDispatcher.NoLeading }}::Dispatch(
{{- .WireServer }}* impl, ::fidl::IncomingHeaderAndMessage&& msg,
internal::MessageStorageViewBase* storage_view, ::fidl::Transaction* txn) {
::fidl::internal::Dispatch(impl, msg, storage_view, txn, entries_, entries_end_,
&unknown_method_handler_entry_);
}
{{- EnsureNamespace "" }}
void {{ .WireServer.NoLeading }}::dispatch_message(
::fidl::IncomingHeaderAndMessage&& msg, ::fidl::Transaction* txn,
::fidl::internal::MessageStorageViewBase* storage_view) {
{{ .WireServerDispatcher }}::Dispatch(this, std::move(msg), storage_view, txn);
}
{{ .WireServer.NoLeading }}::Handler {{ .WireServer.NoLeading }}::bind_handler({{ .Dispatcher }}* dispatcher) {
return [impl=this, dispatcher=dispatcher]({{ .ServerEnd }} request) {
(void) {{ .BindServer }}(dispatcher, std::move(request), impl);
};
}
{{- end }}
{{- define "Protocol:Dispatcher:NaturalMessagingHeader" }}
{{- EnsureNamespace "" }}
template<>
struct {{ .NaturalServerDispatcher }} final {
{{ .NaturalServerDispatcher.Self }}() = delete;
static void Dispatch({{ .NaturalServer }}* impl, ::fidl::IncomingHeaderAndMessage&& msg,
internal::MessageStorageViewBase* storage_view,
::fidl::Transaction* txn);
private:
static const ::fidl::internal::MethodEntry entries_[];
static const ::fidl::internal::MethodEntry* entries_end_;
{{- if .HandlesOneWayUnknownInteractions }}
static const ::fidl::internal::UnknownMethodHandlerEntry unknown_method_handler_entry_;
{{- else }}
static constexpr const ::fidl::internal::UnknownMethodHandlerEntry& unknown_method_handler_entry_ =
::fidl::internal::UnknownMethodHandlerEntry::kClosedProtocolHandlerEntry;
{{- end }}
};
{{- end }}
{{- define "Protocol:Dispatcher:NaturalMessagingSource" }}
{{ EnsureNamespace "" }}
constexpr ::fidl::internal::MethodEntry {{ .NaturalServerDispatcher.NoLeading }}::entries_[] = {
{{- range .ClientMethods }}
{ {{ .OrdinalName }},
[](void* interface, ::fidl::EncodedMessage& msg, ::fidl::WireFormatMetadata metadata,
internal::MessageStorageViewBase* storage_view, ::fidl::Transaction* txn) {
{{- if .HasRequestPayload }}
::fit::result decoded = ::fidl::StandaloneDecode<{{ .RequestPayload }}>(
std::move(msg), metadata);
{{- else }}
::fit::result decoded = ::fidl::internal::DecodeTransactionalMessageWithoutBody(
msg, metadata);
{{- end }}
if (decoded.is_error()) {
return decoded.error_value();
}
{{ .NaturalCompleter }}::Sync completer(txn);
static_cast<{{ $.NaturalServer }}*>(interface)->{{ .Name }}(
{{ if .HasRequestPayload }}decoded.value(),{{ end }}
completer);
return ::fidl::Status::Ok();
},
},
{{- end }}
};
const ::fidl::internal::MethodEntry* {{ .NaturalServerDispatcher.NoLeading }}::entries_end_ =
&entries_[{{- len .ClientMethods -}}];
{{- if .HandlesOneWayUnknownInteractions }}
const ::fidl::internal::UnknownMethodHandlerEntry {{ .NaturalServerDispatcher.NoLeading }}::unknown_method_handler_entry_ = {
.openness = {{ .OpennessValue }},
.dispatch = [](void* interface, uint64_t method_ordinal,
::fidl::UnknownMethodType unknown_method_type, ::fidl::Transaction* txn) {
::fidl::UnknownMethodCompleter::Sync completer(txn);
static_cast<{{ .NaturalServer }}*>(interface)->handle_unknown_method(
{{ .UnknownMethodMetadata }} {
.method_ordinal = method_ordinal,
{{ if .HandlesTwoWayUnknownInteractions }}
.unknown_method_type = unknown_method_type,
{{ end }}
}, completer);
},
.send_reply = {{ .UnknownMethodReplySender }},
};
{{ end }}
{{ EnsureNamespace "" }}
void {{ .NaturalServerDispatcher.NoLeading }}::Dispatch(
{{- .NaturalServer }}* impl, ::fidl::IncomingHeaderAndMessage&& msg,
internal::MessageStorageViewBase* storage_view, ::fidl::Transaction* txn) {
::fidl::internal::Dispatch(impl, msg, storage_view, txn, entries_, entries_end_, &unknown_method_handler_entry_);
}
{{- EnsureNamespace "" }}
void {{ .NaturalServer.NoLeading }}::dispatch_message(
::fidl::IncomingHeaderAndMessage&& msg, ::fidl::Transaction* txn,
::fidl::internal::MessageStorageViewBase* storage_view) {
{{ .NaturalServerDispatcher }}::Dispatch(this, std::move(msg), storage_view, txn);
}
{{- end }}