Skip to content

Commit

Permalink
Merge connection constructor with connect() (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdenCullen authored Jan 3, 2019
1 parent 6c7032b commit 2f59cdf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
24 changes: 9 additions & 15 deletions aws_crt/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion codebuild/linux-clang6-x64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion codebuild/linux-gcc-6x-x64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2f59cdf

Please sign in to comment.