Skip to content

Commit

Permalink
Reflection service changes (#253)
Browse files Browse the repository at this point in the history
* Adding basic cpp files for reflection. This needs a major refactor.

* Removing source only on VIs.

* First pass of refactor for the cpp code.

* Adding a "Generated Descriptors" placeholder VI in the server template.

* Adding proto serializer and descriptor VI generator VI.

* Adding Serialize Proto, making changes to main.vi

* fixing linker errors in Gen Descriptor VI

* Adding register descriptors VI for running the server.

* Updating the server template library to include the register descriptors VI.

* Adding the descriptor registers call during run service.

* Fixing linker errors while building a VIPM package.

* Fix icons. Fix descriptor generation to not create virtual folders.

* Fix linux build error

* Fixing error while building a server when one already exists.

* Fixing implementation for the extensions APIs.

---------

Co-authored-by: chethan.ravindranath <[email protected]>
Co-authored-by: Chakith Pattar <[email protected]>
  • Loading branch information
3 people authored May 5, 2023
1 parent 7ed39a9 commit f0e6881
Show file tree
Hide file tree
Showing 21 changed files with 504 additions and 30 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ endif()
#----------------------------------------------------------------------
# Include generated *.pb.h files
#----------------------------------------------------------------------
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "./src" "./third_party/grpc")
include_directories("${CMAKE_CURRENT_BINARY_DIR}" "./src" "./third_party/grpc" "${CMAKE_CURRENT_BINARY_DIR}/gens")

