{%- set service = model.interfaces[0] -%}
// GENERATED FILE - DO NOT EDIT.
// Produced by clang-rpc-gen from an annotated C++ header. Re-run codegen
// instead of hand-editing this file; it will be overwritten on the next build.
#pragma once

#include "{{ proto_basename }}.grpc.pb.h"
#include "{{ header_include }}"
{% if service.keyed_by is not none %}
#include "rpc/InstanceRegistry.hh"
{% endif %}
{% if service.signals %}
#include "rpc/EventQueue.hh"
{% endif %}

{% if adapter_namespace %}
namespace {{ adapter_namespace }}
{
{% endif -%}
class {{ impl_class_name }} final : public ::{{ service_cpp_ns }}::{{ service.service_name }}::Service
{
public:
{% if service.keyed_by is not none %}
  // {{ service.cxx_qualified_class }} has multiple live instances; the caller supplies a
  // registry that instances register themselves into (see rpc::InstanceRegistry),
  // and each RPC resolves its target from the request's `id` field — the gRPC
  // analog of DBus's per-object-path routing.
  explicit {{ impl_class_name }}(::rpc::InstanceRegistry<{{ model.types[service.keyed_by.type_id].cxx.base_spelling }}, {{ service.cxx_qualified_class }}> &registry){% if split_proto_types %};{% else %}
    : registry_(registry)
  {
  }{% endif %}
{% else %}
  explicit {{ impl_class_name }}({{ service.cxx_qualified_class }} &impl){% if split_proto_types %};{% else %}
    : impl_(impl)
  {
  }{% endif %}
{% endif %}

{% for method in service.methods %}
  ::grpc::Status {{ method.rpc_name }}(::grpc::ServerContext *context,
                                 const ::{{ types_cpp_ns }}::{{ method.rpc_name }}Request *request,
                                 ::{{ types_cpp_ns }}::{{ method.rpc_name }}Response *response) override;
{% endfor %}

{% for signal in service.signals %}
  ::grpc::Status {{ signal.rpc_name }}(::grpc::ServerContext *context,
                                 const ::{{ types_cpp_ns }}::{{ signal.rpc_name }}Request *request,
                                 ::grpc::ServerWriter<::{{ types_cpp_ns }}::{{ signal.rpc_name }}Event> *writer) override;
{% endfor %}

private:
{% if service.keyed_by is not none %}
  ::rpc::InstanceRegistry<{{ model.types[service.keyed_by.type_id].cxx.base_spelling }}, {{ service.cxx_qualified_class }}> &registry_;
{% else %}
  {{ service.cxx_qualified_class }} &impl_;
{% endif %}
{% if split_proto_types %}
  [[maybe_unused]] const void *const service_descriptor_anchor_;
{% endif -%}
};{{- "" -}}
{% if adapter_namespace %}

} // namespace {{ adapter_namespace }}
{% endif -%}
