1 /*
2 * This file is a part of the Cairo-Dock project
3 *
4 * Copyright : (C) see the 'copyright' file.
5 * E-mail    : see the 'copyright' file.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 
21 #ifndef __CAIRO_DOCK_DBUS__
22 #define  __CAIRO_DOCK_DBUS__
23 
24 #include <glib.h>
25 #include <dbus/dbus-glib.h>
26 #include <dbus/dbus-glib-bindings.h>
27 G_BEGIN_DECLS
28 
29 /**
30 *@file cairo-dock-dbus.h This class defines numerous convenient functions to use DBus inside Cairo-Dock.
31 * DBus is used to communicate and interact with other running applications.
32 */
33 
34 #if (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION < 29) // not needed before => http://developer.gnome.org/gobject/unstable/gobject-Generic-values.html#G-VALUE-INIT:CAPS
35 #define G_VALUE_INIT {0,{{0}}}  // bonne idee d'un dev de GTK, pour eviter les warnings de gcc.
36 #endif
37 
38 typedef void (*CairoDockDbusNameOwnerChangedFunc) (const gchar *cName, gboolean bOwned, gpointer data);
39 
40 /** Get the connection to the 'session' Bus.
41 *@return the connection to the bus.
42 */
43 DBusGConnection *cairo_dock_get_session_connection (void);
44 #define cairo_dock_get_dbus_connection cairo_dock_get_session_connection
45 
46 DBusGProxy *cairo_dock_get_main_proxy (void);
47 
48 DBusGProxy *cairo_dock_get_main_system_proxy (void);
49 
50 /**Register a new service on the session bus.
51 *@param cServiceName name of the service.
52 *@return TRUE in case of success, false otherwise.
53 */
54 gboolean cairo_dock_register_service_name (const gchar *cServiceName);
55 
56 /** Say if the bus is available or not.
57 *@return TRUE if the connection to the bus has been established.
58 */
59 gboolean cairo_dock_dbus_is_enabled (void);
60 
61 void cairo_dock_watch_dbus_name_owner (const char *cName, CairoDockDbusNameOwnerChangedFunc pCallback, gpointer data);
62 
63 void cairo_dock_stop_watching_dbus_name_owner (const char *cName, CairoDockDbusNameOwnerChangedFunc pCallback);
64 
65 
66 /** Create a new proxy for the 'session' connection.
67 *@param name a name on the bus.
68 *@param path the path.
69 *@param interface name of the interface.
70 *@return the newly created proxy. Use g_object_unref when your done with it.
71 */
72 DBusGProxy *cairo_dock_create_new_session_proxy (const char *name, const char *path, const char *interface);
73 #define cairo_dock_create_new_dbus_proxy cairo_dock_create_new_session_proxy
74 
75 /**Create a new proxy for the 'system' connection.
76 *@param name a name on the bus.
77 *@param path the path.
78 *@param interface name of the interface.
79 *@return the newly created proxy. Use g_object_unref when your done with it.
80 */
81 DBusGProxy *cairo_dock_create_new_system_proxy (const char *name, const char *path, const char *interface);
82 
83 typedef void (*CairoDockOnAppliPresentOnDbus) (gboolean bPresent, gpointer data);
84 
85 DBusGProxyCall *cairo_dock_dbus_detect_application_async (const gchar *cName, CairoDockOnAppliPresentOnDbus pCallback, gpointer user_data);
86 
87 DBusGProxyCall *cairo_dock_dbus_detect_system_application_async (const gchar *cName, CairoDockOnAppliPresentOnDbus pCallback, gpointer user_data);
88 
89 /** Detect if an application is currently running on Session bus.
90 *@param cName name of the application.
91 *@return TRUE if the application is running and has a service on the bus.
92 */
93 gboolean cairo_dock_dbus_detect_application (const gchar *cName);
94 
95 /** Detect if an application is currently running on System bus.
96 *@param cName name of the application.
97 *@return TRUE if the application is running and has a service on the bus.
98 */
99 gboolean cairo_dock_dbus_detect_system_application (const gchar *cName);
100 
101 
102 gchar **cairo_dock_dbus_get_services (void);
103 
104 /** Get the value of a 'boolean' parameter on the bus.
105 *@param pDbusProxy proxy to the connection.
106 *@param cAccessor name of the accessor.
107 *@return the value of the parameter.
108 */
109 gboolean cairo_dock_dbus_get_boolean (DBusGProxy *pDbusProxy, const gchar *cAccessor);
110 
111 /** Get the value of an 'unsigned integer' parameter non signe on the bus.
112 *@param pDbusProxy proxy to the connection.
113 *@param cAccessor name of the accessor.
114 *@return the value of the parameter.
115 */
116 guint cairo_dock_dbus_get_uinteger (DBusGProxy *pDbusProxy, const gchar *cAccessor);
117 
118 /** Get the value of a 'integer' parameter on the bus.
119 *@param pDbusProxy proxy to the connection.
120 *@param cAccessor name of the accessor.
121 *@return the value of the parameter.
122 */
123 int cairo_dock_dbus_get_integer (DBusGProxy *pDbusProxy, const gchar *cAccessor);
124 
125 /** Get the value of a 'string' parameter on the bus.
126 *@param pDbusProxy proxy to the connection.
127 *@param cAccessor name of the accessor.
128 *@return the value of the parameter, to be freeed with g_free.
129 */
130 gchar *cairo_dock_dbus_get_string (DBusGProxy *pDbusProxy, const gchar *cAccessor);
131 
132 /** Get the value of a 'string list' parameter on the bus.
133 *@param pDbusProxy proxy to the connection.
134 *@param cAccessor name of the accessor.
135 *@return the value of the parameter, to be freeed with g_strfreev.
136 */
137 gchar **cairo_dock_dbus_get_string_list (DBusGProxy *pDbusProxy, const gchar *cAccessor);
138 
139 GPtrArray *cairo_dock_dbus_get_array (DBusGProxy *pDbusProxy, const gchar *cAccessor);
140 
141 /** Get the value of an 'unsigned char' parameter on the bus.
142 *@param pDbusProxy proxy to the connection.
143 *@param cAccessor name of the accessor.
144 *@return the value of the parameter.
145 */
146 guchar *cairo_dock_dbus_get_uchar (DBusGProxy *pDbusProxy, const gchar *cAccessor);
147 
148 gdouble cairo_dock_dbus_get_double (DBusGProxy *pDbusProxy, const gchar *cAccessor);
149 
150 /** Call a command on the bus.
151 *@param pDbusProxy proxy to the connection.
152 *@param cCommand name of the commande.
153 */
154 void cairo_dock_dbus_call (DBusGProxy *pDbusProxy, const gchar *cCommand);
155 
156 
157 void cairo_dock_dbus_get_properties (DBusGProxy *pDbusProxy, const gchar *cCommand, const gchar *cInterface, const gchar *cProperty, GValue *vProperties);  /// deprecated...
158 
159 #define cairo_dock_dbus_get_property_in_value(pDbusProxy, cInterface, cProperty, pProperties) cairo_dock_dbus_get_property_in_value_with_timeout(pDbusProxy, cInterface, cProperty, pProperties, -1)
160 void cairo_dock_dbus_get_property_in_value_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, GValue *pProperty, gint iTimeOut);
161 
162 #define cairo_dock_dbus_get_property_as_boolean(pDbusProxy, cInterface, cProperty) cairo_dock_dbus_get_property_as_boolean_with_timeout(pDbusProxy, cInterface, cProperty, -1)
163 gboolean cairo_dock_dbus_get_property_as_boolean_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, gint iTimeOut);
164 
165 #define cairo_dock_dbus_get_property_as_int(pDbusProxy, cInterface, cProperty) cairo_dock_dbus_get_property_as_int_with_timeout(pDbusProxy, cInterface, cProperty, -1)
166 gint cairo_dock_dbus_get_property_as_int_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, gint iTimeOut);
167 
168 #define cairo_dock_dbus_get_property_as_uint(pDbusProxy, cInterface, cProperty) cairo_dock_dbus_get_property_as_uint_with_timeout(pDbusProxy, cInterface, cProperty, -1)
169 guint cairo_dock_dbus_get_property_as_uint_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, gint iTimeOut);
170 
171 #define cairo_dock_dbus_get_property_as_uchar(pDbusProxy, cInterface, cProperty) cairo_dock_dbus_get_property_as_uchar_with_timeout(pDbusProxy, cInterface, cProperty, -1)
172 guchar cairo_dock_dbus_get_property_as_uchar_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, gint iTimeOut);
173 
174 #define cairo_dock_dbus_get_property_as_double(pDbusProxy, cInterface, cProperty) cairo_dock_dbus_get_property_as_double_with_timeout(pDbusProxy, cInterface, cProperty, -1)
175 gdouble cairo_dock_dbus_get_property_as_double_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, gint iTimeOut);
176 
177 #define cairo_dock_dbus_get_property_as_string(pDbusProxy, cInterface, cProperty) cairo_dock_dbus_get_property_as_string_with_timeout(pDbusProxy, cInterface, cProperty, -1)
178 gchar *cairo_dock_dbus_get_property_as_string_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, gint iTimeOut);
179 
180 #define cairo_dock_dbus_get_property_as_object_path(pDbusProxy, cInterface, cProperty) cairo_dock_dbus_get_property_as_object_path_with_timeout(pDbusProxy, cInterface, cProperty, -1)
181 gchar *cairo_dock_dbus_get_property_as_object_path_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, gint iTimeOut);
182 
183 #define cairo_dock_dbus_get_property_as_boxed(pDbusProxy, cInterface, cProperty) cairo_dock_dbus_get_property_as_boxed_with_timeout(pDbusProxy, cInterface, cProperty, -1)
184 gpointer cairo_dock_dbus_get_property_as_boxed_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, gint iTimeOut);
185 
186 #define cairo_dock_dbus_get_property_as_string_list(pDbusProxy, cInterface, cProperty) cairo_dock_dbus_get_property_as_string_list_with_timeout(pDbusProxy, cInterface, cProperty, -1)
187 gchar **cairo_dock_dbus_get_property_as_string_list_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, gint iTimeOut);
188 
189 
190 #define cairo_dock_dbus_get_all_properties(pDbusProxy, cInterface) cairo_dock_dbus_get_all_properties_with_timeout(pDbusProxy, cInterface, -1)
191 GHashTable *cairo_dock_dbus_get_all_properties_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, gint iTimeOut);
192 
193 
194 #define cairo_dock_dbus_set_property(pDbusProxy, cInterface, cProperty, pProperty) cairo_dock_dbus_set_property_with_timeout(pDbusProxy, cInterface, cProperty, pProperty, -1)
195 void cairo_dock_dbus_set_property_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, GValue *pProperty, gint iTimeOut);
196 
197 #define cairo_dock_dbus_set_boolean_property(pDbusProxy, cInterface, cProperty, bValue) cairo_dock_dbus_set_boolean_property_with_timeout(pDbusProxy, cInterface, cProperty, bValue, -1)
198 void cairo_dock_dbus_set_boolean_property_with_timeout (DBusGProxy *pDbusProxy, const gchar *cInterface, const gchar *cProperty, gboolean bValue, gint iTimeOut);
199 
200 
201 G_END_DECLS
202 #endif
203