<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>dbus-gproxy.c Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.2.15 --> <center> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="modules.html">Modules</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="pages.html">Related Pages</a> </center> <hr><h1>dbus-gproxy.c</h1><div class="fragment"><pre>00001 <font class="comment">/* -*- mode: C; c-file-style: "gnu" -*- */</font> 00002 <font class="comment">/* dbus-gcall.c convenience routines for calling methods, etc.</font> 00003 <font class="comment"> *</font> 00004 <font class="comment"> * Copyright (C) 2003 Red Hat, Inc.</font> 00005 <font class="comment"> *</font> 00006 <font class="comment"> * Licensed under the Academic Free License version 2.0</font> 00007 <font class="comment"> * </font> 00008 <font class="comment"> * This program is free software; you can redistribute it and/or modify</font> 00009 <font class="comment"> * it under the terms of the GNU General Public License as published by</font> 00010 <font class="comment"> * the Free Software Foundation; either version 2 of the License, or</font> 00011 <font class="comment"> * (at your option) any later version.</font> 00012 <font class="comment"> *</font> 00013 <font class="comment"> * This program is distributed in the hope that it will be useful,</font> 00014 <font class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</font> 00015 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</font> 00016 <font class="comment"> * GNU General Public License for more details.</font> 00017 <font class="comment"> * </font> 00018 <font class="comment"> * You should have received a copy of the GNU General Public License</font> 00019 <font class="comment"> * along with this program; if not, write to the Free Software</font> 00020 <font class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</font> 00021 <font class="comment"> *</font> 00022 <font class="comment"> */</font> 00023 <font class="preprocessor">#include "dbus-glib.h"</font> 00024 <font class="preprocessor">#include <string.h></font> 00025 <a name="l00036"></a><a class="code" href="group__DBusGLibInternals.html#a8">00036</a> <font class="keyword">typedef</font> <font class="keyword">struct </font><a class="code" href="structDBusGProxyManager.html">DBusGProxyManager</a> DBusGProxyManager; 00037 <a name="l00041"></a><a class="code" href="structDBusGProxy.html">00041</a> <font class="keyword">struct </font><a class="code" href="structDBusGProxy.html">DBusGProxy</a> 00042 { <a name="l00043"></a><a class="code" href="structDBusGProxy.html#m0">00043</a> GObject <a class="code" href="structDBusGProxy.html#m0">parent</a>; <a name="l00045"></a><a class="code" href="structDBusGProxy.html#m1">00045</a> DBusGProxyManager *<a class="code" href="structDBusGProxy.html#m1">manager</a>; <a name="l00046"></a><a class="code" href="structDBusGProxy.html#m2">00046</a> <font class="keywordtype">char</font> *<a class="code" href="structDBusGProxy.html#m2">service</a>; <a name="l00047"></a><a class="code" href="structDBusGProxy.html#m3">00047</a> <font class="keywordtype">char</font> *<a class="code" href="structDBusGProxy.html#m3">path</a>; <a name="l00048"></a><a class="code" href="structDBusGProxy.html#m4">00048</a> <font class="keywordtype">char</font> *<a class="code" href="structDBusGProxy.html#m4">interface</a>; 00049 }; 00050 <a name="l00054"></a><a class="code" href="structDBusGProxyClass.html">00054</a> <font class="keyword">struct </font><a class="code" href="structDBusGProxyClass.html">DBusGProxyClass</a> 00055 { <a name="l00056"></a><a class="code" href="structDBusGProxyClass.html#m0">00056</a> GObjectClass <a class="code" href="structDBusGProxyClass.html#m0">parent_class</a>; 00057 }; 00058 00059 <font class="keyword">static</font> <font class="keywordtype">void</font> dbus_gproxy_init (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy); 00060 <font class="keyword">static</font> <font class="keywordtype">void</font> dbus_gproxy_class_init (<a class="code" href="structDBusGProxyClass.html">DBusGProxyClass</a> *klass); 00061 <font class="keyword">static</font> <font class="keywordtype">void</font> dbus_gproxy_finalize (GObject *object); 00062 <font class="keyword">static</font> <font class="keywordtype">void</font> dbus_gproxy_dispose (GObject *object); 00063 <font class="keyword">static</font> <font class="keywordtype">void</font> dbus_gproxy_destroy (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy); 00064 <font class="keyword">static</font> <font class="keywordtype">void</font> dbus_gproxy_emit_received (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy, 00065 <a class="code" href="structDBusMessage.html">DBusMessage</a> *message); 00066 00067 <a name="l00072"></a><a class="code" href="structDBusGProxyList.html">00072</a> <font class="keyword">typedef</font> <font class="keyword">struct</font> 00073 <font class="keyword"></font>{ <a name="l00074"></a><a class="code" href="structDBusGProxyList.html#m0">00074</a> GSList *proxies; <a name="l00076"></a><a class="code" href="structDBusGProxyList.html#m1">00076</a> <font class="keywordtype">char</font> name[4]; 00081 } <a class="code" href="structDBusGProxyList.html">DBusGProxyList</a>; 00082 <a name="l00088"></a><a class="code" href="structDBusGProxyManager.html">00088</a> <font class="keyword">struct </font>DBusGProxyManager 00089 { <a name="l00090"></a><a class="code" href="structDBusGProxyManager.html#m0">00090</a> GStaticMutex <a class="code" href="structDBusGProxyManager.html#m0">lock</a>; <a name="l00091"></a><a class="code" href="structDBusGProxyManager.html#m1">00091</a> <font class="keywordtype">int</font> <a class="code" href="structDBusGProxyManager.html#m1">refcount</a>; <a name="l00092"></a><a class="code" href="structDBusGProxyManager.html#m2">00092</a> <a class="code" href="structDBusConnection.html">DBusConnection</a> *<a class="code" href="structDBusGProxyManager.html#m2">connection</a>; <a name="l00094"></a><a class="code" href="structDBusGProxyManager.html#m3">00094</a> GHashTable *<a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>; 00098 }; 00099 00100 <font class="keyword">static</font> DBusGProxyManager *dbus_gproxy_manager_ref (DBusGProxyManager *manager); 00101 <font class="keyword">static</font> DBusHandlerResult dbus_gproxy_manager_filter (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection, 00102 <a class="code" href="structDBusMessage.html">DBusMessage</a> *message, 00103 <font class="keywordtype">void</font> *user_data); 00104 <a name="l00106"></a><a class="code" href="group__DBusGLibInternals.html#a80">00106</a> <font class="preprocessor">#define LOCK_MANAGER(mgr) (g_static_mutex_lock (&(mgr)->lock))</font> 00107 <font class="preprocessor"></font> <a name="l00108"></a><a class="code" href="group__DBusGLibInternals.html#a81">00108</a> <font class="preprocessor">#define UNLOCK_MANAGER(mgr) (g_static_mutex_unlock (&(mgr)->lock))</font> 00109 <font class="preprocessor"></font> 00110 <font class="keyword">static</font> <font class="keywordtype">int</font> gproxy_manager_slot = -1; 00111 00112 <font class="comment">/* Lock controlling get/set manager as data on each connection */</font> 00113 <font class="keyword">static</font> GStaticMutex connection_gproxy_lock = G_STATIC_MUTEX_INIT; 00114 00115 <font class="keyword">static</font> DBusGProxyManager* 00116 dbus_gproxy_manager_get (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection) 00117 { 00118 DBusGProxyManager *manager; 00119 00120 dbus_connection_allocate_data_slot (&gproxy_manager_slot); 00121 <font class="keywordflow">if</font> (gproxy_manager_slot < 0) 00122 g_error (<font class="stringliteral">"out of memory"</font>); 00123 00124 g_static_mutex_lock (&connection_gproxy_lock); 00125 00126 manager = dbus_connection_get_data (connection, gproxy_manager_slot); 00127 <font class="keywordflow">if</font> (manager != NULL) 00128 { 00129 dbus_connection_free_data_slot (&gproxy_manager_slot); 00130 dbus_gproxy_manager_ref (manager); 00131 g_static_mutex_unlock (&connection_gproxy_lock); 00132 <font class="keywordflow">return</font> manager; 00133 } 00134 00135 manager = g_new0 (DBusGProxyManager, 1); 00136 00137 manager-><a class="code" href="structDBusGProxyManager.html#m1">refcount</a> = 1; 00138 manager-><a class="code" href="structDBusGProxyManager.html#m2">connection</a> = connection; 00139 00140 g_static_mutex_init (&manager-><a class="code" href="structDBusGProxyManager.html#m0">lock</a>); 00141 00142 <font class="comment">/* Proxy managers keep the connection alive, which means that</font> 00143 <font class="comment"> * DBusGProxy indirectly does. To free a connection you have to free</font> 00144 <font class="comment"> * all the proxies referring to it.</font> 00145 <font class="comment"> */</font> 00146 dbus_connection_ref (manager-><a class="code" href="structDBusGProxyManager.html#m2">connection</a>); 00147 00148 dbus_connection_set_data (connection, gproxy_manager_slot, 00149 manager, NULL); 00150 00151 dbus_connection_add_filter (connection, dbus_gproxy_manager_filter, 00152 manager, NULL); 00153 00154 g_static_mutex_unlock (&connection_gproxy_lock); 00155 00156 <font class="keywordflow">return</font> manager; 00157 } 00158 00159 <font class="keyword">static</font> DBusGProxyManager * 00160 dbus_gproxy_manager_ref (DBusGProxyManager *manager) 00161 { 00162 g_assert (manager != NULL); 00163 g_assert (manager-><a class="code" href="structDBusGProxyManager.html#m1">refcount</a> > 0); 00164 00165 LOCK_MANAGER (manager); 00166 00167 manager-><a class="code" href="structDBusGProxyManager.html#m1">refcount</a> += 1; 00168 00169 UNLOCK_MANAGER (manager); 00170 00171 <font class="keywordflow">return</font> manager; 00172 } 00173 00174 <font class="keyword">static</font> <font class="keywordtype">void</font> 00175 dbus_gproxy_manager_unref (DBusGProxyManager *manager) 00176 { 00177 g_assert (manager != NULL); 00178 g_assert (manager-><a class="code" href="structDBusGProxyManager.html#m1">refcount</a> > 0); 00179 00180 LOCK_MANAGER (manager); 00181 manager-><a class="code" href="structDBusGProxyManager.html#m1">refcount</a> -= 1; 00182 <font class="keywordflow">if</font> (manager-><a class="code" href="structDBusGProxyManager.html#m1">refcount</a> == 0) 00183 { 00184 UNLOCK_MANAGER (manager); 00185 00186 <font class="keywordflow">if</font> (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>) 00187 { 00188 <font class="comment">/* can't have any proxies left since they hold</font> 00189 <font class="comment"> * a reference to the proxy manager.</font> 00190 <font class="comment"> */</font> 00191 g_assert (g_hash_table_size (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>) == 0); 00192 00193 g_hash_table_destroy (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>); 00194 manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a> = NULL; 00195 } 00196 00197 g_static_mutex_free (&manager-><a class="code" href="structDBusGProxyManager.html#m0">lock</a>); 00198 00199 g_static_mutex_lock (&connection_gproxy_lock); 00200 00201 dbus_connection_remove_filter (manager-><a class="code" href="structDBusGProxyManager.html#m2">connection</a>, dbus_gproxy_manager_filter, 00202 manager); 00203 00204 dbus_connection_set_data (manager-><a class="code" href="structDBusGProxyManager.html#m2">connection</a>, 00205 gproxy_manager_slot, 00206 NULL, NULL); 00207 00208 g_static_mutex_unlock (&connection_gproxy_lock); 00209 00210 dbus_connection_unref (manager-><a class="code" href="structDBusGProxyManager.html#m2">connection</a>); 00211 g_free (manager); 00212 00213 dbus_connection_free_data_slot (&gproxy_manager_slot); 00214 } 00215 <font class="keywordflow">else</font> 00216 { 00217 UNLOCK_MANAGER (manager); 00218 } 00219 } 00220 00221 <font class="keyword">static</font> guint 00222 tristring_hash (gconstpointer key) 00223 { 00224 <font class="keyword">const</font> <font class="keywordtype">char</font> *p = key; 00225 guint h = *p; 00226 00227 <font class="keywordflow">if</font> (h) 00228 { 00229 <font class="keywordflow">for</font> (p += 1; *p != <font class="charliteral">'\0'</font>; p++) 00230 h = (h << 5) - h + *p; 00231 } 00232 00233 <font class="comment">/* skip nul and do the next substring */</font> 00234 <font class="keywordflow">for</font> (p += 1; *p != <font class="charliteral">'\0'</font>; p++) 00235 h = (h << 5) - h + *p; 00236 00237 <font class="comment">/* skip nul again and another substring */</font> 00238 <font class="keywordflow">for</font> (p += 1; *p != <font class="charliteral">'\0'</font>; p++) 00239 h = (h << 5) - h + *p; 00240 00241 <font class="keywordflow">return</font> h; 00242 } 00243 00244 <font class="keyword">static</font> gboolean 00245 strequal_len (<font class="keyword">const</font> <font class="keywordtype">char</font> *a, 00246 <font class="keyword">const</font> <font class="keywordtype">char</font> *b, 00247 size_t *lenp) 00248 { 00249 size_t a_len; 00250 size_t b_len; 00251 00252 a_len = strlen (a); 00253 b_len = strlen (b); 00254 00255 <font class="keywordflow">if</font> (a_len != b_len) 00256 <font class="keywordflow">return</font> FALSE; 00257 00258 <font class="keywordflow">if</font> (memcmp (a, b, a_len) != 0) 00259 <font class="keywordflow">return</font> FALSE; 00260 00261 *lenp = a_len; 00262 00263 <font class="keywordflow">return</font> TRUE; 00264 } 00265 00266 <font class="keyword">static</font> gboolean 00267 tristring_equal (gconstpointer a, 00268 gconstpointer b) 00269 { 00270 <font class="keyword">const</font> <font class="keywordtype">char</font> *ap = a; 00271 <font class="keyword">const</font> <font class="keywordtype">char</font> *bp = b; 00272 size_t len; 00273 00274 <font class="keywordflow">if</font> (!strequal_len (ap, bp, &len)) 00275 <font class="keywordflow">return</font> FALSE; 00276 00277 ap += len + 1; 00278 bp += len + 1; 00279 00280 <font class="keywordflow">if</font> (!strequal_len (ap, bp, &len)) 00281 <font class="keywordflow">return</font> FALSE; 00282 00283 ap += len + 1; 00284 bp += len + 1; 00285 00286 <font class="keywordflow">if</font> (strcmp (ap, bp) != 0) 00287 <font class="keywordflow">return</font> FALSE; 00288 00289 <font class="keywordflow">return</font> TRUE; 00290 } 00291 00292 <font class="keyword">static</font> <font class="keywordtype">char</font>* 00293 tristring_alloc_from_strings (size_t padding_before, 00294 <font class="keyword">const</font> <font class="keywordtype">char</font> *service, 00295 <font class="keyword">const</font> <font class="keywordtype">char</font> *path, 00296 <font class="keyword">const</font> <font class="keywordtype">char</font> *interface) 00297 { 00298 size_t service_len, iface_len, path_len, len; 00299 <font class="keywordtype">char</font> *tri; 00300 00301 <font class="keywordflow">if</font> (service) 00302 service_len = strlen (service); 00303 <font class="keywordflow">else</font> 00304 service_len = 0; 00305 00306 path_len = strlen (path); 00307 00308 iface_len = strlen (interface); 00309 00310 tri = g_malloc (padding_before + service_len + path_len + iface_len + 3); 00311 00312 len = padding_before; 00313 00314 <font class="keywordflow">if</font> (service) 00315 memcpy (&tri[len], service, service_len); 00316 00317 len += service_len; 00318 tri[len] = <font class="charliteral">'\0'</font>; 00319 len += 1; 00320 00321 g_assert (len == (padding_before + service_len + 1)); 00322 00323 memcpy (&tri[len], path, path_len); 00324 len += path_len; 00325 tri[len] = <font class="charliteral">'\0'</font>; 00326 len += 1; 00327 00328 g_assert (len == (padding_before + service_len + path_len + 2)); 00329 00330 memcpy (&tri[len], interface, iface_len); 00331 len += iface_len; 00332 tri[len] = <font class="charliteral">'\0'</font>; 00333 len += 1; 00334 00335 g_assert (len == (padding_before + service_len + path_len + iface_len + 3)); 00336 00337 <font class="keywordflow">return</font> tri; 00338 } 00339 00340 <font class="keyword">static</font> <font class="keywordtype">char</font>* 00341 tristring_from_proxy (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy) 00342 { 00343 <font class="keywordflow">return</font> tristring_alloc_from_strings (0, 00344 proxy-><a class="code" href="structDBusGProxy.html#m2">service</a>, 00345 proxy-><a class="code" href="structDBusGProxy.html#m3">path</a>, 00346 proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>); 00347 } 00348 00349 <font class="keyword">static</font> <font class="keywordtype">char</font>* 00350 tristring_from_message (<a class="code" href="structDBusMessage.html">DBusMessage</a> *message) 00351 { 00352 <font class="keywordflow">return</font> tristring_alloc_from_strings (0, 00353 dbus_message_get_sender (message), 00354 dbus_message_get_path (message), 00355 dbus_message_get_interface (message)); 00356 } 00357 00358 <font class="keyword">static</font> <a class="code" href="structDBusGProxyList.html">DBusGProxyList</a>* 00359 gproxy_list_new (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *first_proxy) 00360 { 00361 <a class="code" href="structDBusGProxyList.html">DBusGProxyList</a> *list; 00362 00363 list = (<font class="keywordtype">void</font>*) tristring_alloc_from_strings (G_STRUCT_OFFSET (<a class="code" href="structDBusGProxyList.html">DBusGProxyList</a>, name), 00364 first_proxy-><a class="code" href="structDBusGProxy.html#m2">service</a>, 00365 first_proxy-><a class="code" href="structDBusGProxy.html#m3">path</a>, 00366 first_proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>); 00367 list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a> = NULL; 00368 00369 <font class="keywordflow">return</font> list; 00370 } 00371 00372 <font class="keyword">static</font> <font class="keywordtype">void</font> 00373 gproxy_list_free (<a class="code" href="structDBusGProxyList.html">DBusGProxyList</a> *list) 00374 { 00375 <font class="comment">/* we don't hold a reference to the proxies in the list,</font> 00376 <font class="comment"> * as they ref the GProxyManager</font> 00377 <font class="comment"> */</font> 00378 g_slist_free (list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a>); 00379 00380 g_free (list); 00381 } 00382 00383 <font class="keyword">static</font> <font class="keywordtype">char</font>* 00384 gproxy_get_match_rule (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy) 00385 { 00386 <font class="comment">/* FIXME Escaping is required here */</font> 00387 00388 <font class="keywordflow">if</font> (proxy-><a class="code" href="structDBusGProxy.html#m2">service</a>) 00389 <font class="keywordflow">return</font> g_strdup_printf (<font class="stringliteral">"type='signal',sender='%s',path='%s',interface='%s'"</font>, 00390 proxy-><a class="code" href="structDBusGProxy.html#m2">service</a>, proxy-><a class="code" href="structDBusGProxy.html#m3">path</a>, proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>); 00391 <font class="keywordflow">else</font> 00392 <font class="keywordflow">return</font> g_strdup_printf (<font class="stringliteral">"type='signal',path='%s',interface='%s'"</font>, 00393 proxy-><a class="code" href="structDBusGProxy.html#m3">path</a>, proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>); 00394 } 00395 00396 <font class="keyword">static</font> <font class="keywordtype">void</font> 00397 dbus_gproxy_manager_register (DBusGProxyManager *manager, 00398 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy) 00399 { 00400 <a class="code" href="structDBusGProxyList.html">DBusGProxyList</a> *list; 00401 00402 LOCK_MANAGER (manager); 00403 00404 <font class="keywordflow">if</font> (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a> == NULL) 00405 { 00406 list = NULL; 00407 manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a> = g_hash_table_new_full (tristring_hash, 00408 tristring_equal, 00409 NULL, 00410 (GFreeFunc) gproxy_list_free); 00411 } 00412 <font class="keywordflow">else</font> 00413 { 00414 <font class="keywordtype">char</font> *tri; 00415 00416 tri = tristring_from_proxy (proxy); 00417 00418 list = g_hash_table_lookup (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>, tri); 00419 00420 g_free (tri); 00421 } 00422 00423 <font class="keywordflow">if</font> (list == NULL) 00424 { 00425 list = gproxy_list_new (proxy); 00426 00427 g_hash_table_replace (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>, 00428 list-><a class="code" href="structDBusGProxyList.html#m1">name</a>, list); 00429 } 00430 00431 <font class="keywordflow">if</font> (list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a> == NULL) 00432 { 00433 <font class="comment">/* We have to add the match rule to the server,</font> 00434 <font class="comment"> * but FIXME only if the server is a message bus,</font> 00435 <font class="comment"> * not if it's a peer.</font> 00436 <font class="comment"> */</font> 00437 <font class="keywordtype">char</font> *rule; 00438 00439 rule = gproxy_get_match_rule (proxy); 00440 00441 <font class="comment">/* We don't check for errors; it's not like anyone would handle them,</font> 00442 <font class="comment"> * and we don't want a round trip here.</font> 00443 <font class="comment"> */</font> 00444 dbus_bus_add_match (manager-><a class="code" href="structDBusGProxyManager.html#m2">connection</a>, 00445 rule, NULL); 00446 00447 g_free (rule); 00448 } 00449 00450 g_assert (g_slist_find (list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a>, proxy) == NULL); 00451 00452 list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a> = g_slist_prepend (list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a>, proxy); 00453 00454 UNLOCK_MANAGER (manager); 00455 } 00456 00457 <font class="keyword">static</font> <font class="keywordtype">void</font> 00458 dbus_gproxy_manager_unregister (DBusGProxyManager *manager, 00459 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy) 00460 { 00461 <a class="code" href="structDBusGProxyList.html">DBusGProxyList</a> *list; 00462 <font class="keywordtype">char</font> *tri; 00463 00464 LOCK_MANAGER (manager); 00465 00466 <font class="preprocessor">#ifndef G_DISABLE_CHECKS</font> 00467 <font class="preprocessor"></font> <font class="keywordflow">if</font> (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a> == NULL) 00468 { 00469 g_warning (<font class="stringliteral">"Trying to unregister a proxy but there aren't any registered"</font>); 00470 <font class="keywordflow">return</font>; 00471 } 00472 <font class="preprocessor">#endif</font> 00473 <font class="preprocessor"></font> 00474 tri = tristring_from_proxy (proxy); 00475 00476 list = g_hash_table_lookup (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>, tri); 00477 00478 <font class="preprocessor">#ifndef G_DISABLE_CHECKS</font> 00479 <font class="preprocessor"></font> <font class="keywordflow">if</font> (list == NULL) 00480 { 00481 g_warning (<font class="stringliteral">"Trying to unregister a proxy but it isn't registered"</font>); 00482 <font class="keywordflow">return</font>; 00483 } 00484 <font class="preprocessor">#endif</font> 00485 <font class="preprocessor"></font> 00486 g_assert (g_slist_find (list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a>, proxy) != NULL); 00487 00488 list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a> = g_slist_remove (list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a>, proxy); 00489 00490 g_assert (g_slist_find (list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a>, proxy) == NULL); 00491 00492 <font class="keywordflow">if</font> (list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a> == NULL) 00493 { 00494 g_hash_table_remove (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>, 00495 tri); 00496 list = NULL; 00497 } 00498 00499 <font class="keywordflow">if</font> (g_hash_table_size (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>) == 0) 00500 { 00501 g_hash_table_destroy (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>); 00502 manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a> = NULL; 00503 } 00504 00505 g_free (tri); 00506 00507 UNLOCK_MANAGER (manager); 00508 } 00509 00510 <font class="keyword">static</font> <font class="keywordtype">void</font> 00511 list_proxies_foreach (gpointer key, 00512 gpointer value, 00513 gpointer user_data) 00514 { 00515 <a class="code" href="structDBusGProxyList.html">DBusGProxyList</a> *list; 00516 GSList **ret; 00517 GSList *tmp; 00518 00519 list = value; 00520 ret = user_data; 00521 00522 tmp = list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a>; 00523 <font class="keywordflow">while</font> (tmp != NULL) 00524 { 00525 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy = DBUS_GPROXY (tmp->data); 00526 00527 g_object_ref (proxy); 00528 *ret = g_slist_prepend (*ret, proxy); 00529 00530 tmp = tmp->next; 00531 } 00532 } 00533 00534 <font class="keyword">static</font> GSList* 00535 dbus_gproxy_manager_list_all (DBusGProxyManager *manager) 00536 { 00537 GSList *ret; 00538 00539 ret = NULL; 00540 00541 <font class="keywordflow">if</font> (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>) 00542 { 00543 g_hash_table_foreach (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>, 00544 list_proxies_foreach, 00545 &ret); 00546 } 00547 00548 <font class="keywordflow">return</font> ret; 00549 } 00550 00551 <font class="keyword">static</font> DBusHandlerResult 00552 dbus_gproxy_manager_filter (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection, 00553 <a class="code" href="structDBusMessage.html">DBusMessage</a> *message, 00554 <font class="keywordtype">void</font> *user_data) 00555 { 00556 DBusGProxyManager *manager; 00557 00558 <font class="keywordflow">if</font> (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL) 00559 <font class="keywordflow">return</font> DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 00560 00561 manager = user_data; 00562 00563 dbus_gproxy_manager_ref (manager); 00564 00565 LOCK_MANAGER (manager); 00566 00567 <font class="keywordflow">if</font> (dbus_message_is_signal (message, 00568 DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL, 00569 <font class="stringliteral">"Disconnected"</font>)) 00570 { 00571 <font class="comment">/* Destroy all the proxies, quite possibly resulting in unreferencing</font> 00572 <font class="comment"> * the proxy manager and the connection as well.</font> 00573 <font class="comment"> */</font> 00574 GSList *all; 00575 GSList *tmp; 00576 00577 all = dbus_gproxy_manager_list_all (manager); 00578 00579 tmp = all; 00580 <font class="keywordflow">while</font> (tmp != NULL) 00581 { 00582 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy; 00583 00584 proxy = DBUS_GPROXY (tmp->data); 00585 00586 UNLOCK_MANAGER (manager); 00587 dbus_gproxy_destroy (proxy); 00588 g_object_unref (G_OBJECT (proxy)); 00589 LOCK_MANAGER (manager); 00590 00591 tmp = tmp->next; 00592 } 00593 00594 g_slist_free (all); 00595 00596 <font class="preprocessor">#ifndef G_DISABLE_CHECKS</font> 00597 <font class="preprocessor"></font> <font class="keywordflow">if</font> (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a> != NULL) 00598 g_warning (<font class="stringliteral">"Disconnection emitted \"destroy\" on all DBusGProxy, but somehow new proxies were created in response to one of those destroy signals. This will cause a memory leak."</font>); 00599 <font class="preprocessor">#endif</font> 00600 <font class="preprocessor"></font> } 00601 <font class="keywordflow">else</font> 00602 { 00603 <font class="keywordtype">char</font> *tri; 00604 <a class="code" href="structDBusGProxyList.html">DBusGProxyList</a> *list; 00605 00606 tri = tristring_from_message (message); 00607 00608 <font class="keywordflow">if</font> (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>) 00609 list = g_hash_table_lookup (manager-><a class="code" href="structDBusGProxyManager.html#m3">proxy_lists</a>, tri); 00610 <font class="keywordflow">else</font> 00611 list = NULL; 00612 00613 <font class="preprocessor">#if 0</font> 00614 <font class="preprocessor"></font> g_print (<font class="stringliteral">"proxy got %s,%s,%s = list %p\n"</font>, 00615 tri, 00616 tri + strlen (tri) + 1, 00617 tri + strlen (tri) + 1 + strlen (tri + strlen (tri) + 1) + 1, 00618 list); 00619 <font class="preprocessor">#endif</font> 00620 <font class="preprocessor"></font> 00621 g_free (tri); 00622 00623 <font class="comment">/* Emit the signal */</font> 00624 00625 <font class="keywordflow">if</font> (list != NULL) 00626 { 00627 GSList *tmp; 00628 GSList *copy; 00629 00630 copy = g_slist_copy (list-><a class="code" href="structDBusGProxyList.html#m0">proxies</a>); 00631 g_slist_foreach (copy, (GFunc) g_object_ref, NULL); 00632 00633 tmp = copy; 00634 <font class="keywordflow">while</font> (tmp != NULL) 00635 { 00636 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy; 00637 00638 proxy = DBUS_GPROXY (tmp->data); 00639 00640 UNLOCK_MANAGER (manager); 00641 dbus_gproxy_emit_received (proxy, message); 00642 g_object_unref (G_OBJECT (proxy)); 00643 LOCK_MANAGER (manager); 00644 00645 tmp = tmp->next; 00646 } 00647 00648 g_slist_free (copy); 00649 } 00650 } 00651 00652 UNLOCK_MANAGER (manager); 00653 dbus_gproxy_manager_unref (manager); 00654 00655 <font class="comment">/* "Handling" signals doesn't make sense, they are for everyone</font> 00656 <font class="comment"> * who cares</font> 00657 <font class="comment"> */</font> 00658 <font class="keywordflow">return</font> DBUS_HANDLER_RESULT_NOT_YET_HANDLED; 00659 } 00660 00661 00662 00663 <font class="comment">/* ---------- DBusGProxy -------------- */</font> 00664 00665 00666 00667 <font class="keyword">enum</font> 00668 { 00669 DESTROY, 00670 RECEIVED, 00671 LAST_SIGNAL 00672 }; 00673 00674 <font class="keyword">static</font> <font class="keywordtype">void</font> *parent_class; 00675 <font class="keyword">static</font> guint signals[LAST_SIGNAL] = { 0 }; 00676 00677 <font class="keyword">static</font> <font class="keywordtype">void</font> 00678 dbus_gproxy_init (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy) 00679 { 00680 <font class="comment">/* Nothing */</font> 00681 } 00682 00683 <font class="keyword">static</font> <font class="keywordtype">void</font> 00684 dbus_gproxy_class_init (<a class="code" href="structDBusGProxyClass.html">DBusGProxyClass</a> *klass) 00685 { 00686 GObjectClass *object_class = G_OBJECT_CLASS (klass); 00687 00688 parent_class = g_type_class_peek_parent (klass); 00689 00690 object_class->finalize = dbus_gproxy_finalize; 00691 object_class->dispose = dbus_gproxy_dispose; 00692 00693 signals[DESTROY] = 00694 g_signal_new (<font class="stringliteral">"destroy"</font>, 00695 G_OBJECT_CLASS_TYPE (object_class), 00696 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, 00697 0, 00698 NULL, NULL, 00699 g_cclosure_marshal_VOID__VOID, 00700 G_TYPE_NONE, 0); 00701 00702 signals[RECEIVED] = 00703 g_signal_new (<font class="stringliteral">"received"</font>, 00704 G_OBJECT_CLASS_TYPE (object_class), 00705 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, 00706 0, 00707 NULL, NULL, 00708 g_cclosure_marshal_VOID__BOXED, 00709 G_TYPE_NONE, 1, 00710 DBUS_TYPE_MESSAGE); 00711 } 00712 00713 00714 <font class="keyword">static</font> <font class="keywordtype">void</font> 00715 dbus_gproxy_dispose (GObject *object) 00716 { 00717 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy; 00718 00719 proxy = DBUS_GPROXY (object); 00720 00721 g_signal_emit (object, signals[DESTROY], 0); 00722 00723 G_OBJECT_CLASS (parent_class)->dispose (object); 00724 } 00725 00726 <font class="keyword">static</font> <font class="keywordtype">void</font> 00727 dbus_gproxy_finalize (GObject *object) 00728 { 00729 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy; 00730 00731 proxy = DBUS_GPROXY (object); 00732 00733 <font class="keywordflow">if</font> (proxy-><a class="code" href="structDBusGProxy.html#m1">manager</a>) 00734 { 00735 dbus_gproxy_manager_unregister (proxy-><a class="code" href="structDBusGProxy.html#m1">manager</a>, proxy); 00736 dbus_gproxy_manager_unref (proxy-><a class="code" href="structDBusGProxy.html#m1">manager</a>); 00737 } 00738 00739 g_free (proxy-><a class="code" href="structDBusGProxy.html#m2">service</a>); 00740 g_free (proxy-><a class="code" href="structDBusGProxy.html#m3">path</a>); 00741 g_free (proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>); 00742 00743 G_OBJECT_CLASS (parent_class)->finalize (object); 00744 } 00745 00746 <font class="keyword">static</font> <font class="keywordtype">void</font> 00747 dbus_gproxy_destroy (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy) 00748 { 00749 <font class="comment">/* FIXME do we need the GTK_IN_DESTRUCTION style flag</font> 00750 <font class="comment"> * from GtkObject?</font> 00751 <font class="comment"> */</font> 00752 g_object_run_dispose (G_OBJECT (proxy)); 00753 } 00754 00755 <font class="keyword">static</font> <font class="keywordtype">char</font>* 00756 create_signal_detail (<font class="keyword">const</font> <font class="keywordtype">char</font> *interface, 00757 <font class="keyword">const</font> <font class="keywordtype">char</font> *signal) 00758 { 00759 GString *str; 00760 00761 str = g_string_new (interface); 00762 00763 g_string_append (str, <font class="stringliteral">"."</font>); 00764 00765 g_string_append (str, signal); 00766 00767 <font class="keywordflow">return</font> g_string_free (str, FALSE); 00768 } 00769 00770 <font class="keyword">static</font> <font class="keywordtype">void</font> 00771 dbus_gproxy_emit_received (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy, 00772 <a class="code" href="structDBusMessage.html">DBusMessage</a> *message) 00773 { 00774 <font class="keyword">const</font> <font class="keywordtype">char</font> *interface; 00775 <font class="keyword">const</font> <font class="keywordtype">char</font> *signal; 00776 <font class="keywordtype">char</font> *detail; 00777 GQuark q; 00778 00779 interface = dbus_message_get_interface (message); 00780 signal = dbus_message_get_member (message); 00781 00782 g_assert (interface != NULL); 00783 g_assert (signal != NULL); 00784 00785 detail = create_signal_detail (interface, signal); 00786 00787 <font class="comment">/* If the quark isn't preexisting, there's no way there</font> 00788 <font class="comment"> * are any handlers connected. We don't want to create</font> 00789 <font class="comment"> * extra quarks for every possible signal.</font> 00790 <font class="comment"> */</font> 00791 q = g_quark_try_string (detail); 00792 00793 <font class="keywordflow">if</font> (q != 0) 00794 g_signal_emit (G_OBJECT (proxy), 00795 signals[RECEIVED], 00796 q, 00797 message); 00798 00799 g_free (detail); 00800 } 00801 00813 GType <a name="l00814"></a><a class="code" href="group__DBusGLib.html#a34">00814</a> dbus_gproxy_get_type (<font class="keywordtype">void</font>) 00815 { 00816 <font class="keyword">static</font> GType object_type = 0; 00817 00818 <font class="keywordflow">if</font> (!object_type) 00819 { 00820 <font class="keyword">static</font> <font class="keyword">const</font> GTypeInfo object_info = 00821 { 00822 <font class="keyword">sizeof</font> (DBusGProxyClass), 00823 (GBaseInitFunc) NULL, 00824 (GBaseFinalizeFunc) NULL, 00825 (GClassInitFunc) dbus_gproxy_class_init, 00826 NULL, <font class="comment">/* class_finalize */</font> 00827 NULL, <font class="comment">/* class_data */</font> 00828 <font class="keyword">sizeof</font> (DBusGProxy), 00829 0, <font class="comment">/* n_preallocs */</font> 00830 (GInstanceInitFunc) dbus_gproxy_init, 00831 }; 00832 00833 object_type = g_type_register_static (G_TYPE_OBJECT, 00834 <font class="stringliteral">"DBusGProxy"</font>, 00835 &object_info, 0); 00836 } 00837 00838 <font class="keywordflow">return</font> object_type; 00839 } 00840 00841 <font class="keyword">static</font> <a class="code" href="structDBusGProxy.html">DBusGProxy</a>* 00842 dbus_gproxy_new (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection, 00843 <font class="keyword">const</font> <font class="keywordtype">char</font> *service_name, 00844 <font class="keyword">const</font> <font class="keywordtype">char</font> *path_name, 00845 <font class="keyword">const</font> <font class="keywordtype">char</font> *interface_name) 00846 { 00847 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy; 00848 00849 g_assert (connection != NULL); 00850 00851 proxy = g_object_new (DBUS_TYPE_GPROXY, NULL); 00852 00853 <font class="comment">/* These should all be construct-only mandatory properties,</font> 00854 <font class="comment"> * for now we just don't let people use g_object_new().</font> 00855 <font class="comment"> */</font> 00856 00857 proxy-><a class="code" href="structDBusGProxy.html#m1">manager</a> = dbus_gproxy_manager_get (connection); 00858 00859 proxy-><a class="code" href="structDBusGProxy.html#m2">service</a> = g_strdup (service_name); 00860 proxy-><a class="code" href="structDBusGProxy.html#m3">path</a> = g_strdup (path_name); 00861 proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a> = g_strdup (interface_name); 00862 00863 dbus_gproxy_manager_register (proxy-><a class="code" href="structDBusGProxy.html#m1">manager</a>, proxy); 00864 00865 <font class="keywordflow">return</font> proxy; 00866 } 00867 00890 <a class="code" href="structDBusGProxy.html">DBusGProxy</a>* <a name="l00891"></a><a class="code" href="group__DBusGLib.html#a36">00891</a> dbus_gproxy_new_for_service (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection, 00892 <font class="keyword">const</font> <font class="keywordtype">char</font> *service_name, 00893 <font class="keyword">const</font> <font class="keywordtype">char</font> *path_name, 00894 <font class="keyword">const</font> <font class="keywordtype">char</font> *interface_name) 00895 { 00896 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy; 00897 00898 g_return_val_if_fail (connection != NULL, NULL); 00899 g_return_val_if_fail (service_name != NULL, NULL); 00900 g_return_val_if_fail (path_name != NULL, NULL); 00901 g_return_val_if_fail (interface_name != NULL, NULL); 00902 00903 proxy = dbus_gproxy_new (connection, service_name, 00904 path_name, interface_name); 00905 00906 <font class="keywordflow">return</font> proxy; 00907 } 00908 00932 <a class="code" href="structDBusGProxy.html">DBusGProxy</a>* <a name="l00933"></a><a class="code" href="group__DBusGLib.html#a37">00933</a> dbus_gproxy_new_for_service_owner (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection, 00934 <font class="keyword">const</font> <font class="keywordtype">char</font> *service_name, 00935 <font class="keyword">const</font> <font class="keywordtype">char</font> *path_name, 00936 <font class="keyword">const</font> <font class="keywordtype">char</font> *interface_name, 00937 GError **error) 00938 { 00939 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy; 00940 00941 <a class="code" href="structDBusMessage.html">DBusMessage</a> *request, *reply; 00942 <a class="code" href="structDBusError.html">DBusError</a> derror; 00943 <font class="keywordtype">char</font> *base_service_name; 00944 00945 g_return_val_if_fail (connection != NULL, NULL); 00946 g_return_val_if_fail (service_name != NULL, NULL); 00947 g_return_val_if_fail (path_name != NULL, NULL); 00948 g_return_val_if_fail (interface_name != NULL, NULL); 00949 00950 dbus_error_init (&derror); 00951 00952 proxy = NULL; 00953 base_service_name = NULL; 00954 reply = NULL; 00955 00956 request = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS, 00957 DBUS_PATH_ORG_FREEDESKTOP_DBUS, 00958 DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, 00959 <font class="stringliteral">"GetServiceOwner"</font>); 00960 <font class="keywordflow">if</font> (request == NULL) 00961 g_error (<font class="stringliteral">"Out of memory"</font>); 00962 00963 <font class="keywordflow">if</font> (! dbus_message_append_args (request, 00964 DBUS_TYPE_STRING, service_name, 00965 DBUS_TYPE_INVALID)) 00966 g_error (<font class="stringliteral">"Out of memory"</font>); 00967 00968 reply = dbus_connection_send_with_reply_and_block (connection, request, 00969 2000, &derror); 00970 <font class="keywordflow">if</font> (reply == NULL) 00971 <font class="keywordflow">goto</font> error; 00972 00973 <font class="keywordflow">if</font> (dbus_set_error_from_message (&derror, reply)) 00974 <font class="keywordflow">goto</font> error; 00975 00976 <font class="keywordflow">if</font> (! dbus_message_get_args (reply, &derror, 00977 DBUS_TYPE_STRING, &base_service_name, 00978 DBUS_TYPE_INVALID)) 00979 <font class="keywordflow">goto</font> error; 00980 00981 00982 proxy = dbus_gproxy_new (connection, base_service_name, 00983 path_name, interface_name); 00984 00985 <font class="keywordflow">goto</font> out; 00986 00987 error: 00988 g_assert (dbus_error_is_set (&derror)); 00989 dbus_set_g_error (error, &derror); 00990 dbus_error_free (&derror); 00991 00992 out: 00993 <font class="keywordflow">if</font> (request) 00994 dbus_message_unref (request); 00995 <font class="keywordflow">if</font> (reply) 00996 dbus_message_unref (reply); 00997 dbus_free (base_service_name); 00998 00999 <font class="keywordflow">return</font> proxy; 01000 } 01001 01016 <a class="code" href="structDBusGProxy.html">DBusGProxy</a>* <a name="l01017"></a><a class="code" href="group__DBusGLib.html#a38">01017</a> dbus_gproxy_new_for_peer (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection, 01018 <font class="keyword">const</font> <font class="keywordtype">char</font> *path_name, 01019 <font class="keyword">const</font> <font class="keywordtype">char</font> *interface_name) 01020 { 01021 <a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy; 01022 01023 g_return_val_if_fail (connection != NULL, NULL); 01024 g_return_val_if_fail (path_name != NULL, NULL); 01025 g_return_val_if_fail (interface_name != NULL, NULL); 01026 01027 proxy = dbus_gproxy_new (connection, NULL, 01028 path_name, interface_name); 01029 01030 <font class="keywordflow">return</font> proxy; 01031 } 01032 01052 <a class="code" href="structDBusPendingCall.html">DBusPendingCall</a>* <a name="l01053"></a><a class="code" href="group__DBusGLib.html#a39">01053</a> dbus_gproxy_begin_call (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy, 01054 <font class="keyword">const</font> <font class="keywordtype">char</font> *method, 01055 <font class="keywordtype">int</font> first_arg_type, 01056 ...) 01057 { 01058 <a class="code" href="structDBusPendingCall.html">DBusPendingCall</a> *pending; 01059 <a class="code" href="structDBusMessage.html">DBusMessage</a> *message; 01060 va_list args; 01061 01062 g_return_val_if_fail (DBUS_IS_GPROXY (proxy), NULL); 01063 01064 message = dbus_message_new_method_call (proxy-><a class="code" href="structDBusGProxy.html#m2">service</a>, 01065 proxy-><a class="code" href="structDBusGProxy.html#m3">path</a>, 01066 proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>, 01067 method); 01068 <font class="keywordflow">if</font> (message == NULL) 01069 <font class="keywordflow">goto</font> oom; 01070 01071 va_start (args, first_arg_type); 01072 <font class="keywordflow">if</font> (!dbus_message_append_args_valist (message, first_arg_type, 01073 args)) 01074 <font class="keywordflow">goto</font> oom; 01075 va_end (args); 01076 01077 <font class="keywordflow">if</font> (!dbus_connection_send_with_reply (proxy-><a class="code" href="structDBusGProxy.html#m1">manager</a>-><a class="code" href="structDBusGProxyManager.html#m2">connection</a>, 01078 message, 01079 &pending, 01080 -1)) 01081 <font class="keywordflow">goto</font> oom; 01082 01083 <font class="keywordflow">return</font> pending; 01084 01085 oom: 01086 <font class="comment">/* FIXME we should create a pending call that's</font> 01087 <font class="comment"> * immediately completed with an error status without</font> 01088 <font class="comment"> * ever going on the wire.</font> 01089 <font class="comment"> */</font> 01090 01091 g_error (<font class="stringliteral">"Out of memory"</font>); 01092 <font class="keywordflow">return</font> NULL; 01093 } 01094 01120 gboolean <a name="l01121"></a><a class="code" href="group__DBusGLib.html#a40">01121</a> dbus_gproxy_end_call (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy, 01122 <a class="code" href="structDBusPendingCall.html">DBusPendingCall</a> *pending, 01123 GError **error, 01124 <font class="keywordtype">int</font> first_arg_type, 01125 ...) 01126 { 01127 <a class="code" href="structDBusMessage.html">DBusMessage</a> *message; 01128 va_list args; 01129 <a class="code" href="structDBusError.html">DBusError</a> derror; 01130 01131 g_return_val_if_fail (DBUS_IS_GPROXY (proxy), FALSE); 01132 g_return_val_if_fail (pending != NULL, FALSE); 01133 01134 dbus_pending_call_block (pending); 01135 message = dbus_pending_call_get_reply (pending); 01136 01137 g_assert (message != NULL); 01138 01139 dbus_error_init (&derror); 01140 01141 <font class="keywordflow">switch</font> (dbus_message_get_type (message)) 01142 { 01143 <font class="keywordflow">case</font> DBUS_MESSAGE_TYPE_METHOD_RETURN: 01144 va_start (args, first_arg_type); 01145 <font class="keywordflow">if</font> (!dbus_message_get_args_valist (message, &derror, first_arg_type, args)) 01146 { 01147 va_end (args); 01148 <font class="keywordflow">goto</font> error; 01149 } 01150 va_end (args); 01151 01152 <font class="keywordflow">return</font> TRUE; 01153 01154 <font class="keywordflow">case</font> DBUS_MESSAGE_TYPE_ERROR: 01155 dbus_set_error_from_message (&derror, message); 01156 <font class="keywordflow">goto</font> error; 01157 01158 <font class="keywordflow">default</font>: 01159 dbus_set_error (&derror, DBUS_ERROR_FAILED, 01160 <font class="stringliteral">"Reply was neither a method return nor an exception"</font>); 01161 <font class="keywordflow">goto</font> error; 01162 } 01163 01164 error: 01165 dbus_set_g_error (error, &derror); 01166 dbus_error_free (&derror); 01167 <font class="keywordflow">return</font> FALSE; 01168 } 01169 01181 <font class="keywordtype">void</font> <a name="l01182"></a><a class="code" href="group__DBusGLib.html#a41">01182</a> dbus_gproxy_call_no_reply (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy, 01183 <font class="keyword">const</font> <font class="keywordtype">char</font> *method, 01184 <font class="keywordtype">int</font> first_arg_type, 01185 ...) 01186 { 01187 <a class="code" href="structDBusMessage.html">DBusMessage</a> *message; 01188 va_list args; 01189 01190 g_return_if_fail (DBUS_IS_GPROXY (proxy)); 01191 01192 message = dbus_message_new_method_call (proxy-><a class="code" href="structDBusGProxy.html#m2">service</a>, 01193 proxy-><a class="code" href="structDBusGProxy.html#m3">path</a>, 01194 proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>, 01195 method); 01196 <font class="keywordflow">if</font> (message == NULL) 01197 <font class="keywordflow">goto</font> oom; 01198 01199 dbus_message_set_no_reply (message, TRUE); 01200 01201 va_start (args, first_arg_type); 01202 <font class="keywordflow">if</font> (!dbus_message_append_args_valist (message, first_arg_type, 01203 args)) 01204 <font class="keywordflow">goto</font> oom; 01205 va_end (args); 01206 01207 <font class="keywordflow">if</font> (!dbus_connection_send (proxy-><a class="code" href="structDBusGProxy.html#m1">manager</a>-><a class="code" href="structDBusGProxyManager.html#m2">connection</a>, 01208 message, 01209 NULL)) 01210 <font class="keywordflow">goto</font> oom; 01211 01212 <font class="keywordflow">return</font>; 01213 01214 oom: 01215 g_error (<font class="stringliteral">"Out of memory"</font>); 01216 } 01217 01236 <font class="keywordtype">void</font> <a name="l01237"></a><a class="code" href="group__DBusGLib.html#a42">01237</a> dbus_gproxy_send (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy, 01238 <a class="code" href="structDBusMessage.html">DBusMessage</a> *message, 01239 dbus_uint32_t *client_serial) 01240 { 01241 g_return_if_fail (DBUS_IS_GPROXY (proxy)); 01242 01243 <font class="keywordflow">if</font> (proxy-><a class="code" href="structDBusGProxy.html#m2">service</a>) 01244 { 01245 <font class="keywordflow">if</font> (!dbus_message_set_destination (message, proxy-><a class="code" href="structDBusGProxy.html#m2">service</a>)) 01246 g_error (<font class="stringliteral">"Out of memory"</font>); 01247 } 01248 <font class="keywordflow">if</font> (proxy-><a class="code" href="structDBusGProxy.html#m3">path</a>) 01249 { 01250 <font class="keywordflow">if</font> (!dbus_message_set_path (message, proxy-><a class="code" href="structDBusGProxy.html#m3">path</a>)) 01251 g_error (<font class="stringliteral">"Out of memory"</font>); 01252 } 01253 <font class="keywordflow">if</font> (proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>) 01254 { 01255 <font class="keywordflow">if</font> (!dbus_message_set_interface (message, proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>)) 01256 g_error (<font class="stringliteral">"Out of memory"</font>); 01257 } 01258 01259 <font class="keywordflow">if</font> (!dbus_connection_send (proxy-><a class="code" href="structDBusGProxy.html#m1">manager</a>-><a class="code" href="structDBusGProxyManager.html#m2">connection</a>, message, client_serial)) 01260 g_error (<font class="stringliteral">"Out of memory\n"</font>); 01261 } 01262 01274 <font class="keywordtype">void</font> <a name="l01275"></a><a class="code" href="group__DBusGLib.html#a43">01275</a> dbus_gproxy_connect_signal (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy, 01276 <font class="keyword">const</font> <font class="keywordtype">char</font> *signal_name, 01277 DBusGProxySignalHandler handler, 01278 <font class="keywordtype">void</font> *data, 01279 GClosureNotify free_data_func) 01280 { 01281 GClosure *closure; 01282 <font class="keywordtype">char</font> *detail; 01283 01284 g_return_if_fail (DBUS_IS_GPROXY (proxy)); 01285 g_return_if_fail (signal_name != NULL); 01286 g_return_if_fail (handler != NULL); 01287 01288 detail = create_signal_detail (proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>, signal_name); 01289 01290 closure = g_cclosure_new (G_CALLBACK (handler), data, free_data_func); 01291 g_signal_connect_closure_by_id (G_OBJECT (proxy), 01292 signals[RECEIVED], 01293 g_quark_from_string (detail), 01294 closure, FALSE); 01295 01296 g_free (detail); 01297 } 01298 01308 <font class="keywordtype">void</font> <a name="l01309"></a><a class="code" href="group__DBusGLib.html#a44">01309</a> dbus_gproxy_disconnect_signal (<a class="code" href="structDBusGProxy.html">DBusGProxy</a> *proxy, 01310 <font class="keyword">const</font> <font class="keywordtype">char</font> *signal_name, 01311 DBusGProxySignalHandler handler, 01312 <font class="keywordtype">void</font> *data) 01313 { 01314 <font class="keywordtype">char</font> *detail; 01315 GQuark q; 01316 01317 g_return_if_fail (DBUS_IS_GPROXY (proxy)); 01318 g_return_if_fail (signal_name != NULL); 01319 g_return_if_fail (handler != NULL); 01320 01321 detail = create_signal_detail (proxy-><a class="code" href="structDBusGProxy.html#m4">interface</a>, signal_name); 01322 q = g_quark_try_string (detail); 01323 g_free (detail); 01324 01325 <font class="preprocessor">#ifndef G_DISABLE_CHECKS</font> 01326 <font class="preprocessor"></font> <font class="keywordflow">if</font> (q == 0) 01327 { 01328 g_warning (<font class="stringliteral">"%s: No signal handlers for %s found on this DBusGProxy"</font>, 01329 G_GNUC_FUNCTION, signal_name); 01330 <font class="keywordflow">return</font>; 01331 } 01332 <font class="preprocessor">#endif</font> 01333 <font class="preprocessor"></font> 01334 g_signal_handlers_disconnect_matched (G_OBJECT (proxy), 01335 G_SIGNAL_MATCH_DETAIL | 01336 G_SIGNAL_MATCH_FUNC | 01337 G_SIGNAL_MATCH_DATA, 01338 signals[RECEIVED], 01339 q, 01340 NULL, 01341 G_CALLBACK (handler), data); 01342 } 01343 01346 <font class="preprocessor">#ifdef DBUS_BUILD_TESTS</font> 01347 <font class="preprocessor"></font> 01353 dbus_bool_t 01354 _dbus_gproxy_test (<font class="keywordtype">void</font>) 01355 { 01356 01357 01358 <font class="keywordflow">return</font> TRUE; 01359 } 01360 01361 <font class="preprocessor">#endif </font><font class="comment">/* DBUS_BUILD_TESTS */</font> </pre></div><hr><address align="right"><small>Generated on Wed Jun 9 05:01:25 2004 for D-BUS by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.15 </small></address> </body> </html>