some refactoring and socket server added

This commit is contained in:
Ayzen
2026-04-08 18:43:29 +03:00
parent 202993325d
commit 1d7d0a756e
25 changed files with 3093 additions and 2527 deletions
+55
View File
@@ -30,6 +30,7 @@ from python_app.models.run_config_model import RunConfigModel
from python_app.orchestration.config_writer import ConfigWriter
from python_app.orchestration.gui_session_state import GuiSessionState, GuiSessionStateStore
from python_app.orchestration.live_processing_config import ProcessingLiveConfigWriter
from python_app.orchestration.locator_runtime import LocatorTcpService
from python_app.orchestration.preprocess_assets import VISIBLE_PREPROCESS_ASSET_KEYS, preprocess_asset_model
from python_app.orchestration.process_supervisor import ProcessSupervisor
from python_app.orchestration.shm_reader import ShmRingReader
@@ -79,6 +80,7 @@ class AppWindow(
self._supervisor = ProcessSupervisor(self._project_root)
self._live_config_writer = ProcessingLiveConfigWriter(runtime_dir / "processing_live.json")
self._gui_session_state_store = GuiSessionStateStore(runtime_dir / "gui_session_state.json")
self._locator_service: LocatorTcpService | None = None
def _init_config_profile_state(self) -> None:
"""Resolve startup profile path, load active profile, and queue fallback notices."""
@@ -107,6 +109,7 @@ class AppWindow(
"INFO",
f"Loaded legacy run config without GUI defaults: {active_profile_path}",
)
self._locator_service = self._build_locator_service(self._defaults_config)
self._remember_active_profile_path(active_profile_path, startup=True)
def _init_reader_handles(self) -> None:
@@ -197,9 +200,58 @@ class AppWindow(
self._log(f"Active config profile: {self._active_profile_path}")
self._refresh_preprocess_summary_labels()
self._apply_initial_radar_limits()
self._start_locator_service()
self._write_live_processing_config()
self._timer.start()
def _start_locator_service(self) -> None:
"""Start embedded locator TCP service without failing the GUI."""
try:
if self._locator_service is None:
self._locator_service = self._build_locator_service(self._defaults_config)
self._locator_service.start()
self._locator_service.publish_empty()
self._log(
f"Locator TCP server listening on "
f"{self._locator_service.host}:{self._locator_service.port}"
)
except Exception as exc: # noqa: BLE001
self._log_exception("Failed to start locator TCP server", exc, level="WARN")
def _build_locator_service(self, config: RunConfigModel) -> LocatorTcpService:
"""Create locator service instance from stable run config."""
locator_server = config.runtime.locator_server
return LocatorTcpService(
host=str(locator_server.host),
port=int(locator_server.port),
device_id=int(locator_server.device_id),
protocol_version=int(locator_server.protocol_version),
max_payload_bytes=int(locator_server.max_payload_bytes),
client_queue_size=int(locator_server.client_queue_size),
logger_name=str(locator_server.logger_name),
)
def _reload_locator_service_from_config(self) -> None:
"""Rebuild locator service using current stable config and restart if needed."""
previous_service = self._locator_service
was_running = previous_service is not None and previous_service.is_running()
if previous_service is not None:
previous_service.stop()
self._locator_service = self._build_locator_service(self._defaults_config)
if not was_running:
return
try:
self._locator_service.start()
self._locator_service.publish_empty()
self._log(
"Locator TCP server reloaded from config: "
f"{self._locator_service.host}:{self._locator_service.port}"
)
except Exception as exc: # noqa: BLE001
self._log_exception("Failed to reload locator TCP server from config", exc, level="WARN")
def _resolve_startup_profile_path(self) -> Path:
"""Resolve active profile path from session-state or root fallback path."""
try:
@@ -434,6 +486,9 @@ class AppWindow(
self._abort_capture_sequence(resume_pipeline=False)
# 2) Stop all managed processes/readers.
self._stop_all_processes()
# 3) Stop embedded locator service.
if self._locator_service is not None:
self._locator_service.stop()
# 3) Close auxiliary dialog windows.
if self._preprocess_dialog is not None:
self._preprocess_dialog.close()