From: Vlad Vasiliev Date: Fri, 23 Apr 2010 11:35:18 +0000 (+0300) Subject: begun dbus X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;h=0d2148de7a243569183045fb0b57140b8fd86985;p=livewp begun dbus --- diff --git a/applet/src/Makefile.am b/applet/src/Makefile.am index f1047bb..adbb07b 100644 --- a/applet/src/Makefile.am +++ b/applet/src/Makefile.am @@ -3,7 +3,8 @@ SOURCE_FILES = livewp-main.c \ livewp-astro.c livewp-astro.h \ livewp-rules.c livewp-rules.h \ livewp-settings.c livewp-settings.h livewp-common.h \ - livewp-config.c livewp-config.h + livewp-config.c livewp-config.h \ + livewp-dbus.c livewp-dbus.h bin_PROGRAMS = livewp livewp_SOURCES = $(SOURCE_FILES) @@ -22,7 +23,8 @@ liblivewp_home_widget_la_SOURCES = livewp-main.c \ livewp-astro.c livewp-astro.h \ livewp-rules.c livewp-rules.h \ livewp-settings.c livewp-settings.h livewp-common.h \ - livewp-config.c livewp-config.h + livewp-config.c livewp-config.h \ + livewp-dbus.c livewp-dbus.h liblivewp_home_widget_la_LIBADD = $(EXAMPLE_LIBS) $(OSSO_LIBS) AM_CFLAGS = -Wall $(EXAMPLE_CFLAGS) $(OSSO_CFLAGS) diff --git a/applet/src/livewp-common.h b/applet/src/livewp-common.h index bb12fe4..4fe6bc7 100644 --- a/applet/src/livewp-common.h +++ b/applet/src/livewp-common.h @@ -62,6 +62,9 @@ struct _Animation_WallpaperPrivate GtkWidget *main_widget; GtkWidget *right_corner; AWallpaperPlugin *desktop_plugin; + DBusConnection *dbus_conn; + DBusConnection *dbus_conn_session; + osso_context_t *osso; }; struct _AWallpaperPlugin @@ -94,4 +97,10 @@ typedef struct { void (*func_probability)(gpointer); } Actor; +#define LIVEWP_SIGNAL_INTERFACE "org.maemo.livewp" +#define LIVEWP_SIGNAL_PATH "/org/maemo/livewp" +#define LIVEWP_SIGNAL_RELOAD_CONFIG_INTERFACE "org.maemo.livewp.reload_config" +#define LIVEWP_SIGNAL_RELOAD_CONFIG_PATH "/org/maemo/livewp/reload_config" +#define LIVEWP_RELOAD_CONFIG "reload_config" +#define LIVEWP_RELOAD_PLUGIN "reload_plugin" #endif diff --git a/applet/src/livewp-dbus.c b/applet/src/livewp-dbus.c new file mode 100644 index 0000000..5e2db50 --- /dev/null +++ b/applet/src/livewp-dbus.c @@ -0,0 +1,148 @@ +/* vim: set sw=4 ts=4 et: */ +/* + * This file is part of Live Wallpaper (livewp) + * + * Copyright (C) 2010 Vlad Vasiliev + * Copyright (C) 2010 Tanya Makova + * for the code + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA +*/ + +/*******************************************************************************/ +#include "livewp-common.h" +#include "livewp-dbus.h" +/*******************************************************************************/ +void +livewp_initialize_dbus(Animation_WallpaperPrivate *priv){ + gchar *tmp; + gchar *filter_string; + DBusError error; + +// if(!priv->dbus_is_initialize){ + dbus_error_init (&error); + /* Add D-BUS signal handler for 'status_changed' */ +#if !defined APPLICATION + priv->dbus_conn = (DBusConnection *) osso_get_sys_dbus_connection(priv->osso); + priv->dbus_conn_session = (DBusConnection *) osso_get_dbus_connection(priv->osso); +#else + priv->dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + priv->dbus_conn_session = dbus_bus_get(DBUS_BUS_SESSION, NULL); +#endif + + if (priv->dbus_conn_session){ + filter_string = + g_strdup_printf("type='signal', interface='%s'", LIVEWP_SIGNAL_INTERFACE); + dbus_bus_add_match(priv->dbus_conn_session, filter_string, &error); + if (dbus_error_is_set(&error)){ + fprintf(stderr,"dbus_bus_add_match failed: %s", error.message); + dbus_error_free(&error); + } + g_free(filter_string); + /* add the callback */ + dbus_connection_add_filter(priv->dbus_conn_session, + get_livewp_signal_cb, + NULL, NULL); + } + + // } + +} +/*******************************************************************************/ +void +livewp_deinitialize_dbus(Animation_WallpaperPrivate *priv){ +#ifdef DEBUGFUNCTIONCALL + START_FUNCTION; +#endif + gchar *filter_string; + DBusError error; + + if (priv->dbus_conn){ +#if defined APPLICATION + dbus_connection_close(priv->dbus_conn); + dbus_connection_unref(priv->dbus_conn); +#endif + } + if (priv->dbus_conn_session){ + filter_string = + g_strdup_printf("type='signal', interface='%s'", LIVEWP_SIGNAL_INTERFACE); + + dbus_error_init (&error); + dbus_bus_remove_match(priv->dbus_conn_session, filter_string, &error); + if (!dbus_error_is_set(&error)){ + dbus_connection_remove_filter(priv->dbus_conn_session, + (DBusHandleMessageFunction)get_livewp_signal_cb, + NULL); + }else{ + + fprintf(stderr,"dbus_bus_add_match failed: %s", error.message); + dbus_error_free(&error); + } + + g_free(filter_string); + } + +} +/*******************************************************************************/ +void +send_dbus_signal (const gchar *interface, + const gchar *path, + const gchar *member) +{ + gboolean success; + + DBusMessage *message = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL); + dbus_message_set_interface (message, interface); + dbus_message_set_path (message, path); + dbus_message_set_member (message, member); +// success = dbus_connection_send (priv->dbus_conn_session, message, NULL); + dbus_message_unref (message); + + fprintf (stderr, "%s '%s' message.\n", + success ? "Sent" : "Failed to send", + member); + +} + +/*******************************************************************************/ +DBusHandlerResult +get_livewp_signal_cb(DBusConnection *conn, DBusMessage *msg, Animation_WallpaperPrivate *priv){ + +#ifdef DEBUGFUNCTIONCALL + START_FUNCTION; +#endif +/* +#if defined APPLICATION + fprintf(stderr,"Application\n"); +#else + fprintf(stderr,"Plugin\n"); +#endif +*/ + if (dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_RELOAD_CONFIG)){ + if(read_config(priv)){ + fprintf(stderr, "\nCan not read config file.\n"); + }else{ + read_config(priv); + } + } +#ifndef APPLICATION +// if (dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_RELOAD_PLUGIN)) +// reload_livewp_plugin(); +#endif + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} +/*******************************************************************************/ + diff --git a/applet/src/livewp-dbus.h b/applet/src/livewp-dbus.h new file mode 100644 index 0000000..de903ce --- /dev/null +++ b/applet/src/livewp-dbus.h @@ -0,0 +1,38 @@ +/* vim: set sw=4 ts=4 et: */ +/* + * This file is part of Live Wallpaper (livewp) + * + * Copyright (C) 2010 Vlad Vasiliev + * Copyright (C) 2010 Tanya Makova + * for the code + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA +*/ +/*******************************************************************************/ +#ifndef _livewp_dbus_h +#define _livewp_dbus_h 1 +/*******************************************************************************/ +#include "livewp-common.h" +#include +#include +/*******************************************************************************/ +void livewp_initialize_dbus(Animation_WallpaperPrivate *priv); +void livewp_deinitialize_dbus(Animation_WallpaperPrivate *priv); +DBusHandlerResult +get_livewp_signal_cb(DBusConnection *conn, DBusMessage *msg, Animation_WallpaperPrivate *priv); +void send_dbus_signal (const gchar *interface, const gchar *path, const gchar *member); +/*******************************************************************************/ +#endif diff --git a/applet/src/livewp-main.c b/applet/src/livewp-main.c index 0b2332b..cfa03dd 100644 --- a/applet/src/livewp-main.c +++ b/applet/src/livewp-main.c @@ -44,7 +44,7 @@ main(int argc, char *argv[]) GtkWidget *btn_setting, *vbox; gint result; HildonProgram *app; - osso_context_t *osso_context=NULL; + Animation_WallpaperPrivate *priv = g_new0 (Animation_WallpaperPrivate, 1); #ifdef ENABLE_NLS @@ -58,8 +58,8 @@ main(int argc, char *argv[]) app = HILDON_PROGRAM (hildon_program_get_instance()); g_set_application_name (PACKAGE); - osso_context = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL); - if(!osso_context){ + priv->osso = osso_initialize("org.maemo.livewp", VERSION, TRUE, NULL); + if(!priv->osso){ fprintf(stderr,"osso_initialize failed\n"); return 1; }