in src/kudu/rpc/protoc-gen-krpc.cc [346:433]
void GenerateServiceIfHeader(Printer *printer,
SubstitutionContext *subs,
const FileDescriptor *file) const {
Print(printer, *subs,
"// THIS FILE IS AUTOGENERATED FROM $path$\n"
"\n"
"#ifndef KUDU_RPC_$upper_case$_SERVICE_IF_DOT_H\n"
"#define KUDU_RPC_$upper_case$_SERVICE_IF_DOT_H\n"
"\n"
"#include <string>\n"
"\n"
"#include \"kudu/gutil/ref_counted.h\"\n"
"#include \"kudu/rpc/service_if.h\"\n"
"\n"
"namespace google {\n"
"namespace protobuf {\n"
"class Message;\n"
"} // namespace protobuf\n"
"} // namespace google\n"
"\n"
"namespace kudu {\n"
"class MetricEntity;\n"
"namespace rpc {\n"
"class ResultTracker;\n"
"class RpcContext;\n"
"} // namespace rpc\n"
"} // namespace kudu\n"
"\n"
"$open_namespace$"
"\n");
for (int service_idx = 0; service_idx < file->service_count();
++service_idx) {
const ServiceDescriptor *service = file->service(service_idx);
subs->PushService(service);
Print(printer, *subs,
"class $service_name$If : public ::kudu::rpc::GeneratedServiceIf {\n"
" public:\n"
" explicit $service_name$If(const scoped_refptr<::kudu::MetricEntity>& entity,"
" const scoped_refptr<::kudu::rpc::ResultTracker>& result_tracker);\n"
" virtual ~$service_name$If();\n"
" std::string service_name() const override;\n"
" static std::string static_service_name();\n"
"\n"
);
set<string> authz_methods;
for (int method_idx = 0; method_idx < service->method_count();
++method_idx) {
const MethodDescriptor *method = service->method(method_idx);
subs->PushMethod(method);
Print(printer, *subs,
" virtual void $rpc_name$(const class $request$ *req,\n"
" class $response$ *resp, ::kudu::rpc::RpcContext *context) = 0;\n"
);
subs->Pop();
if (auto m = GetAuthzMethod(*method)) {
authz_methods.insert(m.get());
}
}
if (!authz_methods.empty()) {
printer->Print(
"\n\n"
" // Authorization methods\n"
" // ---------------------\n\n");
}
for (const string& m : authz_methods) {
printer->Print({ {"m", m} },
" virtual bool $m$(const google::protobuf::Message* req,\n"
" google::protobuf::Message* resp, ::kudu::rpc::RpcContext *context) = 0;\n");
}
Print(printer, *subs,
"\n"
"};\n"
);
subs->Pop(); // Service
}
Print(printer, *subs,
"\n"
"$close_namespace$\n"
"#endif\n");
}