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