From 0686ff9c47006a9159441a9ffb417bbae5647816 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 31 Jul 2011 20:33:27 +0300 Subject: [PATCH] Notify ladishd when lash client is initialized --- dbus_constants.h | 3 +++ lash_compat/liblash/lash.c | 51 +++++++++++++++++++++++++++++++++++++- wscript | 6 ++++- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/dbus_constants.h b/dbus_constants.h index e49985a0..2781d5c1 100644 --- a/dbus_constants.h +++ b/dbus_constants.h @@ -45,6 +45,9 @@ #define IFACE_GRAPH_DICT DBUS_NAME_BASE ".GraphDict" #define IFACE_GRAPH_MANAGER DBUS_NAME_BASE ".GraphManager" #define IFACE_RECENT_ITEMS DBUS_NAME_BASE ".RecentItems" +#define LASH_SERVER_OBJECT_PATH DBUS_BASE_PATH "/LashServer" +#define IFACE_LASH_SERVER DBUS_NAME_BASE ".LashServer" +#define IFACE_LASH_CLIENT DBUS_NAME_BASE ".LashClient" #define JMCORE_SERVICE_NAME DBUS_NAME_BASE ".jmcore" #define JMCORE_IFACE JMCORE_SERVICE_NAME diff --git a/lash_compat/liblash/lash.c b/lash_compat/liblash/lash.c index 681bd839..900bcffd 100644 --- a/lash_compat/liblash/lash.c +++ b/lash_compat/liblash/lash.c @@ -33,6 +33,8 @@ #include "../../common/catdup.h" //#define LOG_OUTPUT_STDOUT #include "../../log.h" +#include "../../dbus/helpers.h" +#include "../../dbus_constants.h" struct _lash_client { @@ -72,16 +74,63 @@ void lash_args_destroy(lash_args_t * args) lash_client_t * lash_init(const lash_args_t * args, const char * class, int client_flags, lash_protocol_t protocol) { + DBusError error; + DBusMessage * msg_ptr; + const char * dbus_unique_name; + bool ret; + dbus_uint32_t flags32; + if ((client_flags & LASH_Server_Interface) != 0) { log_error("ladish does not implement LASH server interface."); - return NULL; + goto fail; + } + + dbus_error_init(&error); + cdbus_g_dbus_connection = dbus_bus_get_private(DBUS_BUS_SESSION, &error); + if (cdbus_g_dbus_connection == NULL) + { + log_error("Cannot connect to D-Bus session bus: %s", error.message); + dbus_error_free(&error); + goto fail; + } + + dbus_connection_set_exit_on_disconnect(cdbus_g_dbus_connection, FALSE); + + dbus_unique_name = dbus_bus_get_unique_name(cdbus_g_dbus_connection); + if (dbus_unique_name == NULL) + { + log_error("Failed to read unique bus name"); + goto close_connection; + } + + log_info("Connected to session bus, unique name is \"%s\"", dbus_unique_name); + + flags32 = client_flags; + msg_ptr = cdbus_new_method_call_message(SERVICE_NAME, LASH_SERVER_OBJECT_PATH, IFACE_LASH_SERVER, "Init", "su", &class, &flags32); + if (msg_ptr == NULL) + { + goto close_connection; + } + + ret = dbus_connection_send(cdbus_g_dbus_connection, msg_ptr, NULL); + dbus_message_unref(msg_ptr); + if (!ret) + { + log_error("Cannot send message over D-Bus due to lack of memory"); + goto close_connection; } log_debug("ladish LASH support initialized (%s %s)", (client_flags & LASH_Config_File) != 0 ? "file" : "", (client_flags & LASH_Config_Data_Set) != 0 ? "dict" : ""); g_client.flags = client_flags; return &g_client; + +close_connection: + dbus_connection_close(cdbus_g_dbus_connection); + dbus_connection_unref(cdbus_g_dbus_connection); +fail: + return NULL; } unsigned int lash_get_pending_event_count(lash_client_t * client_ptr) diff --git a/wscript b/wscript index b15261ab..d2e3b8a3 100644 --- a/wscript +++ b/wscript @@ -461,7 +461,11 @@ def build(bld): liblash.target = 'lash' liblash.vnum = "1.1.1" liblash.defines = ['LOG_OUTPUT_STDOUT'] - liblash.source = [os.path.join("lash_compat", "liblash", 'lash.c'), os.path.join("common", "catdup.c")] + liblash.source = [ + os.path.join("lash_compat", "liblash", 'lash.c'), + os.path.join("common", "catdup.c"), + os.path.join("dbus", "helpers.c"), + ] bld.install_files('${PREFIX}/include/lash', bld.path.ant_glob('lash_compat/liblash/lash/*.h'))