#include <grpc/support/port_platform.h>
#include <grpcpp/ext/channelz_service_plugin.h>
#include <grpcpp/impl/server_builder_plugin.h>
#include <grpcpp/impl/server_initializer.h>
#include <grpcpp/server.h>
#include "src/cpp/server/channelz/channelz_service.h"
namespace grpc {
namespace channelz {
namespace experimental {
class ChannelzServicePlugin : public ::grpc::ServerBuilderPlugin {
public:
ChannelzServicePlugin() : channelz_service_(new grpc::ChannelzService()) {}
grpc::string name() override { return "channelz_service"; }
void InitServer(grpc::ServerInitializer* si) override {
si->RegisterService(channelz_service_);
}
void Finish(grpc::ServerInitializer* si) override {}
void ChangeArguments(const grpc::string& name, void* value) override {}
bool has_sync_methods() const override {
if (channelz_service_) {
return channelz_service_->has_synchronous_methods();
}
return false;
}
bool has_async_methods() const override {
if (channelz_service_) {
return channelz_service_->has_async_methods();
}
return false;
}
private:
std::shared_ptr<grpc::ChannelzService> channelz_service_;
};
static std::unique_ptr< ::grpc::ServerBuilderPlugin>
CreateChannelzServicePlugin() {
return std::unique_ptr< ::grpc::ServerBuilderPlugin>(
new ChannelzServicePlugin());
}
void InitChannelzService() {
static bool already_here = false;
if (already_here) return;
already_here = true;
::grpc::ServerBuilder::InternalAddPluginFactory(&CreateChannelzServicePlugin);
}
} } }