dbus: track object path registration state and allow explicit unregiser
This commit is contained in:
parent
55406c08a7
commit
ed2f5eb687
|
@ -42,6 +42,7 @@ struct dbus_object_path
|
||||||
char * name;
|
char * name;
|
||||||
DBusMessage * introspection;
|
DBusMessage * introspection;
|
||||||
struct dbus_object_path_interface * ifaces;
|
struct dbus_object_path_interface * ifaces;
|
||||||
|
bool registered;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define write_buf(args...) buf_ptr += sprintf(buf_ptr, ## args)
|
#define write_buf(args...) buf_ptr += sprintf(buf_ptr, ## args)
|
||||||
|
@ -288,6 +289,8 @@ dbus_object_path dbus_object_path_new(const char *name, const struct dbus_interf
|
||||||
iface_dst_ptr++;
|
iface_dst_ptr++;
|
||||||
iface_dst_ptr->iface = NULL;
|
iface_dst_ptr->iface = NULL;
|
||||||
|
|
||||||
|
opath_ptr->registered = false;
|
||||||
|
|
||||||
return (dbus_object_path)opath_ptr;
|
return (dbus_object_path)opath_ptr;
|
||||||
|
|
||||||
free_ifaces:
|
free_ifaces:
|
||||||
|
@ -302,11 +305,21 @@ fail:
|
||||||
|
|
||||||
#define opath_ptr ((struct dbus_object_path *)data)
|
#define opath_ptr ((struct dbus_object_path *)data)
|
||||||
|
|
||||||
|
void dbus_object_path_unregister(DBusConnection * connection_ptr, dbus_object_path data)
|
||||||
|
{
|
||||||
|
ASSERT(opath_ptr->registered);
|
||||||
|
|
||||||
|
if (!dbus_connection_unregister_object_path(connection_ptr, opath_ptr->name))
|
||||||
|
{
|
||||||
|
log_error("dbus_connection_unregister_object_path() failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void dbus_object_path_destroy(DBusConnection * connection_ptr, dbus_object_path data)
|
void dbus_object_path_destroy(DBusConnection * connection_ptr, dbus_object_path data)
|
||||||
{
|
{
|
||||||
log_debug("Destroying object path");
|
log_debug("Destroying object path");
|
||||||
|
|
||||||
if (connection_ptr != NULL && !dbus_connection_unregister_object_path(connection_ptr, opath_ptr->name))
|
if (opath_ptr->registered && connection_ptr != NULL && !dbus_connection_unregister_object_path(connection_ptr, opath_ptr->name))
|
||||||
{
|
{
|
||||||
log_error("dbus_connection_unregister_object_path() failed.");
|
log_error("dbus_connection_unregister_object_path() failed.");
|
||||||
}
|
}
|
||||||
|
@ -403,6 +416,8 @@ bool dbus_object_path_register(DBusConnection * connection_ptr, dbus_object_path
|
||||||
{
|
{
|
||||||
log_debug("Registering object path \"%s\"", opath_ptr->name);
|
log_debug("Registering object path \"%s\"", opath_ptr->name);
|
||||||
|
|
||||||
|
ASSERT(!opath_ptr->registered);
|
||||||
|
|
||||||
DBusObjectPathVTable vtable =
|
DBusObjectPathVTable vtable =
|
||||||
{
|
{
|
||||||
dbus_object_path_handler_unregister,
|
dbus_object_path_handler_unregister,
|
||||||
|
@ -410,7 +425,13 @@ bool dbus_object_path_register(DBusConnection * connection_ptr, dbus_object_path
|
||||||
NULL, NULL, NULL, NULL
|
NULL, NULL, NULL, NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
return dbus_connection_register_object_path(connection_ptr, opath_ptr->name, &vtable, opath_ptr);
|
if (!dbus_connection_register_object_path(connection_ptr, opath_ptr->name, &vtable, opath_ptr))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
opath_ptr->registered = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef opath_ptr
|
#undef opath_ptr
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/*
|
/*
|
||||||
* LADI Session Handler (ladish)
|
* LADI Session Handler (ladish)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008, 2009 Nedko Arnaudov <nedko@arnaudov.name>
|
* Copyright (C) 2008, 2009, 2010 Nedko Arnaudov <nedko@arnaudov.name>
|
||||||
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
|
* Copyright (C) 2008 Juuso Alasuutari <juuso.alasuutari@gmail.com>
|
||||||
*
|
*
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
|
@ -34,6 +34,7 @@ typedef struct dbus_object_path_tag { int unused; } * dbus_object_path;
|
||||||
|
|
||||||
dbus_object_path dbus_object_path_new(const char * name, const struct dbus_interface_descriptor * iface, ...);
|
dbus_object_path dbus_object_path_new(const char * name, const struct dbus_interface_descriptor * iface, ...);
|
||||||
bool dbus_object_path_register(DBusConnection * connection_ptr, dbus_object_path opath);
|
bool dbus_object_path_register(DBusConnection * connection_ptr, dbus_object_path opath);
|
||||||
|
void dbus_object_path_unregister(DBusConnection * connection_ptr, dbus_object_path opath);
|
||||||
void dbus_object_path_destroy(DBusConnection * connection_ptr, dbus_object_path opath);
|
void dbus_object_path_destroy(DBusConnection * connection_ptr, dbus_object_path opath);
|
||||||
|
|
||||||
#endif /* __LASH_DBUS_OBJECT_PATH_H__ */
|
#endif /* __LASH_DBUS_OBJECT_PATH_H__ */
|
||||||
|
|
Loading…
Reference in New Issue