Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ListServices in reflection #294

Merged
merged 12 commits into from
Aug 22, 2023
23 changes: 21 additions & 2 deletions src/lv_proto_server_reflection_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace grpc_labview
{
LVProtoServerReflectionService::LVProtoServerReflectionService() :
descriptor_pool_(grpc::protobuf::DescriptorPool::generated_pool()), services_(new std::vector<std::string>()) {
list_services_info_ptr = std::make_unique<ListServicesInfo>();
list_services_info_ptr->other_pool_services_ = (new std::vector<std::string>());
}

// Add the full names of registered services
Expand Down Expand Up @@ -80,10 +82,23 @@ namespace grpc_labview


void LVProtoServerReflectionService::AddFileDescriptorProto(const std::string& serializedProtoStr) {
// reflection_service_.get()->AddFileDescriptorProto(serializedProto);
FileDescriptorProto proto;
proto.ParseFromString(serializedProtoStr);
other_pool.BuildFile(proto);
list_services_info_ptr->other_pool_file_descriptor = other_pool.BuildFile(proto);
AddOtherPoolServices();
}

void LVProtoServerReflectionService::AddOtherPoolServices()
{
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());
}
}
}


Expand All @@ -97,6 +112,10 @@ namespace grpc_labview
grpc::reflection::v1alpha::ServiceResponse* service_response = response->add_service();
service_response->set_name(value);
}
for (const auto& value : *(list_services_info_ptr->other_pool_services_)) {
grpc::reflection::v1alpha::ServiceResponse* service_response = response->add_service();
service_response->set_name(value);
}

return Status::OK;
}
Expand Down
11 changes: 10 additions & 1 deletion src/lv_proto_server_reflection_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ namespace grpc_labview

void SetServiceList(const std::vector<std::string>* snames);
void AddService(const std::string serviceName);
void AddFileDescriptorProto(const std::string& serializedProtoStr);
void AddFileDescriptorProto(const std::string& serializedProtoStr);
void AddOtherPoolServices();

private:
Status ListService(ServerContext* context, grpc::reflection::v1alpha::ListServiceResponse* response);
Expand All @@ -70,5 +71,13 @@ 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;
};
}
Loading