From 2fe61e8d1021db854e3c2ffdd0d4a69372bba909 Mon Sep 17 00:00:00 2001 From: Pratheeksha S N Date: Thu, 17 Aug 2023 14:33:05 +0530 Subject: [PATCH] implement ListServices() --- src/lv_proto_server_reflection_service.cc | 8 +++++++- src/lv_proto_server_reflection_service.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lv_proto_server_reflection_service.cc b/src/lv_proto_server_reflection_service.cc index f924765a..456f38b4 100644 --- a/src/lv_proto_server_reflection_service.cc +++ b/src/lv_proto_server_reflection_service.cc @@ -83,13 +83,19 @@ namespace grpc_labview // reflection_service_.get()->AddFileDescriptorProto(serializedProto); FileDescriptorProto proto; proto.ParseFromString(serializedProtoStr); - other_pool.BuildFile(proto); + other_pool_file_descriptor = other_pool.BuildFile(proto); } Status LVProtoServerReflectionService::ListService(ServerContext* context, grpc::reflection::v1alpha::ListServiceResponse* response) { + int numServices = other_pool_file_descriptor->service_count(); + for (int i = 0; i < numServices; ++i) { + const google::protobuf::ServiceDescriptor* serviceDescriptor = other_pool_file_descriptor->service(i); + services_->push_back(serviceDescriptor->full_name()); + } + if (services_ == nullptr) { return Status(grpc::StatusCode::NOT_FOUND, "Services not found."); } diff --git a/src/lv_proto_server_reflection_service.h b/src/lv_proto_server_reflection_service.h index 12f909d7..6cfe0b02 100644 --- a/src/lv_proto_server_reflection_service.h +++ b/src/lv_proto_server_reflection_service.h @@ -69,6 +69,7 @@ namespace grpc_labview const grpc::protobuf::DescriptorPool* descriptor_pool_; grpc::protobuf::DescriptorPool other_pool; + const grpc::protobuf::FileDescriptor* other_pool_file_descriptor; std::vector* services_; }; }