diff --git a/src/gatt-client.c b/src/gatt-client.c
index 66c2318..b5b2ea3 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
chrc->ready_id = 0;
- if (chrc->write_io->msg) {
+ if (chrc->write_io && chrc->write_io->msg) {
reply = characteristic_create_pipe(chrc, chrc->write_io->msg);
g_dbus_send_message(btd_get_dbus_connection(), reply);
chrc->write_io->msg = NULL;
}
- if (chrc->notify_io->msg) {
+ if (chrc->notify_io && chrc->notify_io->msg) {
reply = characteristic_create_pipe(chrc, chrc->notify_io->msg);
g_dbus_send_message(btd_get_dbus_connection(), reply);
{
struct notify_client *client = user_data;
struct characteristic *chrc = client->chrc;
+ struct bt_gatt_client *gatt = chrc->service->client->gatt;
- if (!att_ecode)
+ if (att_ecode) {
+ queue_remove(chrc->notify_clients, client);
+ notify_client_free(client);
return;
+ }
- queue_remove(chrc->notify_clients, client);
- notify_client_free(client);
+ if (!bt_gatt_client_is_ready(gatt)) {
+ if (!chrc->ready_id)
+ chrc->ready_id = bt_gatt_client_ready_register(gatt,
+ characteristic_ready,
+ chrc, NULL);
+ return;
+ }
- pipe_io_destroy(chrc->notify_io);
- chrc->notify_io = NULL;
+ characteristic_ready(true, 0, chrc);
}
static void notify_io_destroy(void *data)
chrc->notify_io = new0(struct pipe_io, 1);
chrc->notify_io->data = client;
+ chrc->notify_io->msg = dbus_message_ref(msg);
chrc->notify_io->destroy = notify_io_destroy;
- if (!bt_gatt_client_is_ready(gatt)) {
- if (!chrc->ready_id)
- chrc->ready_id = bt_gatt_client_ready_register(gatt,
- characteristic_ready,
- chrc, NULL);
- chrc->notify_io->msg = dbus_message_ref(msg);
- return NULL;
- }
-
- return characteristic_create_pipe(chrc, msg);
+ return NULL;
}
static DBusMessage *characteristic_start_notify(DBusConnection *conn,