LCOV - code coverage report
Current view: top level - OdbDesignServer/Services - OdbDesignServiceImpl.h (source / functions) Coverage Total Hit
Test: OdbDesign Test Coverage Lines: 85.7 % 14 12
Test Date: 2026-11-19 04:56:22 Functions: 100.0 % 2 2
Legend: Lines: hit not hit

            Line data    Source code
       1              : #pragma once
       2              : 
       3              : #include "odbdesign_export.h"
       4              : #include "service.grpc.pb.h"
       5              : #include "App/DesignCache.h"
       6              : #include "../Config/GrpcServiceConfig.h"
       7              : #include "DesignStreamWalker.h"
       8              : #include "StreamSpoolCache.h"
       9              : #include <memory>
      10              : #include <design.pb.h>
      11              : #include <featuresfile.pb.h>
      12              : #include <service.pb.h>
      13              : #include <standardfontsfile.pb.h>
      14              : #include <symbolname.pb.h>
      15              : #include <grpcpp/impl/status.h>
      16              : #include <grpcpp/server_context.h>
      17              : #include <grpcpp/support/sync_stream.h>
      18              : 
      19              : 
      20              : namespace OdbDesignServer {
      21              :     namespace Services {
      22              : 
      23              :         class OdbDesignServiceImpl final : public Odb::Grpc::OdbDesignService::Service {
      24              :         public:
      25              :             explicit OdbDesignServiceImpl(std::shared_ptr<Odb::Lib::App::DesignCache> cache,
      26              :                 std::shared_ptr<Config::GrpcServiceConfig> config = nullptr);
      27              : 
      28              :             grpc::Status GetDesign(grpc::ServerContext* context,
      29              :                 const Odb::Grpc::GetDesignRequest* request,
      30              :                 Odb::Lib::Protobuf::ProductModel::Design* response) override;
      31              : 
      32              :             grpc::Status GetDesignStream(grpc::ServerContext* context,
      33              :                 const Odb::Grpc::GetDesignRequest* request,
      34              :                 grpc::ServerWriter<Odb::Grpc::DesignChunk>* writer) override;
      35              : 
      36              :             grpc::Status GetLayerFeaturesStream(grpc::ServerContext* context,
      37              :                 const Odb::Grpc::GetLayerFeaturesRequest* request,
      38              :                 grpc::ServerWriter<Odb::Lib::Protobuf::FeaturesFile::FeatureRecord>* writer) override;
      39              : 
      40              :             grpc::Status GetLayerFeaturesBatchStream(grpc::ServerContext* context,
      41              :                 const Odb::Grpc::GetLayerFeaturesRequest* request,
      42              :                 grpc::ServerWriter<Odb::Grpc::FeatureRecordBatch>* writer) override;
      43              : 
      44              :             grpc::Status GetLayerSymbols(grpc::ServerContext* context,
      45              :                 const Odb::Grpc::GetLayerSymbolsRequest* request,
      46              :                 Odb::Grpc::GetLayerSymbolsResponse* response) override;
      47              : 
      48              :             grpc::Status GetStandardFonts(grpc::ServerContext* context,
      49              :                 const Odb::Grpc::GetStandardFontsRequest* request,
      50              :                 Odb::Lib::Protobuf::StandardFontsFile* response) override;
      51              : 
      52              :             grpc::Status RequestLoadDesign(grpc::ServerContext* context,
      53              :                 const Odb::Grpc::RequestLoadDesignRequest* request,
      54              :                 Odb::Grpc::RequestLoadDesignResponse* response) override;
      55              : 
      56              :             grpc::Status HealthCheck(grpc::ServerContext* context,
      57              :                 const Odb::Grpc::HealthCheckRequest* request,
      58              :                 Odb::Grpc::HealthCheckResponse* response) override;
      59              : 
      60              :             // Test/observability seam: the design-stream disk spool.
      61           18 :             const StreamSpoolCache& streamSpoolCache() const { return *m_streamSpool; }
      62              : 
      63              :         private:
      64              :             std::shared_ptr<Odb::Lib::App::DesignCache> m_designCache;
      65              :             std::shared_ptr<Config::GrpcServiceConfig> m_config;
      66              :             std::unique_ptr<StreamSpoolCache> m_streamSpool;
      67              :             DesignStreamOptions m_streamOptions;
      68              :         };
      69              : 
      70              :         // Shared status mapping behind RequestLoadDesign (gRPC) and its REST twin
      71              :         // (POST /designs/<name>/load). Pure lookup: never blocks on a parse; the
      72              :         // only mutating call is the LoadDesignAsync kick, which returns
      73              :         // immediately. Failed falls through to the kick path because a failed
      74              :         // load is retryable by design.
      75            5 :         inline Odb::Grpc::LoadStatus ComputeRequestLoadStatus(
      76              :             Odb::Lib::App::DesignCache& designCache, const std::string& designName)
      77              :         {
      78              :             using Odb::Lib::App::DesignCache;
      79              : 
      80            5 :             switch (designCache.GetLoadState(designName))
      81              :             {
      82            0 :             case DesignCache::LoadState::Loading:
      83            0 :                 return Odb::Grpc::LOAD_ALREADY_LOADING;
      84            1 :             case DesignCache::LoadState::Loaded:
      85            1 :                 return Odb::Grpc::LOAD_ALREADY_LOADED;
      86            4 :             default:
      87            4 :                 break;
      88              :             }
      89              : 
      90            4 :             if (!designCache.ContainsDesign(designName))
      91              :             {
      92            1 :                 return Odb::Grpc::LOAD_NOT_FOUND;
      93              :             }
      94            3 :             return designCache.LoadDesignAsync(designName)
      95            3 :                 ? Odb::Grpc::LOAD_ACCEPTED
      96            3 :                 : Odb::Grpc::LOAD_ALREADY_LOADING;
      97              :         }
      98              : 
      99              :         // JSON status strings for the REST twin's response body
     100              :         // ("accepted" | "already_loading" | "already_loaded" | "not_found").
     101              :         // If/else rather than a switch: protobuf's synthetic
     102              :         // _INT_MIN/MAX_SENTINEL_DO_NOT_USE_ enum values would trip -Wswitch.
     103              :         inline const char* LoadStatusToString(Odb::Grpc::LoadStatus status)
     104              :         {
     105              :             if (status == Odb::Grpc::LOAD_ACCEPTED) return "accepted";
     106              :             if (status == Odb::Grpc::LOAD_ALREADY_LOADING) return "already_loading";
     107              :             if (status == Odb::Grpc::LOAD_ALREADY_LOADED) return "already_loaded";
     108              :             if (status == Odb::Grpc::LOAD_NOT_FOUND) return "not_found";
     109              :             return "unknown";
     110              :         }
     111              : 
     112              :     } // namespace Services
     113              : } // namespace OdbDesignServer
        

Generated by: LCOV version 2.0-1