From 2f59cdfbf57897f562308b4423dd71cb98f0b18e Mon Sep 17 00:00:00 2001 From: Colden Cullen Date: Thu, 3 Jan 2019 10:11:50 -0800 Subject: [PATCH] Merge connection constructor with connect() (#18) --- aws_crt/mqtt.py | 24 +++++++++--------------- codebuild/linux-clang6-x64.yml | 2 +- codebuild/linux-gcc-6x-x64.yml | 2 +- test.py | 6 +++--- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/aws_crt/mqtt.py b/aws_crt/mqtt.py index 266f06ad8..692e08d18 100644 --- a/aws_crt/mqtt.py +++ b/aws_crt/mqtt.py @@ -46,16 +46,9 @@ def __init__(self, bootstrap, tls_ctx = None): self._internal_client = _aws_crt_python.aws_py_mqtt_client_new(self.bootstrap._internal_bootstrap) class Connection(object): - __slots__ = ['_internal_connection', 'client', 'client_id', 'will'] + __slots__ = ['_internal_connection'] - def __init__(self, client, client_id): - - assert isinstance(client, Client) - - self.client = client - self.client_id = client_id - - def connect(self, + def __init__(self, client, client_id, host_name, port, on_connect=_default_on_connect, on_disconnect=_default_on_disconnect, @@ -64,20 +57,21 @@ def connect(self, will=None, username=None, password=None): - assert use_websocket == False - + assert isinstance(client, Client) assert will is None or isinstance(will, Will) + assert use_websocket == False + tls_ctx_cap = None - if self.client.tls_ctx: - tls_ctx_cap = self.client.tls_ctx._internal_tls_ctx + if client.tls_ctx: + tls_ctx_cap = client.tls_ctx._internal_tls_ctx self._internal_connection = _aws_crt_python.aws_py_mqtt_client_connection_new( - self.client._internal_client, + client._internal_client, tls_ctx_cap, host_name, port, - self.client_id, + client_id, keep_alive, on_connect, on_disconnect, diff --git a/codebuild/linux-clang6-x64.yml b/codebuild/linux-clang6-x64.yml index 9d24088cc..6c62ac917 100644 --- a/codebuild/linux-clang6-x64.yml +++ b/codebuild/linux-clang6-x64.yml @@ -7,7 +7,7 @@ phases: - sudo add-apt-repository ppa:ubuntu-toolchain-r/test - sudo apt-add-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-6.0 main" - sudo apt-get update -y - - sudo apt-get install clang-6.0 cmake3 cppcheck clang-tidy-6.0 clang-format-6.0 python3 python3-dev python3-setuptools ninja-build libssl-dev -y -f + - sudo apt-get install clang-6.0 cmake3 cppcheck clang-tidy-6.0 clang-format-6.0 python3 python3-dev python3-setuptools ninja-build libssl-dev -y -f --force-yes pre_build: commands: diff --git a/codebuild/linux-gcc-6x-x64.yml b/codebuild/linux-gcc-6x-x64.yml index b87f6ac8c..73060d36f 100644 --- a/codebuild/linux-gcc-6x-x64.yml +++ b/codebuild/linux-gcc-6x-x64.yml @@ -5,7 +5,7 @@ phases: commands: - sudo add-apt-repository ppa:ubuntu-toolchain-r/test - sudo apt-get update -y - - sudo apt-get install gcc-6 cmake3 cppcheck python3 python3-dev python3-setuptools ninja-build libssl-dev -y + - sudo apt-get install gcc-6 cmake3 cppcheck python3 python3-dev python3-setuptools ninja-build libssl-dev -y -f --force-yes pre_build: commands: - export CC=gcc-6 diff --git a/test.py b/test.py index a3df37636..46dc808b3 100644 --- a/test.py +++ b/test.py @@ -93,11 +93,11 @@ def on_publish(packet_id): tls_context = io.ClientTlsContext(tls_options) if tls_options else None mqtt_client = mqtt.Client(client_bootstrap, tls_context) -mqtt_connection = mqtt.Connection(mqtt_client, CLIENT_ID) - # Connect print("Connecting to {}:{} with client-id:{}".format(args.endpoint, port, CLIENT_ID)) -mqtt_connection.connect( +mqtt_connection = mqtt.Connection( + client=mqtt_client, + client_id=CLIENT_ID, host_name=args.endpoint, port=port, on_connect=on_connect,