-
Notifications
You must be signed in to change notification settings - Fork 63
/
lv_proto_server_reflection_plugin.cc
71 lines (59 loc) · 2.7 KB
/
lv_proto_server_reflection_plugin.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//---------------------------------------------------------------------
//---------------------------------------------------------------------
#include <lv_proto_server_reflection_plugin.h>
#include <grpcpp/impl/server_initializer.h>
#include <grpcpp/server_builder.h>
#include <lv_interop.h>
#include <grpc_server.h>
//---------------------------------------------------------------------
//---------------------------------------------------------------------
using grpc::ServerContext;
using grpc::Status;
using grpc::ServerInitializer;
using grpc::ServerBuilder;
namespace grpc_labview
{
LVProtoServerReflectionPlugin::LVProtoServerReflectionPlugin() : reflection_service_(new grpc_labview::LVProtoServerReflectionService()) {
}
std::string LVProtoServerReflectionPlugin::name() {
return "LVProtoServerReflectionPlugin";
}
void LVProtoServerReflectionPlugin::InitServer(ServerInitializer* si) {
si->RegisterService(reflection_service_);
}
void LVProtoServerReflectionPlugin::Finish(ServerInitializer* si) {
reflection_service_->SetServiceList(si->GetServiceList());
}
void LVProtoServerReflectionPlugin::ChangeArguments(const ::std::string& name, void* value) {
// TODO
}
bool LVProtoServerReflectionPlugin::has_async_methods() const {
return false; // TODO
}
bool LVProtoServerReflectionPlugin::has_sync_methods() const {
return true; // TODO
}
void LVProtoServerReflectionPlugin::AddService(std::string serviceName) {
reflection_service_.get()->AddService(serviceName);
}
void LVProtoServerReflectionPlugin::AddFileDescriptorProto(const std::string& serializedProto) {
reflection_service_.get()->AddFileDescriptorProto(serializedProto);
}
std::unique_ptr< ::grpc::ServerBuilderPlugin> CreateLVProtoReflection() {
LVProtoServerReflectionPlugin* reflectionPluginInstance = new LVProtoServerReflectionPlugin();
reflectionPluginInstance->AddFileDescriptorProto(grpc_labview::ProtoDescriptorString::getInstance()->getDescriptor());
return std::unique_ptr< ::grpc::ServerBuilderPlugin>(reflectionPluginInstance);
}
void InitLVProtoReflectionServerBuilderPlugin() {
static struct Initialize {
Initialize() {
::grpc::ServerBuilder::InternalAddPluginFactory(&CreateLVProtoReflection);
}
} initializer;
}
LIBRARY_EXPORT void DeserializeReflectionInfo(grpc_labview::LStrHandle serializedFileDescriptor)
{
std::string serializedDescriptorStr = grpc_labview::GetLVString(serializedFileDescriptor);
grpc_labview::ProtoDescriptorString::getInstance()->setDescriptor(serializedDescriptorStr);
}
}