Skip to content

Commit

Permalink
create list of services only once
Browse files Browse the repository at this point in the history
  • Loading branch information
pratheekshasn committed Aug 21, 2023
1 parent 73a5120 commit d08ff97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 10 additions & 6 deletions src/lv_proto_server_reflection_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,22 @@ namespace grpc_labview
FileDescriptorProto proto;
proto.ParseFromString(serializedProtoStr);
list_services_info_ptr->other_pool_file_descriptor = other_pool.BuildFile(proto);

if (list_services_info_ptr->other_pool_file_descriptor != nullptr)
{
int numServices = list_services_info_ptr->other_pool_file_descriptor->service_count();
for (int i = 0; i < numServices; ++i)
{
const google::protobuf::ServiceDescriptor* serviceDescriptor = list_services_info_ptr->other_pool_file_descriptor->service(i);
list_services_info_ptr->other_pool_services_->push_back(serviceDescriptor->full_name());
}
}
}


Status LVProtoServerReflectionService::ListService(ServerContext* context,
grpc::reflection::v1alpha::ListServiceResponse* response) {

int numServices = list_services_info_ptr->other_pool_file_descriptor->service_count();
for (int i = 0; i < numServices; ++i) {
const google::protobuf::ServiceDescriptor* serviceDescriptor = list_services_info_ptr->other_pool_file_descriptor->service(i);
list_services_info_ptr->other_pool_services_->push_back(serviceDescriptor->full_name());
}

if (services_ == nullptr) {
return Status(grpc::StatusCode::NOT_FOUND, "Services not found.");
}
Expand Down
16 changes: 8 additions & 8 deletions src/lv_proto_server_reflection_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ namespace grpc_labview
class LVProtoServerReflectionService final : public grpc::reflection::v1alpha::ServerReflection::Service
{
public:
struct ListServicesInfo
{
const grpc::protobuf::FileDescriptor* other_pool_file_descriptor;
std::vector<std::string>* other_pool_services_;
};

std::unique_ptr<ListServicesInfo> list_services_info_ptr;

LVProtoServerReflectionService();

Status ServerReflectionInfo(
Expand Down Expand Up @@ -70,13 +78,5 @@ namespace grpc_labview
const grpc::protobuf::DescriptorPool* descriptor_pool_;
grpc::protobuf::DescriptorPool other_pool;
std::vector<std::string>* services_;

struct ListServicesInfo
{
const grpc::protobuf::FileDescriptor* other_pool_file_descriptor;
std::vector<std::string>* other_pool_services_;
};

std::unique_ptr<ListServicesInfo> list_services_info_ptr;
};
}

0 comments on commit d08ff97

Please sign in to comment.