From 706229337a5233f4a0360276a825e938aa1ffa60 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Sun, 9 Aug 2009 20:05:02 +0300 Subject: [PATCH] IsStudioLoaded method --- daemon/dbus_iface_control.c | 35 ++++++++++++++++++++++++++++++++++ gui/lash_proxy.cpp | 38 ++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/daemon/dbus_iface_control.c b/daemon/dbus_iface_control.c index bd61f307..38892aab 100644 --- a/daemon/dbus_iface_control.c +++ b/daemon/dbus_iface_control.c @@ -33,6 +33,36 @@ #define INTERFACE_NAME DBUS_NAME_BASE ".Control" +static void ladish_is_studio_loaded(method_call_t * call_ptr) +{ + DBusMessageIter iter; + dbus_bool_t is_loaded; + + is_loaded = g_studio != NULL; + + call_ptr->reply = dbus_message_new_method_return(call_ptr->message); + if (call_ptr->reply == NULL) + { + goto fail; + } + + dbus_message_iter_init_append(call_ptr->reply, &iter); + + if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, &is_loaded)) + { + goto fail_unref; + } + + return; + +fail_unref: + dbus_message_unref(call_ptr->reply); + call_ptr->reply = NULL; + +fail: + lash_error("Ran out of memory trying to construct method return"); +} + static void ladish_get_studio_list(method_call_t * call_ptr) { DBusMessageIter iter, array_iter; @@ -205,6 +235,10 @@ void emit_studio_disappeared() signal_new_valist(g_dbus_connection, CONTROL_OBJECT_PATH, INTERFACE_NAME, "StudioDisappeared", DBUS_TYPE_INVALID); } +METHOD_ARGS_BEGIN(IsStudioLoaded, "Check whether studio D-Bus object is present") + METHOD_ARG_DESCRIBE_OUT("present", "b", "Whether studio D-Bus object is present") +METHOD_ARGS_END + METHOD_ARGS_BEGIN(GetStudioList, "Get list of studios") METHOD_ARG_DESCRIBE_OUT("studio_list", "a(sa{sv})", "List of studios, name and properties") METHOD_ARGS_END @@ -222,6 +256,7 @@ METHOD_ARGS_BEGIN(Exit, "Tell ladish D-Bus service to exit") METHOD_ARGS_END METHODS_BEGIN + METHOD_DESCRIBE(IsStudioLoaded, ladish_is_studio_loaded) METHOD_DESCRIBE(GetStudioList, ladish_get_studio_list) METHOD_DESCRIBE(LoadStudio, ladish_load_studio) METHOD_DESCRIBE(GetApplicationList, ladish_get_application_list) diff --git a/gui/lash_proxy.cpp b/gui/lash_proxy.cpp index 497768c6..2b4ca7bb 100644 --- a/gui/lash_proxy.cpp +++ b/gui/lash_proxy.cpp @@ -2,7 +2,7 @@ /* * LADI Session Handler (ladish) * - * Copyright (C) 2008 Nedko Arnaudov + * Copyright (C) 2008, 2009 Nedko Arnaudov * ************************************************************************** * This file contains code that communicates with ladishd through D-Bus @@ -37,7 +37,7 @@ #include "dbus_helpers.h" #define LASH_SERVICE DBUS_NAME_BASE -#define LASH_OBJECT "/" +#define LASH_OBJECT "/org/ladish/Control" #define LASH_IFACE_CONTROL DBUS_NAME_BASE ".Control" struct lash_proxy_impl @@ -46,6 +46,7 @@ struct lash_proxy_impl void fetch_loaded_projects(); void fetch_project_clients(boost::shared_ptr project_ptr); + bool is_studio_loaded(); static void error_msg(const std::string& msg); static void info_msg(const std::string& msg); @@ -121,7 +122,7 @@ lash_proxy_impl::init() // this also actiavtes lash object if it not activated already //fetch_loaded_projects(); - g_app->set_studio_availability(false); + g_app->set_studio_availability(is_studio_loaded()); } bool @@ -930,3 +931,34 @@ lash_proxy_impl::exit() dbus_message_unref(reply_ptr); } + +bool +lash_proxy_impl::is_studio_loaded() +{ + DBusMessage* reply_ptr; + const char * reply_signature; + DBusMessageIter iter; + dbus_bool_t is_loaded; + + if (!call(true, LASH_IFACE_CONTROL, "IsStudioLoaded", &reply_ptr, DBUS_TYPE_INVALID)) + { + error_msg("IsStudioLoaded() call failed."); + return false; + } + + reply_signature = dbus_message_get_signature(reply_ptr); + + if (strcmp(reply_signature, "b") != 0) + { + error_msg((std::string)"IsStudioLoaded() reply signature mismatch. " + reply_signature); + dbus_message_unref(reply_ptr); + return false; + } + + dbus_message_iter_init(reply_ptr, &iter); + + dbus_message_iter_get_basic(&iter, &is_loaded); + + dbus_message_unref(reply_ptr); + return is_loaded; +}