diff --git a/dbus/helpers.c b/dbus/helpers.c index 49309b1f..530b7b7a 100644 --- a/dbus/helpers.c +++ b/dbus/helpers.c @@ -231,3 +231,71 @@ fail: return ret; } +static +const char * +compose_signal_match( + const char * service, + const char * object, + const char * iface, + const char * signal) +{ + static char rule[1024]; + snprintf(rule, sizeof(rule), "type='signal',sender='%s',path='%s',interface='%s',member='%s'", service, object, iface, signal); + return rule; +} + +bool +dbus_register_object_signal_handler( + DBusConnection * connection, + const char * service, + const char * object, + const char * iface, + const char * const * signals, + DBusHandleMessageFunction handler, + void * handler_data) +{ + const char * const * signal; + + for (signal = signals; *signal != NULL; signal++) + { + dbus_bus_add_match(connection, compose_signal_match(service, object, iface, *signal), &g_dbus_error); + if (dbus_error_is_set(&g_dbus_error)) + { + lash_error("Failed to add D-Bus match rule: %s", g_dbus_error.message); + dbus_error_free(&g_dbus_error); + return false; + } + } + + dbus_connection_add_filter(g_dbus_connection, handler, handler_data, NULL); + + return true; +} + +bool +dbus_unregister_object_signal_handler( + DBusConnection * connection, + const char * service, + const char * object, + const char * iface, + const char * const * signals, + DBusHandleMessageFunction handler, + void * handler_data) +{ + const char * const * signal; + + for (signal = signals; *signal != NULL; signal++) + { + dbus_bus_remove_match(connection, compose_signal_match(service, object, iface, *signal), &g_dbus_error); + if (dbus_error_is_set(&g_dbus_error)) + { + lash_error("Failed to add D-Bus match rule: %s", g_dbus_error.message); + dbus_error_free(&g_dbus_error); + return false; + } + } + + dbus_connection_remove_filter(g_dbus_connection, handler, handler_data); + + return true; +} diff --git a/dbus/helpers.h b/dbus/helpers.h index 17e6854d..f99fb51b 100644 --- a/dbus/helpers.h +++ b/dbus/helpers.h @@ -28,6 +28,8 @@ #ifndef HELPERS_H__6C2107A6_A5E3_4806_869B_4BE609535BA2__INCLUDED #define HELPERS_H__6C2107A6_A5E3_4806_869B_4BE609535BA2__INCLUDED +#include + extern DBusConnection * g_dbus_connection; extern DBusError g_dbus_error; @@ -37,6 +39,26 @@ bool dbus_add_dict_entry_bool(DBusMessageIter * dict_iter_ptr, const char * key, bool dbus_call_simple(const char * service, const char * object, const char * iface, const char * method, char * input_signature, ...); +bool +dbus_register_object_signal_handler( + DBusConnection * connection, + const char * service, + const char * object, + const char * iface, + const char * const * signals, + DBusHandleMessageFunction handler, + void * handler_data); + +bool +dbus_unregister_object_signal_handler( + DBusConnection * connection, + const char * service, + const char * object, + const char * iface, + const char * const * signals, + DBusHandleMessageFunction handler, + void * handler_data); + #define DBUS_CALL_DEFAULT_TIMEOUT 1000 // in milliseconds #endif /* #ifndef HELPERS_H__6C2107A6_A5E3_4806_869B_4BE609535BA2__INCLUDED */ diff --git a/graph_proxy.c b/graph_proxy.c index 6594c192..d6dbb2e2 100644 --- a/graph_proxy.c +++ b/graph_proxy.c @@ -67,7 +67,7 @@ struct graph bool active; }; -DBusHandlerResult message_hook(DBusConnection *, DBusMessage *, void *); +static DBusHandlerResult message_hook(DBusConnection *, DBusMessage *, void *); static void clear(struct graph * graph_ptr) { @@ -562,6 +562,7 @@ graph_disconnect_ports( } } +static DBusHandlerResult message_hook( DBusConnection * connection, diff --git a/gui/common.h b/gui/common.h index d434d3cb..621be0d7 100644 --- a/gui/common.h +++ b/gui/common.h @@ -27,11 +27,7 @@ #ifndef COMMON_H__15E63B7A_8350_4ABD_B04C_592158354949__INCLUDED #define COMMON_H__15E63B7A_8350_4ABD_B04C_592158354949__INCLUDED -#include "config.h" /* configure stage result */ - -#include /* C99 bool */ -#include /* fixed bit size ints */ - +#include "../common.h" #include "../common/debug.h" /* log macros */ #endif /* #ifndef COMMON_H__15E63B7A_8350_4ABD_B04C_592158354949__INCLUDED */ diff --git a/gui/control_proxy.c b/gui/control_proxy.c new file mode 100644 index 00000000..8eb14a20 --- /dev/null +++ b/gui/control_proxy.c @@ -0,0 +1,97 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2009 Nedko Arnaudov + * + ************************************************************************** + * This file contains implementation of code that interfaces + * the ladishd Control object through D-Bus + ************************************************************************** + * + * LADI Session Handler is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * LADI Session Handler is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LADI Session Handler. If not, see + * or write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "control_proxy.h" +#include "../dbus/helpers.h" + +#define SERVICE DBUS_NAME_BASE +#define OBJECT DBUS_BASE_PATH "/Control" +#define IFACE DBUS_NAME_BASE ".Control" + +const char * g_signals[] = +{ + "StudioAppeared", + "StudioDisappeared", + NULL +}; + +static DBusHandlerResult message_hook(DBusConnection * connection, DBusMessage * message, void * data) +{ + const char * object_path; + + object_path = dbus_message_get_path(message); + if (object_path == NULL || strcmp(object_path, OBJECT) != 0) + { + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + + if (dbus_message_is_signal(message, IFACE, "StudioAppeared")) + { + lash_info("StudioAppeared"); + control_proxy_on_studio_appeared(); + return DBUS_HANDLER_RESULT_HANDLED; + } + + if (dbus_message_is_signal(message, IFACE, "StudioDisappeared")) + { + lash_info("StudioDisappeared"); + control_proxy_on_studio_disappeared(); + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +bool control_proxy_init(void) +{ + if (!dbus_register_object_signal_handler(g_dbus_connection, SERVICE, OBJECT, IFACE, g_signals, message_hook, NULL)) + { + return false; + } + + return true; +} + +void control_proxy_uninit(void) +{ + dbus_unregister_object_signal_handler(g_dbus_connection, SERVICE, OBJECT, IFACE, g_signals, message_hook, NULL); +} + +bool control_proxy_get_studio_list(struct list_head * studio_list) +{ + return false; +} + +bool control_proxy_load_studio(const char * studio_name) +{ + return false; +} + +bool control_proxy_exit(void) +{ + return false; +} diff --git a/gui/control_proxy.h b/gui/control_proxy.h new file mode 100644 index 00000000..a8feff17 --- /dev/null +++ b/gui/control_proxy.h @@ -0,0 +1,48 @@ +/* -*- Mode: C ; c-basic-offset: 2 -*- */ +/* + * LADI Session Handler (ladish) + * + * Copyright (C) 2009 Nedko Arnaudov + * + ************************************************************************** + * This file contains interface to code that interfaces + * the ladishd Control object through D-Bus + ************************************************************************** + * + * LADI Session Handler is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * LADI Session Handler is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LADI Session Handler. If not, see + * or write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef CONTROL_PROXY_H__8BC89E98_FE1B_4831_8B89_1A48F676E019__INCLUDED +#define CONTROL_PROXY_H__8BC89E98_FE1B_4831_8B89_1A48F676E019__INCLUDED + +#include "common.h" +#include "../common/klist.h" + +struct loadable_studio +{ + struct list_head siblings; + char * name; +}; + +bool control_proxy_init(void); +void control_proxy_uninit(void); +void control_proxy_on_studio_appeared(void); +void control_proxy_on_studio_disappeared(void); +bool control_proxy_get_studio_list(struct list_head * studio_list); +bool control_proxy_load_studio(const char * studio_name); +bool control_proxy_exit(void); + +#endif /* #ifndef CONTROL_PROXY_H__8BC89E98_FE1B_4831_8B89_1A48F676E019__INCLUDED */ diff --git a/gui/main.c b/gui/main.c index a19c2c93..3ffc16cd 100644 --- a/gui/main.c +++ b/gui/main.c @@ -31,6 +31,7 @@ #include "graph_canvas.h" #include "../jack_proxy.h" #include "dbus_helpers.h" +#include "control_proxy.h" #if 0 class Patchage { @@ -851,6 +852,14 @@ Patchage::is_canvas_empty() #endif #endif +void control_proxy_on_studio_appeared(void) +{ +} + +void control_proxy_on_studio_disappeared(void) +{ +} + graph_canvas_handle g_jack_graph_canvas; graph_handle g_jack_graph; @@ -879,6 +888,11 @@ int main(int argc, char** argv) patchage_dbus_init(); + if (!control_proxy_init()) + { + return 1; + } + graph_create(JACKDBUS_SERVICE, JACKDBUS_OBJECT, &g_jack_graph); graph_canvas_create(1600 * 2, 1200 * 2, &g_jack_graph_canvas); graph_canvas_attach(g_jack_graph_canvas, g_jack_graph); @@ -906,6 +920,7 @@ int main(int argc, char** argv) gtk_main(); + control_proxy_uninit(); uninit_glade(); return 0; diff --git a/wscript b/wscript index 21d0f2b4..00eeb541 100644 --- a/wscript +++ b/wscript @@ -278,6 +278,7 @@ def build(bld): 'canvas.cpp', 'graph_canvas.c', 'glade.c', + 'control_proxy.c', ]: gladish.source.append(os.path.join("gui", source))