-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
86 lines (71 loc) · 2.08 KB
/
client.py
File metadata and controls
86 lines (71 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# Copyright 2024 - Dasun Gunasinghe
# Research Engineering Facility, Queensland University of Technology (QUT)
__author__ = 'Dasun Gunasinghe'
__email__ = 'robotics.ref@qut.edu.au'
from abc import ABC, abstractmethod
from typing import TypeVar, Generic
T = TypeVar("T")
class Interpreter(ABC, Generic[T]):
def __init__(self):
pass
@abstractmethod
def verify_output(self, command: T) -> T:
"""Verifies a given output command based on a known interpreter
"""
pass
@abstractmethod
def generate_output(self, command: T) -> T:
"""Generates an output command to be sent in known message format
"""
pass
@abstractmethod
def interpret_input(self, command: T) -> T:
"""Interprets an input and outputs in known message format
"""
pass
T = TypeVar("T")
class Client(ABC, Generic[T]):
def __init__(self, interpreter: Interpreter):
self._connection_status: bool = False
self._interpreter: Interpreter = interpreter
# -- Standard Methods
def get_interpreter(self) -> Interpreter:
return self._interpreter
# -- Properties
@property
def _connected(self):
"""The _connection_status property.
"""
return self._connection_status
@_connected.setter
def _connected(self, value: bool = False):
"""Setting the _connection_status property
"""
self._connection_status = value
# -- Abstract Methods
@abstractmethod
def setup(self) -> T:
"""Conducts required setup for the client
"""
pass
@abstractmethod
def send(self, command: T) -> bool:
"""Sends the command to a client
"""
pass
@abstractmethod
def connect(self) -> bool:
"""Connects to a client device
"""
pass
@abstractmethod
def disconnect(self) -> T:
"""Disconnects from a client device
"""
pass
@abstractmethod
def get_status(self) -> T:
"""Return the status from client
"""
pass