mirror of
https://github.com/lowobservable/oec.git
synced 2026-01-11 23:53:04 +00:00
Extract create session from controller
This commit is contained in:
parent
9cd1603570
commit
ef40e50b58
@ -5,6 +5,7 @@ from serial import Serial
|
||||
from coax import Interface1
|
||||
|
||||
from .controller import Controller
|
||||
from .vt100 import VT100Session
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
@ -32,7 +33,11 @@ def main():
|
||||
print(f'Interface firmware version {firmware_version}')
|
||||
|
||||
# Initialize and start the controller.
|
||||
controller = Controller(interface, [args.command, *args.command_args])
|
||||
host_command = [args.command, *args.command_args]
|
||||
|
||||
create_session = lambda terminal: VT100Session(terminal, host_command)
|
||||
|
||||
controller = Controller(interface, create_session)
|
||||
|
||||
print('Starting controller...')
|
||||
|
||||
|
||||
@ -10,18 +10,17 @@ from coax import poll, poll_ack, KeystrokePollResponse, ReceiveTimeout, \
|
||||
|
||||
from .terminal import Terminal, read_terminal_ids
|
||||
from .session import SessionDisconnectedError
|
||||
from .vt100 import VT100Session
|
||||
|
||||
class Controller:
|
||||
"""The controller."""
|
||||
|
||||
def __init__(self, interface, host_command):
|
||||
def __init__(self, interface, create_session):
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
self.running = True
|
||||
|
||||
self.interface = interface
|
||||
self.host_command = host_command
|
||||
self.create_session = create_session
|
||||
|
||||
self.terminal = None
|
||||
self.session = None
|
||||
@ -87,9 +86,7 @@ class Controller:
|
||||
self.terminal.display.status_line.write_string(0, 'S')
|
||||
|
||||
# Start the session.
|
||||
self.session = VT100Session(self.terminal, self.host_command)
|
||||
|
||||
self.session.start()
|
||||
self._start_session()
|
||||
|
||||
def _handle_terminal_detached(self):
|
||||
self.logger.info('Terminal detached')
|
||||
@ -97,14 +94,23 @@ class Controller:
|
||||
if self.session:
|
||||
self.session.terminate()
|
||||
|
||||
self.session = None
|
||||
|
||||
self.terminal = None
|
||||
self.session = None
|
||||
|
||||
def _handle_session_disconnected(self):
|
||||
self.logger.info('Session disconnected')
|
||||
|
||||
self.session = None
|
||||
|
||||
# Restart the session.
|
||||
self._start_session()
|
||||
|
||||
def _start_session(self):
|
||||
self.session = self.create_session(self.terminal)
|
||||
|
||||
self.session.start()
|
||||
|
||||
def _handle_poll_response(self, poll_response):
|
||||
if isinstance(poll_response, KeystrokePollResponse):
|
||||
self._handle_keystroke_poll_response(poll_response)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user