#----------------------------------------------------------------------
# LabVIEW support for grpc and protobuf
Expand All @@ -67,6 +67,8 @@ add_library(labview_grpc_server SHARED
src/any_support.cc
src/unpacked_fields.cc
src/grpc_load.cc
src/lv_proto_server_reflection_service.cc
src/lv_proto_server_reflection_plugin.cc
)
target_link_libraries(labview_grpc_server
${_REFLECTION}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
</Item>
<Item Name="Register gRPC Messages.vi" Type="VI" URL="../RPC Messages/Register gRPC Messages.vi"/>
</Item>
<Item Name="Generated Descriptors" Type="Folder">
<Item Name="Generated Descriptors.vi" Type="VI" URL="../Generated Descriptors/Generated Descriptors.vi"/>
</Item>
<Item Name="Run Service.vi" Type="VI" URL="../Run Service.vi"/>
<Item Name="Register Descriptors.vi" Type="VI" URL="../RPC Messages/Register Descriptors.vi"/>
</Library>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<VI_Package_Builder_Settings Version="2020.1" Created_Date="2021-10-29 00:29:27" Modified_Date="2023-04-27 06:00:45" Creator="navin" Comments="" ID="e18e1be35c57058b9bc69efe4291503d">
<VI_Package_Builder_Settings Version="2020.1" Created_Date="2021-10-29 00:29:27" Modified_Date="2023-02-02 03:00:03" Creator="navin" Comments="" ID="7cf5ae47e3fcc3bc66900503728c85df">
<Library_General_Settings>
<Package_File_Name>NI_lib_gRPC_Server_and_Client_Template[2]</Package_File_Name>
<Library_Version>1.0.0.2</Library_Version>
<Library_Version>1.0.0.1</Library_Version>
<Auto_Increment_Version>false</Auto_Increment_Version>
<Library_Source_Folder>..</Library_Source_Folder>
<Library_Output_Folder>..\..\Builds</Library_Output_Folder>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@
<Item Name="Basic Generate LV Icon Text Layer.vi" Type="VI" URL="../Top Level API/Basic Generate LV Icon Text Layer.vi"/>
<Item Name="UpdateLibraryFromTemplate.vi" Type="VI" URL="../Top Level API/UpdateLibraryFromTemplate.vi"/>
</Item>
<Item Name="Descriptors" Type="Folder">
<Item Name="Generate Descriptor VI.vi" Type="VI" URL="../Top Level API/Generate Descriptor VI.vi"/>
</Item>
</Item>
<Item Name="VI API" Type="Folder">
<Item Name="Block Diagram" Type="Folder">
Expand Down Expand Up @@ -300,6 +303,7 @@
<Item Name="Create Types.vi" Type="VI" URL="../Proto Parser API/LabVIEW API/Create Types.vi"/>
<Item Name="Create Methods.vi" Type="VI" URL="../Proto Parser API/LabVIEW API/Create Methods.vi"/>
<Item Name="Create Method Metadata.vi" Type="VI" URL="../Proto Parser API/LabVIEW API/Create Method Metadata.vi"/>
<Item Name="Serialize Proto.vi" Type="VI" URL="../Proto Parser API/LabVIEW API/Serialize Proto.vi"/>
</Item>
<Item Name="Animation API" Type="Folder">
<Item Name="Animation.vi" Type="VI" URL="../Animation API/Animation.vi"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<VI_Package_Builder_Settings Version="2020.1" Created_Date="2021-10-29 00:29:27" Modified_Date="2023-04-27 06:00:40" Creator="navin" Comments="" ID="8e4f6bed3653d76fc3ce0281e43a8171">
<VI_Package_Builder_Settings Version="2020.1" Created_Date="2021-10-29 00:29:27" Modified_Date="2023-02-02 02:59:58" Creator="navin" Comments="" ID="ed58f73d10458282bc0872db42434991">
<Library_General_Settings>
<Package_File_Name>NI_lib_gRPC_Server_and_Client_Template</Package_File_Name>
<Library_Version>1.0.0.2</Library_Version>
<Library_Version>1.0.0.1</Library_Version>
<Auto_Increment_Version>false</Auto_Increment_Version>
<Library_Source_Folder>..</Library_Source_Folder>
<Library_Output_Folder>..\..\Builds</Library_Output_Folder>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<VI_Package_Builder_Settings Version="2020.1" Created_Date="2021-11-19 18:41:05" Modified_Date="2023-04-27 06:00:51" Creator="navin" Comments="" ID="ac16a5b91741c33fa146b600846a1ff5">
<VI_Package_Builder_Settings Version="2020.1" Created_Date="2021-11-19 18:41:05" Modified_Date="2023-02-02 03:00:08" Creator="navin" Comments="" ID="6e91903b62849a395c8cf8f9a9a02ea1">
<Library_General_Settings>
<Package_File_Name>NI_lib_LabVIEW_gRPC_Servicer</Package_File_Name>
<Library_Version>1.0.0.2</Library_Version>
<Library_Version>1.0.0.1</Library_Version>
<Auto_Increment_Version>false</Auto_Increment_Version>
<Library_Source_Folder>..</Library_Source_Folder>
<Library_Output_Folder>..\..\Builds</Library_Output_Folder>
Expand Down Expand Up @@ -241,7 +241,7 @@
<Path>..\Servicer</Path>
<VI_Title/>
</Items_Data>
<GUID>F8C87FC5B6A37D1EFC36F04105394AD7</GUID>
<GUID>D87BB706706E4B99F50EAB56152B9768</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>0</Parent_Palette_Index>
Expand Down Expand Up @@ -290,7 +290,7 @@
<Path>..\iService\Server API</Path>
<VI_Title/>
</Items_Data>
<GUID>5ADB509A8487C9CC9FAB3E868C0327D4</GUID>
<GUID>CFD1E279E77CC47BA806A6862C4CF078</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>0</Parent_Palette_Index>
Expand Down Expand Up @@ -353,7 +353,7 @@
<Path>..\Servicer\Run Servicer.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>405415C41501F8DF54DC26E22C55B6D5</GUID>
<GUID>5BD21BBB06EF63857227D15C2D34F0E8</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>1</Parent_Palette_Index>
Expand Down Expand Up @@ -402,7 +402,7 @@
<Path>..\ServiceBase\Accessors\Read Server Stop.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>FA39D316701927042943ECC790A496F8</GUID>
<GUID>8566A24E94C591A64134356D18D94A79</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>1</Parent_Palette_Index>
Expand Down Expand Up @@ -507,7 +507,7 @@
<Path>..\ServiceBase\Server API\Start.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>7FDFC9CDD377A26475E3E4A72367550B</GUID>
<GUID>9397605CCA6040AC6FE9536B62FD1805</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>2</Parent_Palette_Index>
Expand Down Expand Up @@ -598,7 +598,7 @@
<Path>..\Servicer\Accessors\Server State</Path>
<VI_Title/>
</Items_Data>
<GUID>BA8765C45FE659CD0A46AF8226793998</GUID>
<GUID>1ACFAC158FBB48E30C32138FC8176FB7</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>2</Parent_Palette_Index>
Expand Down Expand Up @@ -675,7 +675,7 @@
<Path>..\Servicer\Server API\Stop Server.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>CB82202676054581AF80C3C879582DA6</GUID>
<GUID>F172BF9FF2D353844D68445C81867D97</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>5</Parent_Palette_Index>
Expand Down Expand Up @@ -724,7 +724,7 @@
<Path>..\Servicer\Accessors\gRPC ID\Set gRPC ID.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>C1BD04506D71A9E8D971EC73BC55447D</GUID>
<GUID>EDA094C1B83BD681D626AC4CCF463A0E</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>5</Parent_Palette_Index>
Expand Down Expand Up @@ -773,7 +773,7 @@
<Path>..\Servicer\Accessors\Server Address\Set Server Address.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>48374C4259DE23936FB3A445A56C82EF</GUID>
<GUID>7AD702B3EF8C6F1AEF7E0EB9430EE992</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>5</Parent_Palette_Index>
Expand Down Expand Up @@ -822,7 +822,7 @@
<Path>..\Servicer\Accessors\Server Certificate File\Set Server Certificate File.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>FC4697E8E0A90EF007839B89DB5E6E71</GUID>
<GUID>29DEEEABC57935C661C119CEB28286AE</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>5</Parent_Palette_Index>
Expand Down Expand Up @@ -871,7 +871,7 @@
<Path>..\Servicer\Accessors\Server Key File\Set Server Key File.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>FEBD1F52CBF569DBAC85DCA8245E7547</GUID>
<GUID>149D78BB41DC298EE666D347EADA650C</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>5</Parent_Palette_Index>
Expand Down Expand Up @@ -948,7 +948,7 @@
<Path>..\Servicer\Accessors\Server State\Set Server State.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>FEA285A957364CF1DDFE6129D575CF6D</GUID>
<GUID>C6FFF4FA473B21BDAB40AC17F45537B9</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>11</Parent_Palette_Index>
Expand Down Expand Up @@ -997,7 +997,7 @@
<Path>..\Servicer\Accessors\Server State\State Ref\Set Server State Ref.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>5FF65C5116B7C322ED128392754C4140</GUID>
<GUID>1FD085401925F3F313DCF2D60F2BDA88</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>11</Parent_Palette_Index>
Expand Down Expand Up @@ -1046,7 +1046,7 @@
<Path>..\Servicer\Accessors\Server State\State UE\Set Server State UE.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>7B5D50FA31D2DE89E8A77462F523ECE6</GUID>
<GUID>B6E1DA0C7D1AB27D0D1C009B811BB70E</GUID>
</Functions_Palette_Data>
</Library_Palette_Definition>
</VI_Package_Builder_Settings>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<VI_Package_Builder_Settings Version="2020.1" Created_Date="2021-10-28 23:37:57" Modified_Date="2023-04-27 06:00:56" Creator="navin" Comments="" ID="25ad8bafd8ff4aa7e48dd4b8836bdfc1">
<VI_Package_Builder_Settings Version="2020.1" Created_Date="2021-10-28 23:37:57" Modified_Date="2023-02-02 03:00:13" Creator="navin" Comments="" ID="f42b37bc0d07a94f40abaaa91fbfbc9e">
<Library_General_Settings>
<Package_File_Name>NI_lib_LabVIEW_gRPC_Library</Package_File_Name>
<Library_Version>1.0.0.2</Library_Version>
<Library_Version>1.0.0.1</Library_Version>
<Auto_Increment_Version>false</Auto_Increment_Version>
<Library_Source_Folder>..</Library_Source_Folder>
<Library_Output_Folder>..\..\Builds</Library_Output_Folder>
Expand Down Expand Up @@ -252,7 +252,7 @@ https://github.com/ni/grpc-labview</Description>
<Path>..\Server API</Path>
<VI_Title/>
</Items_Data>
<GUID>9D0EF23B67AA7B071CEF1E8CE20E372E</GUID>
<GUID>101D68177F2E398F64034D7BE0119983</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>0</Parent_Palette_Index>
Expand Down Expand Up @@ -371,7 +371,7 @@ https://github.com/ni/grpc-labview</Description>
<Path>..\Client API\Client Cancel Call.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>C704F760745F4FEB95120165F04C0CDF</GUID>
<GUID>409DF69FAE897C5938C3EEE3E0F87C62</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>0</Parent_Palette_Index>
Expand Down Expand Up @@ -490,7 +490,7 @@ https://github.com/ni/grpc-labview</Description>
<Path>..\Server API\UnpackFromBuffer.vim</Path>
<VI_Title/>
</Items_Data>
<GUID>C67D276E34C5CE6412C7E819A1E466EA</GUID>
<GUID>490CCD3D31B01828111B030AC58E2292</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>2</Parent_Palette_Index>
Expand Down Expand Up @@ -721,7 +721,7 @@ https://github.com/ni/grpc-labview</Description>
<Path>..\Server API\Message Requests\Write Call Response.vim</Path>
<VI_Title/>
</Items_Data>
<GUID>B0EA744EE4A278FD7100A66FA60180A2</GUID>
<GUID>8D61FF79D1C4E21719DA210F469CB3E7</GUID>
</Functions_Palette_Data>
<Functions_Palette_Data>
<Parent_Palette_Index>2</Parent_Palette_Index>
Expand Down Expand Up @@ -840,7 +840,7 @@ https://github.com/ni/grpc-labview</Description>
<Path>..\Server API\Server\Stop Server.vi</Path>
<VI_Title/>
</Items_Data>
<GUID>D789E89BF5696E057BC5094E8F912656</GUID>
<GUID>45A3724B4A3F017960D198BCB6866A18</GUID>
</Functions_Palette_Data>
</Library_Palette_Definition>
</VI_Package_Builder_Settings>
13 changes: 11 additions & 2 deletions src/grpc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
#include <fstream>
#include <iostream>
#include <future>
#include <grpcpp/impl/server_initializer.h>
#include "lv_proto_server_reflection_plugin.h"

//---------------------------------------------------------------------
//---------------------------------------------------------------------
using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using grpc::ServerInitializer;

namespace grpc_labview
{
Expand Down Expand Up @@ -182,7 +185,8 @@ namespace grpc_labview
}

grpc::EnableDefaultHealthCheckService(true);
grpc::reflection::InitProtoReflectionServerBuilderPlugin();
InitLVProtoReflectionServerBuilderPlugin();
// grpc::reflection::InitProtoReflectionServerBuilderPlugin();
ServerBuilder builder;

std::shared_ptr<grpc::ServerCredentials> creds;
Expand Down Expand Up @@ -211,6 +215,10 @@ namespace grpc_labview

_rpcService = std::unique_ptr<grpc::AsyncGenericService>(new grpc::AsyncGenericService());
builder.RegisterAsyncGenericService(_rpcService.get());

// auto _reflectionService = std::unique_ptr<grpc_labview::LVProtoServerReflectionService>(new grpc_labview::LVProtoServerReflectionService());
// builder.RegisterService(_reflectionService.get());

auto cq = builder.AddCompletionQueue();

_server = builder.BuildAndStart();
Expand Down Expand Up @@ -242,5 +250,6 @@ namespace grpc_labview
_runThread->join();
_server = nullptr;
}
}
LVProtoServerReflectionPlugin::GetInstance()->DeleteInstance();
}
}
80 changes: 80 additions & 0 deletions src/lv_proto_server_reflection_plugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//---------------------------------------------------------------------
//---------------------------------------------------------------------
#include <lv_proto_server_reflection_plugin.h>
#include <grpcpp/impl/server_initializer.h>
#include <grpcpp/server_builder.h>
#include <lv_interop.h>
//---------------------------------------------------------------------
//---------------------------------------------------------------------
using grpc::ServerContext;
using grpc::Status;
using grpc::ServerInitializer;
using grpc::ServerBuilder;

namespace grpc_labview
{
LVProtoServerReflectionPlugin* LVProtoServerReflectionPlugin::m_instance = nullptr;

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);
}

LVProtoServerReflectionPlugin* LVProtoServerReflectionPlugin::GetInstance() {
if (m_instance == nullptr)
m_instance = new LVProtoServerReflectionPlugin();
return m_instance;
}

void LVProtoServerReflectionPlugin::DeleteInstance() {
m_instance = nullptr;
}

std::unique_ptr< ::grpc::ServerBuilderPlugin> CreateLVProtoReflection() {
return std::unique_ptr< ::grpc::ServerBuilderPlugin>(
LVProtoServerReflectionPlugin::GetInstance());
}

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);
LVProtoServerReflectionPlugin::GetInstance()->AddFileDescriptorProto(serializedDescriptorStr);
}
}
Loading

0 comments on commit f0e6881

Please sign in to comment.