|
SimCore
Shared transport-layer plumbing for the ADR-029 Train/IL/CTC RBC simulators
|
Public Member Functions | |
| __init__ (self, log, port, handlers, json_handlers=None, bind_host="0.0.0.0") | |
| poll (self, timeout=0.0) | |
Public Attributes | |
| log = log | |
| sel = selectors.DefaultSelector() | |
| handlers = handlers | |
| json_handlers = json_handlers or {} | |
Protected Member Functions | |
| _on_accept (self, _mask) | |
| _on_data (self, client, _mask) | |
| _handle_line (self, client, line) | |
| _handle_json_line (self, line) | |
| _close_client (self, client) | |
Protected Attributes | |
| _listen = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
Definition at line 59 of file control_server.py.
| simcore.control_server.ControlServer.__init__ | ( | self, | |
| log, | |||
| port, | |||
| handlers, | |||
| json_handlers = None, | |||
| bind_host = "0.0.0.0" ) |
@param bind_host: interface to listen on - "0.0.0.0" (every
interface, the previous hardcoded behavior) unless the
sim's own config file (sim_config.py) says otherwise.
@param handlers: {command_name: fn(args: list[str]) -> str}
- fn's return value is written back verbatim (the handler
is responsible for its own trailing newline). Command
names are matched case-insensitively (upper-cased before
lookup) - @handlers' own keys should be upper-case.
@param json_handlers: {cmd_name: fn(request: dict) -> dict} -
fn's return value is JSON-encoded and a trailing newline
appended automatically; fn should raise (any Exception)
rather than return an error dict itself - the caller
turns that into {"status": "ERR", "reason": str(exc)}
uniformly, same "a bad command must not crash the sim"
contract as the plain-text handlers below. Command names
(the JSON request's own "cmd" field) are matched
case-sensitively, unlike plain-text commands - a JSON
API's own field values are not conventionally
case-folded the way a human-typed line's leading word is.
Definition at line 60 of file control_server.py.
|
protected |
Definition at line 176 of file control_server.py.
|
protected |
@return the JSON-encoded (plus trailing newline) reply string
for one JSON-command line - see this class's own doc for the
{"cmd": ...} request/{"status": "OK"|"ERR", ...} reply shape.
Definition at line 155 of file control_server.py.
|
protected |
Definition at line 129 of file control_server.py.
|
protected |
Definition at line 105 of file control_server.py.
|
protected |
Definition at line 115 of file control_server.py.
| simcore.control_server.ControlServer.poll | ( | self, | |
| timeout = 0.0 ) |
Call once per iteration of the sim's own main loop - dispatches any ready accept/read event (non-blocking with @timeout=0, or a small blocking budget if the caller wants this to double as its own pacing tick).
Definition at line 94 of file control_server.py.
|
protected |
Definition at line 85 of file control_server.py.
| simcore.control_server.ControlServer.handlers = handlers |
Definition at line 83 of file control_server.py.
| simcore.control_server.ControlServer.json_handlers = json_handlers or {} |
Definition at line 84 of file control_server.py.
| simcore.control_server.ControlServer.log = log |
Definition at line 81 of file control_server.py.
| simcore.control_server.ControlServer.sel = selectors.DefaultSelector() |
Definition at line 82 of file control_server.py.