fixed all gcc warnings
[livewp] / applet / src / livewp-dbus.c
1 /* vim: set sw=4 ts=4 et: */
2 /*
3  * This file is part of Live Wallpaper (livewp)
4  * 
5  * Copyright (C) 2010 Vlad Vasiliev
6  * Copyright (C) 2010 Tanya Makova
7  *       for the code
8  * 
9  * This software is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1 of
12  * the License, or (at your option) any later version.
13  * 
14  * This software is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this software; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23 */
24
25 /*******************************************************************************/
26 #include "livewp-common.h"
27 #include "livewp-dbus.h"
28 /*******************************************************************************/
29 void
30 livewp_initialize_dbus(Animation_WallpaperPrivate *priv){
31     gchar       *filter_string;
32     DBusError   error;
33
34     dbus_error_init (&error);
35     /* Add D-BUS signal handler for 'status_changed' */
36 #if !defined APPLICATION
37     priv->dbus_conn = (DBusConnection *) osso_get_sys_dbus_connection(priv->osso);
38     priv->dbus_conn_session = (DBusConnection *) osso_get_dbus_connection(priv->osso);
39 #else
40     priv->dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
41     priv->dbus_conn_session = dbus_bus_get(DBUS_BUS_SESSION, NULL);
42 #endif
43
44     if (priv->dbus_conn_session){
45         filter_string =
46             g_strdup_printf("type='signal', interface='%s'", LIVEWP_SIGNAL_INTERFACE);
47         dbus_bus_add_match(priv->dbus_conn_session, filter_string, &error);
48         if (dbus_error_is_set(&error)){
49              fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
50              dbus_error_free(&error);
51         }
52         g_free(filter_string);
53         /* add the callback */
54         dbus_connection_add_filter(priv->dbus_conn_session,
55                                    (DBusHandleMessageFunction)get_livewp_signal_cb,
56                                    priv, NULL);
57     }
58 }
59 /*******************************************************************************/
60 void
61 livewp_deinitialize_dbus(Animation_WallpaperPrivate *priv){
62
63     gchar       *filter_string;
64     DBusError   error;
65
66     if (priv->dbus_conn){
67 #if defined APPLICATION
68          dbus_connection_close(priv->dbus_conn);
69          dbus_connection_unref(priv->dbus_conn);
70 #endif
71     }
72     if (priv->dbus_conn_session){
73         filter_string =
74                 g_strdup_printf("type='signal', interface='%s'", LIVEWP_SIGNAL_INTERFACE);
75
76         dbus_error_init (&error);
77         dbus_bus_remove_match(priv->dbus_conn_session, filter_string, &error);
78         if (!dbus_error_is_set(&error)){
79             dbus_connection_remove_filter(priv->dbus_conn_session,
80                                           (DBusHandleMessageFunction)get_livewp_signal_cb, 
81                                           NULL);
82         }else{
83       
84             fprintf(stderr,"dbus_bus_add_match failed: %s", error.message);
85             dbus_error_free(&error);
86         }
87
88          g_free(filter_string);
89     }
90
91 }
92 /*******************************************************************************/
93 void
94 send_dbus_signal (Animation_WallpaperPrivate *priv,
95                   const gchar *interface,
96                   const gchar *path,
97                   const gchar *member)
98 {
99   gboolean       success;
100   
101   DBusMessage *message = dbus_message_new (DBUS_MESSAGE_TYPE_SIGNAL);
102   dbus_message_set_interface (message, interface);
103   dbus_message_set_path (message, path);
104   dbus_message_set_member (message, member);
105   success = dbus_connection_send (priv->dbus_conn_session, message, NULL);
106   dbus_message_unref (message);
107   
108   fprintf (stderr, "%s '%s' message.\n",
109                                  success ? "Sent" : "Failed to send",
110                                  member);
111
112 }
113
114 /*******************************************************************************/
115 DBusHandlerResult
116 get_livewp_signal_cb(DBusConnection *conn, DBusMessage *msg, Animation_WallpaperPrivate *priv){
117
118 #ifdef DEBUGFUNCTIONCALL
119     START_FUNCTION;
120 #endif
121
122     if (dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_RELOAD_CONFIG)){
123         if(read_config(priv)){
124                 fprintf(stderr, "\nCan not read config file.\n");
125         }else{
126             read_config(priv);
127 #if  !(defined APPLICATION || defined CONTROLPANEL)
128             reload_scene(priv->desktop_plugin);
129 #endif
130         }
131     }
132 #ifndef APPLICATION
133 //    if (dbus_message_is_signal(msg, LIVEWP_SIGNAL_INTERFACE, LIVEWP_RELOAD_PLUGIN))
134 //        reload_livewp_plugin();
135 #endif
136     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
137 }
138 /*******************************************************************************/
139