Server Design - ni/grpc-device GitHub Wiki

Server Initialization

Key functions:

  • main(): source/server/core_server.cpp
    • Parses command line options
    • Reads configuration file
    • Sets up signal handler / console control handler
    • Daemonizes (if applicable)
  • RunServer(): source/server/core_server.cpp
    • Manages the server's lifetime
    • Owns service objects
    • Builds and runs the server
    • Waits for server shutdown (triggered by signal handler)
    • System test equivalent: source/tests/system/device_server.cpp
  • register_all_services(): generated/register_all_services.cpp
    • Creates the resource repositories used to store session handles
    • Calls service registration functions
    • Collects service objects in a vector<shared_ptr<void>>
  • ${driver}::register_service(): generated/*/register_service.cpp
    • Creates the library object used to call the driver DLL
    • Creates the service object
    • Registers the service with the gRPC server builder

Server Objects

The core server uses shared_ptr to manage the lifetime of the services, libraries, and resource repositories. This diagram shows a simplified view of the graph of shared_ptr references.

graph TD
    %% register_all_services.cpp
    CoreServer --> SessionRepository
    CoreServer --> Service
    Service --> SessionResourceRepository
    SessionResourceRepository --> SessionRepository

    %% *_service_registrar.cpp
    Service --> Library

    %% *_service.cpp
    Service -. creates .-> CleanupLambda
    CleanupLambda --> Library
    SessionRepository --> CleanupLambda

    %% session_resource_repository.h
    CleanupLambda --> ResourceMap
Loading
⚠️ **GitHub.com Fallback** ⚠️