Skip to content

Commit

Permalink
Bumped version for new pypi package (#95)
Browse files Browse the repository at this point in the history
* Bumped version for new pypi package

* Use uuid for client id

* Applied PR feedback
  • Loading branch information
Justin Boswell authored Nov 20, 2019
1 parent c10c6d2 commit 06d55fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def awscrt_ext():

setuptools.setup(
name="awscrt",
version="0.3.3",
version="0.4.1",
author="Amazon Web Services, Inc",
author_email="[email protected]",
description="A common runtime for AWS Python projects",
Expand Down
29 changes: 20 additions & 9 deletions source/mqtt_client_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ struct mqtt_connection_binding {
/* Dependencies that must outlive this */
PyObject *on_connection_interrupted;
PyObject *on_connection_resumed;
PyObject *on_any_publish;
PyObject *client;
};

Expand All @@ -56,6 +57,7 @@ static void s_mqtt_python_connection_finish_destruction(struct mqtt_connection_b

Py_XDECREF(py_connection->on_connection_interrupted);
Py_XDECREF(py_connection->on_connection_resumed);
Py_XDECREF(py_connection->on_any_publish);
Py_DECREF(py_connection->client);

aws_mem_release(aws_py_get_allocator(), py_connection);
Expand Down Expand Up @@ -184,7 +186,9 @@ PyObject *aws_py_mqtt_client_connection_new(PyObject *self, PyObject *args) {
/* From hereon, nothing will fail */

py_connection->on_connection_interrupted = PyWeakref_NewProxy(on_connection_interrupted, NULL);
AWS_FATAL_ASSERT(py_connection->on_connection_interrupted);
py_connection->on_connection_resumed = PyWeakref_NewProxy(on_connection_resumed, NULL);
AWS_FATAL_ASSERT(py_connection->on_connection_resumed);
py_connection->client = client_py;
Py_INCREF(py_connection->client);

Expand Down Expand Up @@ -602,10 +606,6 @@ static void s_subscribe_callback(
(void)connection;

PyObject *callback = user_data;
if (!callback) {
return;
}

PyGILState_STATE state = PyGILState_Ensure();

PyObject *result = PyObject_CallFunction(
Expand Down Expand Up @@ -644,7 +644,7 @@ static void s_suback_callback(
(void)connection;

PyObject *callback = userdata;
if (!callback) {
if (callback == Py_None) {
return;
}

Expand Down Expand Up @@ -683,8 +683,8 @@ PyObject *aws_py_mqtt_client_connection_subscribe(PyObject *self, PyObject *args
return NULL;
}

Py_XINCREF(callback);
Py_XINCREF(suback_callback);
Py_INCREF(callback);
Py_INCREF(suback_callback);

struct aws_byte_cursor topic_filter = aws_byte_cursor_from_array(topic, topic_len);
uint16_t msg_id = aws_mqtt_client_connection_subscribe(
Expand All @@ -698,8 +698,8 @@ PyObject *aws_py_mqtt_client_connection_subscribe(PyObject *self, PyObject *args
suback_callback);

if (msg_id == 0) {
Py_XDECREF(callback);
Py_XDECREF(suback_callback);
Py_DECREF(callback);
Py_DECREF(suback_callback);
return PyErr_AwsLastError();
}

Expand All @@ -721,12 +721,23 @@ PyObject *aws_py_mqtt_client_connection_on_message(PyObject *self, PyObject *arg
return NULL;
}

Py_CLEAR(py_connection->on_any_publish);

if (callback == Py_None) {
aws_mqtt_client_connection_set_on_any_publish_handler(py_connection->native, NULL, NULL);
Py_RETURN_NONE;
}

callback = PyWeakref_NewProxy(callback, NULL);
AWS_FATAL_ASSERT(callback);

if (aws_mqtt_client_connection_set_on_any_publish_handler(py_connection->native, s_subscribe_callback, callback)) {
Py_DECREF(callback);
return PyErr_AwsLastError();
}

py_connection->on_any_publish = callback;

Py_RETURN_NONE;
}

Expand Down
3 changes: 2 additions & 1 deletion test/test_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import unittest
import boto3
import time
import uuid
import warnings


Expand Down Expand Up @@ -75,7 +76,7 @@ def _test_connection(self):
tls = ClientTlsContext(tls_opts)
client = Client(ClientBootstrap(EventLoopGroup()), tls)
connection = Connection(client)
connection.connect('aws-crt-python-unit-test-'.format(time.gmtime()), config.endpoint, 8883).result()
connection.connect('aws-crt-python-unit-test-{0}'.format(uuid.uuid4()), config.endpoint, 8883).result()
return connection
except Exception as ex:
self.assertFalse(ex)
Expand Down

0 comments on commit 06d55fd

Please sign in to comment.