94 lines
2.9 KiB
C++
94 lines
2.9 KiB
C++
#pragma once
|
|
#include "{{filename name}}.pb.h"
|
|
#include "lib/api/public/ApiServer.h"
|
|
#include "lib/utils/bts_export.h"
|
|
#include <string>
|
|
#include <functional>
|
|
#include <vector>
|
|
#include <set>
|
|
#include <memory>
|
|
|
|
namespace bts { namespace api {
|
|
class ServiceContext;
|
|
class AuthToken;
|
|
}}
|
|
|
|
{{ns-open package}}
|
|
|
|
// Forward declaractions
|
|
{{#each message_type}}
|
|
class {{name}};{{/each}}
|
|
|
|
{{#each service}}
|
|
// {{comment}}
|
|
class Authenticated{{name}}Base : public bts::api::ApiServer {
|
|
public:
|
|
{{#each method}}
|
|
{{#if server_streaming}}
|
|
typedef std::function<void(const std::vector<{{output_type_cpp}}>*, const std::vector<{{output_type_cpp}}>*, std::set<{{key_type.cpptype}}>*)> {{cap name}}Publisher;
|
|
typedef bts::api::StatefulPublisher<{{output_type_cpp}}, {{key_type.cpptype}}> {{cap name}}StatefulPublisher;
|
|
{{/if}}
|
|
{{/each}}
|
|
|
|
protected:
|
|
Authenticated{{name}}Base(bts::api::ServiceContext& context, const std::string& qualifier="");
|
|
|
|
const char* name() const override;
|
|
|
|
{{#each method}}
|
|
{{#if server_streaming}}
|
|
{{cap name}}Publisher make_{{name}}_publisher(const std::string& qualifier) const { return make_{{name}}_publisher(qualifier.c_str()); }
|
|
{{cap name}}Publisher make_{{name}}_publisher(const char* qualifier=nullptr) const;
|
|
{{cap name}}StatefulPublisher make_{{name}}_stateful_publisher(const char* qualifier=nullptr) const;
|
|
|
|
virtual void allow_{{name}}(const bts::api::AuthToken& token, const std::string& qualifier, const api::Response<bts::api::StreamAccessResponse>& reply);
|
|
|
|
{{else}}
|
|
|
|
// {{comment}}
|
|
virtual void {{name}}(
|
|
const api::AuthToken& token,
|
|
const {{input_type_cpp}}& request,
|
|
const api::Response<{{output_type_cpp}}>& reply) = 0;
|
|
{{/if}}
|
|
{{/each}}
|
|
|
|
enum ServiceMethods {
|
|
SYS_PING = -1,
|
|
{{#each method}}
|
|
{{upper name}} = {{@index}},
|
|
{{/each}}
|
|
};
|
|
|
|
{{#each method}}{{#if server_streaming}}
|
|
{{cap name}}Publisher make_{{name}}_publisher(bts::api::TableHandle) const;
|
|
{{/if}}{{/each}}
|
|
|
|
private:
|
|
void dispatch(const bts::api::RequestHeader&, google::protobuf::io::ZeroCopyInputStream&, OnResponse) override;
|
|
};
|
|
|
|
// {{comment}}
|
|
class {{name}}Base : public Authenticated{{name}}Base {
|
|
protected:
|
|
{{name}}Base(bts::api::ServiceContext& context, const std::string& qualifier="") : Authenticated{{name}}Base(context, qualifier) {}
|
|
public:
|
|
{{#each method}}
|
|
{{#unless server_streaming}}
|
|
void {{name}}(
|
|
const api::AuthToken&,
|
|
const {{input_type_cpp}}& request,
|
|
const api::Response<{{output_type_cpp}}>& reply) override {
|
|
{{name}}(request, reply);
|
|
}
|
|
// {{comment}}
|
|
virtual void {{name}}(
|
|
const {{input_type_cpp}}& request,
|
|
const api::Response<{{output_type_cpp}}>& reply) = 0;
|
|
{{/unless}}
|
|
{{/each}}
|
|
};
|
|
|
|
{{/each}}
|
|
{{ns-close package}}
|