grpc-labview icon indicating copy to clipboard operation
grpc-labview copied to clipboard

Server Template and scripting Improvement

Open navinsubramani opened this issue 4 years ago • 3 comments

Need:

  • [ ] No breakage or smooth update of existing code during proto update
  • [ ] Less boilerplate code should be part of the template and user code
  • [ ] Ways to abstract the user code and template code

navinsubramani avatar Jan 31 '22 21:01 navinsubramani

route_guide_new.zip

This is one implementation where user code is separated from the generated code. Developed by modifying the route guide example.

  1. Created two libraries. One with sufix '_scriptedcode' which will be modified by the code generation, and another with '_usercode' which will have user logic. The '_scriptedcode' will contain all the proto definitions and gRPC related code, and '_usercode' will not be updated by code generation and will have only the logic
  2. Added dispatch methods for all proto functions and called them under Async or Sync engines.
  3. '_usercode' class will inherit from the '_scriptedcode' and will have implementations for all methods.

So, essentially user needs to worry about only the marked library below. image

So, the class structure is: image

navinsubramani avatar Jan 31 '22 21:01 navinsubramani

I second the third point for abstraction. In my application I created a wrapper class that has two top level poly VIs. "Get Request" and "Set Response"

Example Get Request wrapper vi image

Example Set Request wrapper VI image

This way the user of the library does not depend on the message type definitions and only the data I care about is on the input or output. Then the server application just calls two VIs and the developer needs to make sure Response and Request VIs match.

image

BShermanator avatar Feb 17 '22 19:02 BShermanator

I can also see a big benefit in separating user code from generated code. It is probably going to avoid issues with generation in the future.

The way I've seen this done in other languages is with the equivalent of interfaces. So the generated code would generate interfaces which the user code inherits. I know this isn't as straightforward in LabVIEW due to version restrictions and user familiarity.

This would enable another improvement I see though which is then the user code can be called in the sync and async case without the user having to do any additional work.

JamesWiresmith avatar Jun 28 '22 08:06 JamesWiresmith