Sophie

Sophie

distrib > Mandriva > 2007.0 > x86_64 > media > main-release > by-pkgid > 926d2d1e3111287cee1b0a4fad4fb4f6 > files > 54

lib64dbus-1_3-devel-0.92-6mdv2007.0.x86_64.rpm

<!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-bus.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> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; </center>
<hr><h1>dbus-bus.c</h1><div class="fragment"><pre>00001 <font class="comment">/* -*- mode: C; c-file-style: "gnu" -*- */</font>
00002 <font class="comment">/* dbus-bus.c  Convenience functions for communicating with the bus.</font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * Copyright (C) 2003  CodeFactory AB</font>
00005 <font class="comment"> * Copyright (C) 2003  Red Hat, Inc.</font>
00006 <font class="comment"> *</font>
00007 <font class="comment"> * Licensed under the Academic Free License version 2.0</font>
00008 <font class="comment"> * </font>
00009 <font class="comment"> * This program is free software; you can redistribute it and/or modify</font>
00010 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00011 <font class="comment"> * the Free Software Foundation; either version 2 of the License, or</font>
00012 <font class="comment"> * (at your option) any later version.</font>
00013 <font class="comment"> *</font>
00014 <font class="comment"> * This program is distributed in the hope that it will be useful,</font>
00015 <font class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00016 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</font>
00017 <font class="comment"> * GNU General Public License for more details.</font>
00018 <font class="comment"> * </font>
00019 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00020 <font class="comment"> * along with this program; if not, write to the Free Software</font>
00021 <font class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA</font>
00022 <font class="comment"> *</font>
00023 <font class="comment"> */</font>
00024 
00025 <font class="preprocessor">#include "dbus-bus.h"</font>
00026 <font class="preprocessor">#include "dbus-protocol.h"</font>
00027 <font class="preprocessor">#include "dbus-internals.h"</font>
00028 <font class="preprocessor">#include "dbus-message.h"</font>
00029 <font class="preprocessor">#include &lt;string.h&gt;</font>
00030 
<a name="l00061"></a><a class="code" href="structBusData.html">00061</a> <font class="keyword">typedef</font> <font class="keyword">struct</font>
00062 <font class="keyword"></font>{
<a name="l00063"></a><a class="code" href="structBusData.html#m0">00063</a>   <a class="code" href="structDBusConnection.html">DBusConnection</a> *connection; 
<a name="l00064"></a><a class="code" href="structBusData.html#m1">00064</a>   <font class="keywordtype">char</font> *base_service; 
<a name="l00066"></a><a class="code" href="structBusData.html#m2">00066</a>   <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> is_well_known : 1; 
00067 } <a class="code" href="structBusData.html">BusData</a>;
00068 
00071 <font class="keyword">static</font> dbus_int32_t bus_data_slot = -1;
00072 
<a name="l00074"></a><a class="code" href="group__DBusBusInternals.html#a10">00074</a> <font class="preprocessor">#define N_BUS_TYPES 3</font>
00075 <font class="preprocessor"></font>
00076 <font class="keyword">static</font> <a class="code" href="structDBusConnection.html">DBusConnection</a> *bus_connections[N_BUS_TYPES];
00077 <font class="keyword">static</font> <font class="keywordtype">char</font> *bus_connection_addresses[N_BUS_TYPES] = { NULL, NULL, NULL };
00078 
00079 <font class="keyword">static</font> DBusBusType activation_bus_type = DBUS_BUS_ACTIVATION;
00080 
00081 <font class="keyword">static</font> dbus_bool_t initialized = FALSE;
00082 
00086 _DBUS_DEFINE_GLOBAL_LOCK (bus);
00087 
00088 <font class="keyword">static</font> <font class="keywordtype">void</font>
00089 addresses_shutdown_func (<font class="keywordtype">void</font> *data)
00090 {
00091   <font class="keywordtype">int</font> i;
00092 
00093   i = 0;
00094   <font class="keywordflow">while</font> (i &lt; N_BUS_TYPES)
00095     {
00096       <font class="keywordflow">if</font> (bus_connections[i] != NULL)
00097         _dbus_warn (<font class="stringliteral">"dbus_shutdown() called but connections were still live!"</font>);
00098       
00099       dbus_free (bus_connection_addresses[i]);
00100       bus_connection_addresses[i] = NULL;
00101       ++i;
00102     }
00103 
00104   activation_bus_type = DBUS_BUS_ACTIVATION;
00105 }
00106 
00107 <font class="keyword">static</font> dbus_bool_t
00108 get_from_env (<font class="keywordtype">char</font>           **connection_p,
00109               <font class="keyword">const</font> <font class="keywordtype">char</font>      *env_var)
00110 {
00111   <font class="keyword">const</font> <font class="keywordtype">char</font> *s;
00112   
00113   _dbus_assert (*connection_p == NULL);
00114   
00115   s = _dbus_getenv (env_var);
00116   <font class="keywordflow">if</font> (s == NULL || *s == <font class="charliteral">'\0'</font>)
00117     <font class="keywordflow">return</font> TRUE; <font class="comment">/* successfully didn't use the env var */</font>
00118   <font class="keywordflow">else</font>
00119     {
00120       *connection_p = _dbus_strdup (s);
00121       <font class="keywordflow">return</font> *connection_p != NULL;
00122     }
00123 }
00124 
00125 <font class="keyword">static</font> dbus_bool_t
00126 init_connections_unlocked (<font class="keywordtype">void</font>)
00127 {
00128   <font class="keywordflow">if</font> (!initialized)
00129     {
00130       <font class="keyword">const</font> <font class="keywordtype">char</font> *s;
00131       <font class="keywordtype">int</font> i;
00132 
00133       i = 0;
00134       <font class="keywordflow">while</font> (i &lt; N_BUS_TYPES)
00135         {
00136           bus_connections[i] = NULL;
00137           ++i;
00138         }
00139 
00140       <font class="comment">/* Don't init these twice, we may run this code twice if</font>
00141 <font class="comment">       * init_connections_unlocked() fails midway through.</font>
00142 <font class="comment">       * In practice, each block below should contain only one</font>
00143 <font class="comment">       * "return FALSE" or running through twice may not</font>
00144 <font class="comment">       * work right.</font>
00145 <font class="comment">       */</font>
00146       
00147        <font class="keywordflow">if</font> (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00148          {
00149            _dbus_verbose (<font class="stringliteral">"Filling in system bus address...\n"</font>);
00150            
00151            <font class="keywordflow">if</font> (!get_from_env (&amp;bus_connection_addresses[DBUS_BUS_SYSTEM],
00152                               <font class="stringliteral">"DBUS_SYSTEM_BUS_ADDRESS"</font>))
00153              <font class="keywordflow">return</font> FALSE;
00154          }
00155 
00156                   
00157        <font class="keywordflow">if</font> (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00158          {
00159            <font class="comment">/* Use default system bus address if none set in environment */</font>
00160            bus_connection_addresses[DBUS_BUS_SYSTEM] =
00161              _dbus_strdup (DBUS_SYSTEM_BUS_DEFAULT_ADDRESS);
00162            <font class="keywordflow">if</font> (bus_connection_addresses[DBUS_BUS_SYSTEM] == NULL)
00163              <font class="keywordflow">return</font> FALSE;
00164            
00165            _dbus_verbose (<font class="stringliteral">"  used default system bus \"%s\"\n"</font>,
00166                           bus_connection_addresses[DBUS_BUS_SYSTEM]);
00167          }
00168        <font class="keywordflow">else</font>
00169          _dbus_verbose (<font class="stringliteral">"  used env var system bus \"%s\"\n"</font>,
00170                         bus_connection_addresses[DBUS_BUS_SYSTEM]);
00171           
00172       <font class="keywordflow">if</font> (bus_connection_addresses[DBUS_BUS_SESSION] == NULL)
00173         {
00174           _dbus_verbose (<font class="stringliteral">"Filling in session bus address...\n"</font>);
00175           
00176           <font class="keywordflow">if</font> (!get_from_env (&amp;bus_connection_addresses[DBUS_BUS_SESSION],
00177                              <font class="stringliteral">"DBUS_SESSION_BUS_ADDRESS"</font>))
00178             <font class="keywordflow">return</font> FALSE;
00179           _dbus_verbose (<font class="stringliteral">"  \"%s\"\n"</font>, bus_connection_addresses[DBUS_BUS_SESSION] ?
00180                          bus_connection_addresses[DBUS_BUS_SESSION] : <font class="stringliteral">"none set"</font>);
00181         }
00182 
00183       <font class="keywordflow">if</font> (bus_connection_addresses[DBUS_BUS_ACTIVATION] == NULL)
00184         {
00185           _dbus_verbose (<font class="stringliteral">"Filling in activation bus address...\n"</font>);
00186           
00187           <font class="keywordflow">if</font> (!get_from_env (&amp;bus_connection_addresses[DBUS_BUS_ACTIVATION],
00188                              <font class="stringliteral">"DBUS_ACTIVATION_ADDRESS"</font>))
00189             <font class="keywordflow">return</font> FALSE;
00190           
00191           _dbus_verbose (<font class="stringliteral">"  \"%s\"\n"</font>, bus_connection_addresses[DBUS_BUS_ACTIVATION] ?
00192                          bus_connection_addresses[DBUS_BUS_ACTIVATION] : <font class="stringliteral">"none set"</font>);
00193         }
00194 
00195 
00196       <font class="keywordflow">if</font> (bus_connection_addresses[DBUS_BUS_ACTIVATION] != NULL)
00197         {
00198           s = _dbus_getenv (<font class="stringliteral">"DBUS_ACTIVATION_BUS_TYPE"</font>);
00199               
00200           <font class="keywordflow">if</font> (s != NULL)
00201             {
00202               _dbus_verbose (<font class="stringliteral">"Bus activation type was set to \"%s\"\n"</font>, s);
00203                   
00204               <font class="keywordflow">if</font> (strcmp (s, <font class="stringliteral">"system"</font>) == 0)
00205                 activation_bus_type = DBUS_BUS_SYSTEM;
00206               <font class="keywordflow">else</font> <font class="keywordflow">if</font> (strcmp (s, <font class="stringliteral">"session"</font>) == 0)
00207                 activation_bus_type = DBUS_BUS_SESSION;
00208             }
00209         }
00210       <font class="keywordflow">else</font>
00211         {
00212           <font class="comment">/* Default to the session bus instead if available */</font>
00213           <font class="keywordflow">if</font> (bus_connection_addresses[DBUS_BUS_SESSION] != NULL)
00214             {
00215               bus_connection_addresses[DBUS_BUS_ACTIVATION] =
00216                 _dbus_strdup (bus_connection_addresses[DBUS_BUS_SESSION]);
00217               <font class="keywordflow">if</font> (bus_connection_addresses[DBUS_BUS_ACTIVATION] == NULL)
00218                 <font class="keywordflow">return</font> FALSE;
00219             }
00220         }
00221       
00222       <font class="comment">/* If we return FALSE we have to be sure that restarting</font>
00223 <font class="comment">       * the above code will work right</font>
00224 <font class="comment">       */</font>
00225       
00226       <font class="keywordflow">if</font> (!_dbus_setenv (<font class="stringliteral">"DBUS_ACTIVATION_ADDRESS"</font>, NULL))
00227         <font class="keywordflow">return</font> FALSE;
00228 
00229       <font class="keywordflow">if</font> (!_dbus_setenv (<font class="stringliteral">"DBUS_ACTIVATION_BUS_TYPE"</font>, NULL))
00230         <font class="keywordflow">return</font> FALSE;
00231       
00232       <font class="keywordflow">if</font> (!_dbus_register_shutdown_func (addresses_shutdown_func,
00233                                          NULL))
00234         <font class="keywordflow">return</font> FALSE;
00235       
00236       initialized = TRUE;
00237     }
00238 
00239   <font class="keywordflow">return</font> initialized;
00240 }
00241 
00242 <font class="keyword">static</font> <font class="keywordtype">void</font>
00243 bus_data_free (<font class="keywordtype">void</font> *data)
00244 {
00245   <a class="code" href="structBusData.html">BusData</a> *bd = data;
00246   
00247   <font class="keywordflow">if</font> (bd-&gt;<a class="code" href="structBusData.html#m2">is_well_known</a>)
00248     {
00249       <font class="keywordtype">int</font> i;
00250       _DBUS_LOCK (bus);
00251       <font class="comment">/* We may be stored in more than one slot */</font>
00252       i = 0;
00253       <font class="keywordflow">while</font> (i &lt; N_BUS_TYPES)
00254         {
00255           <font class="keywordflow">if</font> (bus_connections[i] == bd-&gt;<a class="code" href="structBusData.html#m0">connection</a>)
00256             bus_connections[i] = NULL;
00257           
00258           ++i;
00259         }
00260       _DBUS_UNLOCK (bus);
00261     }
00262   
00263   dbus_free (bd-&gt;<a class="code" href="structBusData.html#m1">base_service</a>);
00264   dbus_free (bd);
00265 
00266   dbus_connection_free_data_slot (&amp;bus_data_slot);
00267 }
00268 
00269 <font class="keyword">static</font> <a class="code" href="structBusData.html">BusData</a>*
00270 ensure_bus_data (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection)
00271 {
00272   <a class="code" href="structBusData.html">BusData</a> *bd;
00273 
00274   <font class="keywordflow">if</font> (!dbus_connection_allocate_data_slot (&amp;bus_data_slot))
00275     <font class="keywordflow">return</font> NULL;
00276 
00277   bd = dbus_connection_get_data (connection, bus_data_slot);
00278   <font class="keywordflow">if</font> (bd == NULL)
00279     {      
00280       bd = dbus_new0 (<a class="code" href="structBusData.html">BusData</a>, 1);
00281       <font class="keywordflow">if</font> (bd == NULL)
00282         {
00283           dbus_connection_free_data_slot (&amp;bus_data_slot);
00284           <font class="keywordflow">return</font> NULL;
00285         }
00286 
00287       bd-&gt;<a class="code" href="structBusData.html#m0">connection</a> = connection;
00288       
00289       <font class="keywordflow">if</font> (!dbus_connection_set_data (connection, bus_data_slot, bd,
00290                                      bus_data_free))
00291         {
00292           dbus_free (bd);
00293           dbus_connection_free_data_slot (&amp;bus_data_slot);
00294           <font class="keywordflow">return</font> NULL;
00295         }
00296 
00297       <font class="comment">/* Data slot refcount now held by the BusData */</font>
00298     }
00299   <font class="keywordflow">else</font>
00300     {
00301       dbus_connection_free_data_slot (&amp;bus_data_slot);
00302     }
00303 
00304   <font class="keywordflow">return</font> bd;
00305 }
00306  <font class="comment">/* end of implementation details docs */</font>
00308 
00324 <a class="code" href="structDBusConnection.html">DBusConnection</a> *
<a name="l00325"></a><a class="code" href="group__DBusBus.html#a0">00325</a> dbus_bus_get (DBusBusType  type,
00326               <a class="code" href="structDBusError.html">DBusError</a>   *error)
00327 {
00328   <font class="keyword">const</font> <font class="keywordtype">char</font> *address;
00329   <a class="code" href="structDBusConnection.html">DBusConnection</a> *connection;
00330   <a class="code" href="structBusData.html">BusData</a> *bd;
00331   DBusBusType address_type;
00332 
00333   _dbus_return_val_if_fail (type &gt;= 0 &amp;&amp; type &lt; N_BUS_TYPES, NULL);
00334   _dbus_return_val_if_error_is_set (error, NULL);
00335 
00336   _DBUS_LOCK (bus);
00337 
00338   <font class="keywordflow">if</font> (!init_connections_unlocked ())
00339     {
00340       _DBUS_UNLOCK (bus);
00341       dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
00342       <font class="keywordflow">return</font> NULL;
00343     }
00344 
00345   <font class="comment">/* We want to use the activation address even if the</font>
00346 <font class="comment">   * activating bus is the session or system bus,</font>
00347 <font class="comment">   * per the spec.</font>
00348 <font class="comment">   */</font>
00349   address_type = type;
00350   
00351   <font class="comment">/* Use the real type of the activation bus for getting its</font>
00352 <font class="comment">   * connection, but only if the real type's address is available. (If</font>
00353 <font class="comment">   * the activating bus isn't a well-known bus then</font>
00354 <font class="comment">   * activation_bus_type == DBUS_BUS_ACTIVATION)</font>
00355 <font class="comment">   */</font>
00356   <font class="keywordflow">if</font> (type == DBUS_BUS_ACTIVATION &amp;&amp;
00357       bus_connection_addresses[activation_bus_type] != NULL)
00358     type = activation_bus_type;
00359   
00360   <font class="keywordflow">if</font> (bus_connections[type] != NULL)
00361     {
00362       connection = bus_connections[type];
00363       dbus_connection_ref (connection);
00364       
00365       _DBUS_UNLOCK (bus);
00366       <font class="keywordflow">return</font> connection;
00367     }
00368 
00369   address = bus_connection_addresses[address_type];
00370   <font class="keywordflow">if</font> (address == NULL)
00371     {
00372       dbus_set_error (error, DBUS_ERROR_FAILED,
00373                       <font class="stringliteral">"Unable to determine the address of the message bus"</font>);
00374       _DBUS_UNLOCK (bus);
00375       <font class="keywordflow">return</font> NULL;
00376     }
00377 
00378   connection = dbus_connection_open (address, error);
00379   
00380   <font class="keywordflow">if</font> (!connection)
00381     {
00382       _DBUS_ASSERT_ERROR_IS_SET (error);
00383       _DBUS_UNLOCK (bus);
00384       <font class="keywordflow">return</font> NULL;
00385     }
00386 
00387   <font class="comment">/* By default we're bound to the lifecycle of</font>
00388 <font class="comment">   * the message bus.</font>
00389 <font class="comment">   */</font>
00390   dbus_connection_set_exit_on_disconnect (connection,
00391                                           TRUE);
00392   
00393   <font class="keywordflow">if</font> (!dbus_bus_register (connection, error))
00394     {
00395       _DBUS_ASSERT_ERROR_IS_SET (error);
00396       dbus_connection_disconnect (connection);
00397       dbus_connection_unref (connection);
00398 
00399       _DBUS_UNLOCK (bus);
00400       <font class="keywordflow">return</font> NULL;
00401     }
00402 
00403   bus_connections[type] = connection;
00404   bd = ensure_bus_data (connection);
00405   _dbus_assert (bd != NULL);
00406 
00407   bd-&gt;<a class="code" href="structBusData.html#m2">is_well_known</a> = TRUE;
00408 
00409   _DBUS_UNLOCK (bus);
00410   <font class="keywordflow">return</font> connection;
00411 }
00412 
00413 
00427 dbus_bool_t
<a name="l00428"></a><a class="code" href="group__DBusBus.html#a1">00428</a> dbus_bus_register (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection,
00429                    <a class="code" href="structDBusError.html">DBusError</a>      *error)
00430 {
00431   <a class="code" href="structDBusMessage.html">DBusMessage</a> *message, *reply;
00432   <font class="keywordtype">char</font> *name;
00433   <a class="code" href="structBusData.html">BusData</a> *bd;
00434   dbus_bool_t retval;
00435 
00436   _dbus_return_val_if_fail (connection != NULL, FALSE);
00437   _dbus_return_val_if_error_is_set (error, FALSE);
00438 
00439   retval = FALSE;
00440   
00441   bd = ensure_bus_data (connection);
00442   <font class="keywordflow">if</font> (bd == NULL)
00443     {
00444       _DBUS_SET_OOM (error);
00445       <font class="keywordflow">return</font> FALSE;
00446     }
00447 
00448   <font class="keywordflow">if</font> (bd-&gt;<a class="code" href="structBusData.html#m1">base_service</a> != NULL)
00449     {
00450       _dbus_warn (<font class="stringliteral">"Attempt to register the same DBusConnection with the message bus, but it is already registered\n"</font>);
00451       <font class="comment">/* This isn't an error, it's a programming bug. We'll be nice</font>
00452 <font class="comment">       * and not _dbus_assert_not_reached()</font>
00453 <font class="comment">       */</font>
00454       <font class="keywordflow">return</font> TRUE;
00455     }
00456   
00457   message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
00458                                           DBUS_PATH_ORG_FREEDESKTOP_DBUS,
00459                                           DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
00460                                           <font class="stringliteral">"Hello"</font>); 
00461 
00462   <font class="keywordflow">if</font> (!message)
00463     {
00464       _DBUS_SET_OOM (error);
00465       <font class="keywordflow">return</font> FALSE;
00466     }
00467   
00468   reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
00469 
00470   dbus_message_unref (message);
00471   
00472   <font class="keywordflow">if</font> (reply == NULL)
00473     <font class="keywordflow">goto</font> out;
00474   <font class="keywordflow">else</font> <font class="keywordflow">if</font> (dbus_set_error_from_message (error, reply))
00475     <font class="keywordflow">goto</font> out;
00476   <font class="keywordflow">else</font> <font class="keywordflow">if</font> (!dbus_message_get_args (reply, error,
00477                                    DBUS_TYPE_STRING, &amp;name,
00478                                    DBUS_TYPE_INVALID))
00479     <font class="keywordflow">goto</font> out;
00480   
00481   bd-&gt;<a class="code" href="structBusData.html#m1">base_service</a> = name;
00482 
00483   retval = TRUE;
00484   
00485  out:
00486   <font class="keywordflow">if</font> (reply)
00487     dbus_message_unref (reply);
00488 
00489   <font class="keywordflow">if</font> (!retval)
00490     _DBUS_ASSERT_ERROR_IS_SET (error);
00491   
00492   <font class="keywordflow">return</font> retval;
00493 }
00494 
00495 
00507 dbus_bool_t
<a name="l00508"></a><a class="code" href="group__DBusBus.html#a2">00508</a> dbus_bus_set_base_service (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection,
00509                            <font class="keyword">const</font> <font class="keywordtype">char</font>     *base_service)
00510 {
00511   <a class="code" href="structBusData.html">BusData</a> *bd;
00512 
00513   _dbus_return_val_if_fail (connection != NULL, FALSE);
00514   _dbus_return_val_if_fail (base_service != NULL, FALSE);
00515   
00516   bd = ensure_bus_data (connection);
00517   <font class="keywordflow">if</font> (bd == NULL)
00518     <font class="keywordflow">return</font> FALSE;
00519 
00520   _dbus_assert (bd-&gt;<a class="code" href="structBusData.html#m1">base_service</a> == NULL);
00521   
00522   bd-&gt;<a class="code" href="structBusData.html#m1">base_service</a> = _dbus_strdup (base_service);
00523   <font class="keywordflow">return</font> bd-&gt;<a class="code" href="structBusData.html#m1">base_service</a> != NULL;
00524 }
00525 
00534 <font class="keyword">const</font> <font class="keywordtype">char</font>*
<a name="l00535"></a><a class="code" href="group__DBusBus.html#a3">00535</a> dbus_bus_get_base_service (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection)
00536 {
00537   <a class="code" href="structBusData.html">BusData</a> *bd;
00538 
00539   _dbus_return_val_if_fail (connection != NULL, NULL);
00540   
00541   bd = ensure_bus_data (connection);
00542   <font class="keywordflow">if</font> (bd == NULL)
00543     <font class="keywordflow">return</font> NULL;
00544   
00545   <font class="keywordflow">return</font> bd-&gt;<a class="code" href="structBusData.html#m1">base_service</a>;
00546 }
00547 
00563 <font class="keywordtype">int</font>
<a name="l00564"></a><a class="code" href="group__DBusBus.html#a4">00564</a> dbus_bus_acquire_service (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection,
00565                           <font class="keyword">const</font> <font class="keywordtype">char</font>     *service_name,
00566                           <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font>    flags,
00567                           <a class="code" href="structDBusError.html">DBusError</a>      *error)
00568 {
00569   <a class="code" href="structDBusMessage.html">DBusMessage</a> *message, *reply;
00570   dbus_uint32_t service_result;
00571 
00572   _dbus_return_val_if_fail (connection != NULL, 0);
00573   _dbus_return_val_if_fail (service_name != NULL, 0);
00574   _dbus_return_val_if_error_is_set (error, 0);
00575   
00576   message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
00577                                           DBUS_PATH_ORG_FREEDESKTOP_DBUS,
00578                                           DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
00579                                           <font class="stringliteral">"AcquireService"</font>);
00580 
00581   <font class="keywordflow">if</font> (message == NULL)
00582     {
00583       _DBUS_SET_OOM (error);
00584       <font class="keywordflow">return</font> -1;
00585     }
00586  
00587   <font class="keywordflow">if</font> (!dbus_message_append_args (message,
00588                                  DBUS_TYPE_STRING, service_name,
00589                                  DBUS_TYPE_UINT32, flags,
00590                                  DBUS_TYPE_INVALID))
00591     {
00592       dbus_message_unref (message);
00593       _DBUS_SET_OOM (error);
00594       <font class="keywordflow">return</font> -1;
00595     }
00596   
00597   reply = dbus_connection_send_with_reply_and_block (connection, message, -1,
00598                                                      error);
00599   
00600   dbus_message_unref (message);
00601   
00602   <font class="keywordflow">if</font> (reply == NULL)
00603     {
00604       _DBUS_ASSERT_ERROR_IS_SET (error);
00605       <font class="keywordflow">return</font> -1;
00606     }  
00607 
00608   <font class="keywordflow">if</font> (dbus_set_error_from_message (error, reply))
00609     {
00610       _DBUS_ASSERT_ERROR_IS_SET (error);
00611       dbus_message_unref (reply);
00612       <font class="keywordflow">return</font> -1;
00613     }
00614   
00615   <font class="keywordflow">if</font> (!dbus_message_get_args (reply, error,
00616                               DBUS_TYPE_UINT32, &amp;service_result,
00617                               DBUS_TYPE_INVALID))
00618     {
00619       _DBUS_ASSERT_ERROR_IS_SET (error);
00620       dbus_message_unref (reply);
00621       <font class="keywordflow">return</font> -1;
00622     }
00623 
00624   dbus_message_unref (reply);
00625   
00626   <font class="keywordflow">return</font> service_result;
00627 }
00628 
00639 dbus_bool_t
<a name="l00640"></a><a class="code" href="group__DBusBus.html#a5">00640</a> dbus_bus_service_exists (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection,
00641                          <font class="keyword">const</font> <font class="keywordtype">char</font>     *service_name,
00642                          <a class="code" href="structDBusError.html">DBusError</a>      *error)
00643 {
00644   <a class="code" href="structDBusMessage.html">DBusMessage</a> *message, *reply;
00645   <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> exists;
00646 
00647   _dbus_return_val_if_fail (connection != NULL, FALSE);
00648   _dbus_return_val_if_fail (service_name != NULL, FALSE);
00649   _dbus_return_val_if_error_is_set (error, FALSE);
00650   
00651   message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
00652                                           DBUS_PATH_ORG_FREEDESKTOP_DBUS,
00653                                           DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
00654                                           <font class="stringliteral">"ServiceExists"</font>);
00655   <font class="keywordflow">if</font> (message == NULL)
00656     {
00657       _DBUS_SET_OOM (error);
00658       <font class="keywordflow">return</font> FALSE;
00659     }
00660   
00661   <font class="keywordflow">if</font> (!dbus_message_append_args (message,
00662                                  DBUS_TYPE_STRING, service_name,
00663                                  DBUS_TYPE_INVALID))
00664     {
00665       dbus_message_unref (message);
00666       _DBUS_SET_OOM (error);
00667       <font class="keywordflow">return</font> FALSE;
00668     }
00669   
00670   reply = dbus_connection_send_with_reply_and_block (connection, message, -1, error);
00671   dbus_message_unref (message);
00672 
00673   <font class="keywordflow">if</font> (reply == NULL)
00674     {
00675       _DBUS_ASSERT_ERROR_IS_SET (error);
00676       <font class="keywordflow">return</font> FALSE;
00677     }
00678 
00679   <font class="keywordflow">if</font> (!dbus_message_get_args (reply, error,
00680                               DBUS_TYPE_UINT32, &amp;exists,
00681                               DBUS_TYPE_INVALID))
00682     {
00683       _DBUS_ASSERT_ERROR_IS_SET (error);
00684       <font class="keywordflow">return</font> FALSE;
00685     }
00686   
00687   <font class="keywordflow">return</font> (exists != FALSE);
00688 }
00689 
00705 dbus_bool_t
<a name="l00706"></a><a class="code" href="group__DBusBus.html#a6">00706</a> dbus_bus_activate_service (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection,
00707                            <font class="keyword">const</font> <font class="keywordtype">char</font>     *service_name,
00708                            dbus_uint32_t   flags,
00709                            dbus_uint32_t  *result,
00710                            <a class="code" href="structDBusError.html">DBusError</a>      *error)
00711 {
00712   <a class="code" href="structDBusMessage.html">DBusMessage</a> *msg;
00713   <a class="code" href="structDBusMessage.html">DBusMessage</a> *reply;
00714 
00715   msg = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
00716                                       DBUS_PATH_ORG_FREEDESKTOP_DBUS,
00717                                       DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
00718                                       <font class="stringliteral">"ActivateService"</font>);
00719 
00720   <font class="keywordflow">if</font> (!dbus_message_append_args (msg, DBUS_TYPE_STRING, service_name,
00721                                  DBUS_TYPE_UINT32, flags, DBUS_TYPE_INVALID))
00722     {
00723       dbus_message_unref (msg);
00724       _DBUS_SET_OOM (error);
00725       <font class="keywordflow">return</font> FALSE;
00726     }
00727 
00728   reply = dbus_connection_send_with_reply_and_block (connection, msg,
00729                                                      -1, error);
00730   dbus_message_unref (msg);
00731 
00732   <font class="keywordflow">if</font> (reply == NULL)
00733     {
00734       _DBUS_ASSERT_ERROR_IS_SET (error);
00735       <font class="keywordflow">return</font> FALSE;
00736     }
00737 
00738   <font class="keywordflow">if</font> (dbus_set_error_from_message (error, reply))
00739     {
00740       _DBUS_ASSERT_ERROR_IS_SET (error);
00741       dbus_message_unref (reply);
00742       <font class="keywordflow">return</font> FALSE;
00743     }
00744 
00745   <font class="keywordflow">if</font> (result != NULL &amp;&amp;
00746       !dbus_message_get_args (reply, error, DBUS_TYPE_UINT32,
00747                               result, DBUS_TYPE_INVALID))
00748     {
00749       _DBUS_ASSERT_ERROR_IS_SET (error);
00750       dbus_message_unref (reply);
00751       <font class="keywordflow">return</font> FALSE;
00752     }
00753   
00754   dbus_message_unref (reply);
00755   <font class="keywordflow">return</font> TRUE;
00756 }
00757 
00758 <font class="keyword">static</font> <font class="keywordtype">void</font>
00759 send_no_return_values (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection,
00760                        <a class="code" href="structDBusMessage.html">DBusMessage</a>    *msg,
00761                        <a class="code" href="structDBusError.html">DBusError</a>      *error)
00762 {
00763   <font class="keywordflow">if</font> (error)
00764     {
00765       <font class="comment">/* Block to check success codepath */</font>
00766       <a class="code" href="structDBusMessage.html">DBusMessage</a> *reply;
00767       
00768       reply = dbus_connection_send_with_reply_and_block (connection, msg,
00769                                                          -1, error);
00770       
00771       <font class="keywordflow">if</font> (reply == NULL)
00772         {
00773           _DBUS_ASSERT_ERROR_IS_SET (error);
00774           <font class="keywordflow">return</font>;
00775         }
00776 
00777       <font class="keywordflow">if</font> (dbus_set_error_from_message (error, reply))
00778         {
00779           _DBUS_ASSERT_ERROR_IS_SET (error);
00780           dbus_message_unref (reply);
00781           <font class="keywordflow">return</font>;
00782         }
00783 
00784       dbus_message_unref (reply);
00785     }
00786   <font class="keywordflow">else</font>
00787     {
00788       <font class="comment">/* Silently-fail nonblocking codepath */</font>
00789       <font class="keywordflow">if</font> (!dbus_connection_send (connection, msg, NULL))
00790         <font class="keywordflow">return</font>;
00791     }
00792 }
00793 
00816 <font class="keywordtype">void</font>
<a name="l00817"></a><a class="code" href="group__DBusBus.html#a8">00817</a> dbus_bus_add_match (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection,
00818                     <font class="keyword">const</font> <font class="keywordtype">char</font>     *rule,
00819                     <a class="code" href="structDBusError.html">DBusError</a>      *error)
00820 {
00821   <a class="code" href="structDBusMessage.html">DBusMessage</a> *msg;
00822 
00823   msg = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
00824                                       DBUS_PATH_ORG_FREEDESKTOP_DBUS,
00825                                       DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
00826                                       <font class="stringliteral">"AddMatch"</font>);
00827 
00828   <font class="keywordflow">if</font> (!dbus_message_append_args (msg, DBUS_TYPE_STRING, rule,
00829                                  DBUS_TYPE_INVALID))
00830     {
00831       dbus_message_unref (msg);
00832       _DBUS_SET_OOM (error);
00833       <font class="keywordflow">return</font>;
00834     }
00835 
00836   send_no_return_values (connection, msg, error);
00837 
00838   dbus_message_unref (msg);
00839 }
00840 
00854 <font class="keywordtype">void</font>
<a name="l00855"></a><a class="code" href="group__DBusBus.html#a9">00855</a> dbus_bus_remove_match (<a class="code" href="structDBusConnection.html">DBusConnection</a> *connection,
00856                        <font class="keyword">const</font> <font class="keywordtype">char</font>     *rule,
00857                        <a class="code" href="structDBusError.html">DBusError</a>      *error)
00858 {
00859   <a class="code" href="structDBusMessage.html">DBusMessage</a> *msg;
00860 
00861   msg = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
00862                                       DBUS_PATH_ORG_FREEDESKTOP_DBUS,
00863                                       DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
00864                                       <font class="stringliteral">"RemoveMatch"</font>);
00865 
00866   <font class="keywordflow">if</font> (!dbus_message_append_args (msg, DBUS_TYPE_STRING, rule,
00867                                  DBUS_TYPE_INVALID))
00868     {
00869       dbus_message_unref (msg);
00870       _DBUS_SET_OOM (error);
00871       <font class="keywordflow">return</font>;
00872     }
00873 
00874   send_no_return_values (connection, msg, error);
00875 
00876   dbus_message_unref (msg);
00877 }
00878 
</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>