summaryrefslogtreecommitdiff
path: root/mesh/dbus.c
diff options
context:
space:
mode:
authorInga Stotland <inga.stotland@intel.com>2020-06-10 10:11:19 -0700
committerBrian Gix <brian.gix@intel.com>2020-06-10 10:27:17 -0700
commit65cdf6b22cdf04d0142cb925d7c1d924e6fe6dbd (patch)
treef863ce2bf425b5e1c59d4c88f65aefac9895f606 /mesh/dbus.c
parente5179f9fe59765606e7c806dccab2753e3297c1b (diff)
downloadbluez-65cdf6b22cdf04d0142cb925d7c1d924e6fe6dbd.tar.gz
mesh: Add destroy callback to dbus_send_with_timeout()
This adds a destroy callback as a function parameter to dbus_send_with_timeout() to allow automatic release of user data on either reply or timeout.
Diffstat (limited to 'mesh/dbus.c')
-rw-r--r--mesh/dbus.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/mesh/dbus.c b/mesh/dbus.c
index 83ae22c9f..63ea420ed 100644
--- a/mesh/dbus.c
+++ b/mesh/dbus.c
@@ -41,6 +41,7 @@ struct send_info {
struct l_dbus *dbus;
struct l_timeout *timeout;
l_dbus_message_func_t cb;
+ l_dbus_destroy_func_t destroy;
void *user_data;
uint32_t serial;
};
@@ -159,6 +160,10 @@ static void send_reply(struct l_dbus_message *message, void *user_data)
l_timeout_remove(info->timeout);
info->cb(message, info->user_data);
+
+ if (info->destroy)
+ info->destroy(info->user_data);
+
l_free(info);
}
@@ -173,6 +178,7 @@ static void send_timeout(struct l_timeout *timeout, void *user_data)
void dbus_send_with_timeout(struct l_dbus *dbus, struct l_dbus_message *msg,
l_dbus_message_func_t cb,
void *user_data,
+ l_dbus_destroy_func_t destroy,
unsigned int seconds)
{
struct send_info *info = l_new(struct send_info, 1);
@@ -180,6 +186,7 @@ void dbus_send_with_timeout(struct l_dbus *dbus, struct l_dbus_message *msg,
info->dbus = dbus;
info->cb = cb;
info->user_data = user_data;
+ info->destroy = destroy;
info->serial = l_dbus_send_with_reply(dbus, msg, send_reply,
info, NULL);
info->timeout = l_timeout_create(seconds, send_timeout, info, NULL);