Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdp: clean up conn/proto initialization #649

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/model/sdp/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, data_received_callback, name=None, **kwargs):
self.dummy = None
self._send_lock = None
self.use_send_lock = False
self._params = None
self._params = {}

if not hasattr(self, 'logger'):
self.logger = logging.getLogger(__name__)
Expand Down
46 changes: 15 additions & 31 deletions lib/model/sdp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,13 @@ class SDPProtocol(SDPConnection):

def __init__(self, data_received_callback, name=None, **kwargs):

self.logger = logging.getLogger(__name__)

if SDP_standalone:
self.logger = logging.getLogger('__main__')
# init super, get logger
super().__init__(data_received_callback, name, **kwargs)

self.logger.debug(f'protocol initializing from {self.__class__.__name__} with arguments {kwargs}')

# set class properties
self._is_connected = False
self._data_received_callback = data_received_callback

# make sure we have a basic set of parameters
self._params = {PLUGIN_ATTR_CB_ON_DISCONNECT: None,
PLUGIN_ATTR_CB_ON_CONNECT: None,
PLUGIN_ATTR_MSG_TIMEOUT: 3,
PLUGIN_ATTR_MSG_REPEAT: 3,
PLUGIN_ATTR_CONNECTION: SDPConnection}
self._params.update({PLUGIN_ATTR_CONNECTION: SDPConnection})
self._params.update(kwargs)

# check if some of the arguments are usable
Expand Down Expand Up @@ -146,8 +136,20 @@ def data_received_callback(by, message, command=None)
"""
def __init__(self, data_received_callback, name=None, **kwargs):

# init super, get logger
super().__init__(data_received_callback, name, **kwargs)

# make sure we have a basic set of parameters for the TCP connection
self._params.update({PLUGIN_ATTR_NET_PORT: 9090,
PLUGIN_ATTR_MSG_REPEAT: 3,
PLUGIN_ATTR_MSG_TIMEOUT: 5,
PLUGIN_ATTR_CONNECTION: CONN_NET_TCP_CLI,
JSON_MOVE_KEYS: []})
self._params.update(kwargs)

# check if some of the arguments are usable
self._set_connection_params()

# set class properties
self._shutdown_active = False

Expand All @@ -158,24 +160,6 @@ def __init__(self, data_received_callback, name=None, **kwargs):

self._receive_buffer = b''

# make sure we have a basic set of parameters for the TCP connection
self._params = {PLUGIN_ATTR_NET_HOST: '',
PLUGIN_ATTR_NET_PORT: 9090,
PLUGIN_ATTR_CONN_AUTO_CONN: True,
PLUGIN_ATTR_CONN_RETRIES: 1,
PLUGIN_ATTR_CONN_CYCLE: 3,
PLUGIN_ATTR_CONN_TIMEOUT: 3,
PLUGIN_ATTR_MSG_REPEAT: 3,
PLUGIN_ATTR_MSG_TIMEOUT: 5,
PLUGIN_ATTR_CB_ON_DISCONNECT: None,
PLUGIN_ATTR_CB_ON_CONNECT: None,
PLUGIN_ATTR_CONNECTION: CONN_NET_TCP_CLI,
JSON_MOVE_KEYS: []}
self._params.update(kwargs)

# check if some of the arguments are usable
self._set_connection_params()

# self._message_archive[str message_id] = [time() sendtime, str method, str params or None, int repeat]
self._message_archive = {}

Expand Down
Loading