feat: EquipmentRuntime engine owner + secs_gemd gRPC daemon

Extract the SECS/GEM engine wiring out of the secs_server app into a
reusable class, and stand up a language-agnostic gRPC daemon on top so a
tool's software (any language) can drive the equipment without linking C++
or knowing SEMI. Foundation for replacing a vendor's SECS/GEM server.

Engine reuse:
- EquipmentRuntime (include/secsgem/gem/runtime.hpp, src/gem/runtime.cpp):
  owns io_context, passive Server, model, control-state machine, Router;
  thread-safe outbound API (set_variable/emit_event/set_alarm/clear_alarm),
  on_command hook, deliver_or_spool, run()/run_async()/poll()/stop().
- register_default_handlers (src/gem/default_handlers.cpp): the 56 GEM
  handlers + domain emitters, relocated from secs_server so the app and the
  daemon speak byte-identical GEM. secs_server.cpp reduced ~1270 -> 113 lines.
- name_index.hpp: resolve_variable(name) -> VID (the name->id binding layer).

Daemon (apps/secs_gemd.cpp, proto/secsgem/v1/equipment.proto):
- runs the engine + HSMS link on a background thread; serves the gRPC
  Equipment service. Increment 1: SetVariables (name-resolved, plain
  value->Item) and GetControlState. proto carries the full v1 surface
  (universal + carrier/recipe/job tiers); remaining RPCs + the Subscribe
  command stream are next (docs/DAEMON_ROADMAP.md).
- CMake: opt-in SECSGEM_DAEMON, protoc/grpc_cpp_plugin codegen, gracefully
  skipped where protobuf/grpc++ are absent. Dockerfile gains the grpc deps.

Tests (proof): test_runtime, test_default_handlers (S1F1->S1F2, S2F41->hook),
test_name_index. Full suite 458/458, 2795 assertions; live server<->client
GEM300 demo still passes on the refactored server.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-10 18:01:16 +02:00
parent 4b4b2ac690
commit fc898f8410
14 changed files with 2135 additions and 1183 deletions
+48
View File
@@ -98,6 +98,8 @@ add_library(secsgem
src/gem/module_state.cpp
src/gem/e84_state.cpp
src/gem/host_handler.cpp
src/gem/runtime.cpp
src/gem/default_handlers.cpp
src/config/loader.cpp
src/config/validate.cpp
src/endpoint.cpp
@@ -131,6 +133,49 @@ target_link_libraries(secs_bench PRIVATE secsgem)
add_executable(pvd_tool examples/pvd_tool/main.cpp)
target_link_libraries(pvd_tool PRIVATE secsgem)
# --- gRPC daemon: secs_gemd -----------------------------------------------
# Runs the engine on a background thread and exposes proto/secsgem/v1 over
# gRPC. Opt-in and gracefully skipped where protobuf/grpc++ aren't installed,
# so the core library + tests build without them.
option(SECSGEM_DAEMON "Build the secs_gemd gRPC daemon" ON)
if(SECSGEM_DAEMON)
find_package(Protobuf QUIET)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(GRPCPP QUIET IMPORTED_TARGET grpc++)
endif()
find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin)
if(Protobuf_FOUND AND GRPCPP_FOUND AND GRPC_CPP_PLUGIN)
set(PROTO_DIR ${CMAKE_SOURCE_DIR}/proto)
set(PROTO_FILE ${PROTO_DIR}/secsgem/v1/equipment.proto)
set(PROTO_OUT ${CMAKE_BINARY_DIR}/generated)
add_custom_command(
OUTPUT ${PROTO_OUT}/secsgem/v1/equipment.pb.cc
${PROTO_OUT}/secsgem/v1/equipment.pb.h
${PROTO_OUT}/secsgem/v1/equipment.grpc.pb.cc
${PROTO_OUT}/secsgem/v1/equipment.grpc.pb.h
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROTO_OUT}
COMMAND ${Protobuf_PROTOC_EXECUTABLE}
--proto_path=${PROTO_DIR}
--cpp_out=${PROTO_OUT}
--grpc_out=${PROTO_OUT}
--plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN}
${PROTO_FILE}
DEPENDS ${PROTO_FILE}
COMMENT "Generating gRPC C++ from equipment.proto"
VERBATIM)
add_executable(secs_gemd
apps/secs_gemd.cpp
${PROTO_OUT}/secsgem/v1/equipment.pb.cc
${PROTO_OUT}/secsgem/v1/equipment.grpc.pb.cc)
target_include_directories(secs_gemd PRIVATE ${PROTO_OUT} ${Protobuf_INCLUDE_DIRS})
target_link_libraries(secs_gemd PRIVATE secsgem PkgConfig::GRPCPP ${Protobuf_LIBRARIES})
message(STATUS "secs_gemd daemon enabled (grpc++ ${GRPCPP_VERSION})")
else()
message(STATUS "secs_gemd skipped (need protobuf + grpc++ + grpc_cpp_plugin)")
endif()
endif()
if(SECSGEM_FUZZ)
# libFuzzer entry-point targets. Each owns its own `main` via the
# `-fsanitize=fuzzer` link flag; do NOT also link them into the
@@ -170,6 +215,9 @@ add_executable(secsgem_tests
tests/test_control_state.cpp
tests/test_communication_state.cpp
tests/test_data_model.cpp
tests/test_runtime.cpp
tests/test_default_handlers.cpp
tests/test_name_index.cpp
tests/test_messages.cpp
tests/test_loader.cpp
tests/test_process_jobs.cpp