diff --git a/client/gatt.c b/client/gatt.c
index 7530383..ab74aa6 100644
--- a/client/gatt.c
+++ b/client/gatt.c
static GList *managers;
static GList *uuids;
-static GDBusProxy *write_proxy;
-static struct io *write_io;
-static uint16_t write_mtu;
+struct pipe_io {
+ GDBusProxy *proxy;
+ struct io *io;
+ uint16_t mtu;
+};
-static GDBusProxy *notify_proxy;
-static struct io *notify_io;
-static uint16_t notify_mtu;
+static struct pipe_io write_io;
+static struct pipe_io notify_io;
static void print_service(struct service *service, const char *description)
{
static void notify_io_destroy(void)
{
- io_destroy(notify_io);
- notify_io = NULL;
- notify_proxy = NULL;
- notify_mtu = 0;
+ io_destroy(notify_io.io);
+ memset(¬ify_io, 0, sizeof(notify_io));
}
static void write_io_destroy(void)
{
- io_destroy(write_io);
- write_io = NULL;
- write_proxy = NULL;
- write_mtu = 0;
+ io_destroy(write_io.io);
+ memset(&write_io, 0, sizeof(write_io));
}
void gatt_remove_characteristic(GDBusProxy *proxy)
print_characteristic(proxy, COLORED_DEL);
- if (write_proxy == proxy)
+ if (write_io.proxy == proxy)
write_io_destroy();
- else if (notify_proxy == proxy)
+ else if (notify_io.proxy == proxy)
notify_io_destroy();
}
iov.iov_len = i;
/* Write using the fd if it has been acquired and fit the MTU */
- if (proxy == write_proxy && (write_io && write_mtu >= i)) {
- rl_printf("Attempting to write fd %d\n", io_get_fd(write_io));
- if (io_send(write_io, &iov, 1) < 0) {
+ if (proxy == write_io.proxy && (write_io.io && write_io.mtu >= i)) {
+ rl_printf("Attempting to write fd %d\n",
+ io_get_fd(write_io.io));
+ if (io_send(write_io.io, &iov, 1) < 0) {
rl_printf("Failed to write: %s", strerror(errno));
return;
}
int fd = io_get_fd(io);
ssize_t bytes_read;
- if (io != notify_io)
+ if (io != notify_io.io)
return true;
bytes_read = read(fd, buf, sizeof(buf));
return false;
rl_printf("[" COLORED_CHG "] %s Notification:\n",
- g_dbus_proxy_get_path(notify_proxy));
+ g_dbus_proxy_get_path(notify_io.proxy));
rl_hexdump(buf, bytes_read);
return true;
static bool pipe_hup(struct io *io, void *user_data)
{
- rl_printf("%s closed\n", io == notify_io ? "Notify" : "Write");
+ rl_printf("%s closed\n", io == notify_io.io ? "Notify" : "Write");
- if (io == notify_io)
+ if (io == notify_io.io)
notify_io_destroy();
else
write_io_destroy();
if (dbus_set_error_from_message(&error, message) == TRUE) {
rl_printf("Failed to acquire write: %s\n", error.name);
dbus_error_free(&error);
- write_proxy = NULL;
+ write_io.proxy = NULL;
return;
}
- if (write_io)
+ if (write_io.io)
write_io_destroy();
if ((dbus_message_get_args(message, NULL, DBUS_TYPE_UNIX_FD, &fd,
- DBUS_TYPE_UINT16, &write_mtu,
+ DBUS_TYPE_UINT16, &write_io.mtu,
DBUS_TYPE_INVALID) == false)) {
rl_printf("Invalid AcquireWrite response\n");
return;
}
- rl_printf("AcquireWrite success: fd %d MTU %u\n", fd, write_mtu);
+ rl_printf("AcquireWrite success: fd %d MTU %u\n", fd, write_io.mtu);
- write_io = pipe_io_new(fd);
+ write_io.io = pipe_io_new(fd);
}
void gatt_acquire_write(GDBusProxy *proxy, const char *arg)
return;
}
- write_proxy = proxy;
+ write_io.proxy = proxy;
}
void gatt_release_write(GDBusProxy *proxy, const char *arg)
{
- if (proxy != write_proxy || !write_io) {
+ if (proxy != write_io.proxy || !write_io.io) {
rl_printf("Write not acquired\n");
return;
}
if (dbus_set_error_from_message(&error, message) == TRUE) {
rl_printf("Failed to acquire notify: %s\n", error.name);
dbus_error_free(&error);
- write_proxy = NULL;
+ write_io.proxy = NULL;
return;
}
- if (notify_io) {
- io_destroy(notify_io);
- notify_io = NULL;
+ if (notify_io.io) {
+ io_destroy(notify_io.io);
+ notify_io.io = NULL;
}
- notify_mtu = 0;
+ notify_io.mtu = 0;
if ((dbus_message_get_args(message, NULL, DBUS_TYPE_UNIX_FD, &fd,
- DBUS_TYPE_UINT16, ¬ify_mtu,
+ DBUS_TYPE_UINT16, ¬ify_io.mtu,
DBUS_TYPE_INVALID) == false)) {
rl_printf("Invalid AcquireNotify response\n");
return;
}
- rl_printf("AcquireNotify success: fd %d MTU %u\n", fd, notify_mtu);
+ rl_printf("AcquireNotify success: fd %d MTU %u\n", fd, notify_io.mtu);
- notify_io = pipe_io_new(fd);
+ notify_io.io = pipe_io_new(fd);
}
void gatt_acquire_notify(GDBusProxy *proxy, const char *arg)
return;
}
- notify_proxy = proxy;
+ notify_io.proxy = proxy;
}
void gatt_release_notify(GDBusProxy *proxy, const char *arg)
{
- if (proxy != notify_proxy || !notify_io) {
- rl_printf("Write not acquired\n");
+ if (proxy != notify_io.proxy || !notify_io.io) {
+ rl_printf("Notify not acquired\n");
return;
}