Some checks failed
Tests / Detect Changes (push) Has been cancelled
Tests / Installer Test (Raspberry Pi OS - ARM) (push) Has been cancelled
Tests / Installer Test (Raspberry Pi OS - ARM)-1 (push) Has been cancelled
Tests / Unit Tests (push) Has been cancelled
Tests / Unit Tests-1 (push) Has been cancelled
Tests / Unit Tests-2 (push) Has been cancelled
Tests / Unit Tests-3 (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / Integration Tests-1 (push) Has been cancelled
Tests / Integration Tests-2 (push) Has been cancelled
Tests / Integration Tests-3 (push) Has been cancelled
Tests / Installer Test (Fresh System) (push) Has been cancelled
Tests / Installer Test (Fresh System)-1 (push) Has been cancelled
Tests / Installer Test (Fresh System)-2 (push) Has been cancelled
Tests / Installer Test (Fresh System)-3 (push) Has been cancelled
Tests / Installer Test (Fresh System)-4 (push) Has been cancelled
104 lines
2.4 KiB
Python
104 lines
2.4 KiB
Python
import os
|
|
|
|
|
|
BACKEND_ENV_VAR = "BLE_RETICULUM_SESSION_BACKEND"
|
|
DEFAULT_BACKEND = "auto"
|
|
VALID_BACKENDS = {"auto", "cpp", "python"}
|
|
|
|
|
|
def _requested_backend():
|
|
value = os.environ.get(BACKEND_ENV_VAR, DEFAULT_BACKEND).strip().lower()
|
|
if value not in VALID_BACKENDS:
|
|
raise ValueError(
|
|
f"Invalid {BACKEND_ENV_VAR}={value!r}; expected 'auto', 'cpp', or 'python'"
|
|
)
|
|
return value
|
|
|
|
|
|
def _load_cpp_backend():
|
|
try:
|
|
from ble_protocol_core_cpp import (
|
|
BLEPeerSessionManager,
|
|
ConnectionId,
|
|
ConnectionSnapshot,
|
|
InputDecision,
|
|
LocalRole,
|
|
SessionActionType,
|
|
)
|
|
except ImportError as e:
|
|
raise ImportError(
|
|
"C++ BLE session backend is not available. Build or install "
|
|
"ble_protocol_core_cpp, or set BLE_RETICULUM_SESSION_BACKEND=python."
|
|
) from e
|
|
|
|
return (
|
|
"cpp",
|
|
BLEPeerSessionManager,
|
|
ConnectionId,
|
|
ConnectionSnapshot,
|
|
InputDecision,
|
|
LocalRole,
|
|
SessionActionType,
|
|
)
|
|
|
|
|
|
def _load_python_backend():
|
|
return ("python", None, None, None, None, None, None)
|
|
|
|
|
|
REQUESTED_BACKEND = _requested_backend()
|
|
|
|
if REQUESTED_BACKEND == "python":
|
|
(
|
|
BACKEND,
|
|
BLEPeerSessionManager,
|
|
ConnectionId,
|
|
ConnectionSnapshot,
|
|
InputDecision,
|
|
LocalRole,
|
|
SessionActionType,
|
|
) = _load_python_backend()
|
|
elif REQUESTED_BACKEND == "cpp":
|
|
(
|
|
BACKEND,
|
|
BLEPeerSessionManager,
|
|
ConnectionId,
|
|
ConnectionSnapshot,
|
|
InputDecision,
|
|
LocalRole,
|
|
SessionActionType,
|
|
) = _load_cpp_backend()
|
|
else:
|
|
try:
|
|
(
|
|
BACKEND,
|
|
BLEPeerSessionManager,
|
|
ConnectionId,
|
|
ConnectionSnapshot,
|
|
InputDecision,
|
|
LocalRole,
|
|
SessionActionType,
|
|
) = _load_cpp_backend()
|
|
except ImportError:
|
|
(
|
|
BACKEND,
|
|
BLEPeerSessionManager,
|
|
ConnectionId,
|
|
ConnectionSnapshot,
|
|
InputDecision,
|
|
LocalRole,
|
|
SessionActionType,
|
|
) = _load_python_backend()
|
|
|
|
|
|
__all__ = [
|
|
"BACKEND",
|
|
"BACKEND_ENV_VAR",
|
|
"REQUESTED_BACKEND",
|
|
"BLEPeerSessionManager",
|
|
"ConnectionId",
|
|
"ConnectionSnapshot",
|
|
"InputDecision",
|
|
"LocalRole",
|
|
"SessionActionType",
|
|
]
|