Skip to content

Commit

Permalink
Implement ListServices in reflection (#294)
Browse files Browse the repository at this point in the history
* implement ListServices()
  • Loading branch information
pratheekshasn authored Aug 22, 2023
1 parent 715e905 commit fd474c4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
22 changes: 20 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,7 @@ namespace grpc_labview
{
LVProtoServerReflectionService::LVProtoServerReflectionService() :
descriptor_pool_(grpc::protobuf::DescriptorPool::generated_pool()), services_(new std::vector<std::string>()) {
other_pool_services_info_ptr = std::make_unique<OtherPoolServiceInfo>();
}

// Add the full names of registered services
Expand Down Expand Up @@ -80,10 +81,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);
other_pool_services_info_ptr->other_pool_file_descriptor = other_pool.BuildFile(proto);
AddOtherPoolServices();
}

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


Expand All @@ -97,6 +111,10 @@ namespace grpc_labview
grpc::reflection::v1alpha::ServiceResponse* service_response = response->add_service();
service_response->set_name(value);
}
for (const auto value : other_pool_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 OtherPoolServiceInfo
{
const grpc::protobuf::FileDescriptor* other_pool_file_descriptor;
std::vector<std::string> other_pool_services_;
};

std::unique_ptr<OtherPoolServiceInfo> other_pool_services_info_ptr;
};
}

0 comments on commit fd474c4

Please sign in to comment.