Sophie

Sophie

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

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-watch.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-watch.c</h1><div class="fragment"><pre>00001 <font class="comment">/* -*- mode: C; c-file-style: "gnu" -*- */</font>
00002 <font class="comment">/* dbus-watch.c DBusWatch implementation</font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * Copyright (C) 2002, 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 
00024 <font class="preprocessor">#include "dbus-internals.h"</font>
00025 <font class="preprocessor">#include "dbus-watch.h"</font>
00026 <font class="preprocessor">#include "dbus-list.h"</font>
00027 
<a name="l00039"></a><a class="code" href="structDBusWatch.html">00039</a> <font class="keyword">struct </font><a class="code" href="structDBusWatch.html">DBusWatch</a>
00040 {
<a name="l00041"></a><a class="code" href="structDBusWatch.html#m0">00041</a>   <font class="keywordtype">int</font> <a class="code" href="structDBusWatch.html#m0">refcount</a>;                        
<a name="l00042"></a><a class="code" href="structDBusWatch.html#m1">00042</a>   <font class="keywordtype">int</font> <a class="code" href="structDBusWatch.html#m1">fd</a>;                              
<a name="l00043"></a><a class="code" href="structDBusWatch.html#m2">00043</a>   <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> <a class="code" href="structDBusWatch.html#m2">flags</a>;                  
<a name="l00045"></a><a class="code" href="structDBusWatch.html#m3">00045</a>   DBusWatchHandler <a class="code" href="structDBusWatch.html#m3">handler</a>;                    
<a name="l00046"></a><a class="code" href="structDBusWatch.html#m4">00046</a>   <font class="keywordtype">void</font> *<a class="code" href="structDBusWatch.html#m4">handler_data</a>;                          
<a name="l00047"></a><a class="code" href="structDBusWatch.html#m5">00047</a>   DBusFreeFunction <a class="code" href="structDBusWatch.html#m5">free_handler_data_function</a>; 
<a name="l00049"></a><a class="code" href="structDBusWatch.html#m6">00049</a>   <font class="keywordtype">void</font> *<a class="code" href="structDBusWatch.html#m6">data</a>;                          
<a name="l00050"></a><a class="code" href="structDBusWatch.html#m7">00050</a>   DBusFreeFunction <a class="code" href="structDBusWatch.html#m7">free_data_function</a>; 
<a name="l00051"></a><a class="code" href="structDBusWatch.html#m8">00051</a>   <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> <a class="code" href="structDBusWatch.html#m8">enabled</a> : 1;            
00052 };
00053 
00066 <a class="code" href="structDBusWatch.html">DBusWatch</a>*
<a name="l00067"></a><a class="code" href="group__DBusWatchInternals.html#a0">00067</a> _dbus_watch_new (<font class="keywordtype">int</font>               fd,
00068                  <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font>      flags,
00069                  dbus_bool_t       enabled,
00070                  DBusWatchHandler  handler,
00071                  <font class="keywordtype">void</font>             *data,
00072                  DBusFreeFunction  free_data_function)
00073 {
00074   <a class="code" href="structDBusWatch.html">DBusWatch</a> *watch;
00075 
00076 <font class="preprocessor">#define VALID_WATCH_FLAGS (DBUS_WATCH_WRITABLE | DBUS_WATCH_READABLE)</font>
00077 <font class="preprocessor"></font>  
00078   _dbus_assert ((flags &amp; VALID_WATCH_FLAGS) == flags);
00079   
00080   watch = dbus_new0 (<a class="code" href="structDBusWatch.html">DBusWatch</a>, 1);
00081   <font class="keywordflow">if</font> (watch == NULL)
00082     <font class="keywordflow">return</font> NULL;
00083   
00084   watch-&gt;<a class="code" href="structDBusWatch.html#m0">refcount</a> = 1;
00085   watch-&gt;<a class="code" href="structDBusWatch.html#m1">fd</a> = fd;
00086   watch-&gt;<a class="code" href="structDBusWatch.html#m2">flags</a> = flags;
00087   watch-&gt;<a class="code" href="structDBusWatch.html#m8">enabled</a> = enabled;
00088 
00089   watch-&gt;<a class="code" href="structDBusWatch.html#m3">handler</a> = handler;
00090   watch-&gt;<a class="code" href="structDBusWatch.html#m4">handler_data</a> = data;
00091   watch-&gt;<a class="code" href="structDBusWatch.html#m5">free_handler_data_function</a> = free_data_function;
00092   
00093   <font class="keywordflow">return</font> watch;
00094 }
00095 
00102 <a class="code" href="structDBusWatch.html">DBusWatch</a> *
<a name="l00103"></a><a class="code" href="group__DBusWatchInternals.html#a1">00103</a> _dbus_watch_ref (<a class="code" href="structDBusWatch.html">DBusWatch</a> *watch)
00104 {
00105   watch-&gt;<a class="code" href="structDBusWatch.html#m0">refcount</a> += 1;
00106 
00107   <font class="keywordflow">return</font> watch;
00108 }
00109 
00116 <font class="keywordtype">void</font>
<a name="l00117"></a><a class="code" href="group__DBusWatchInternals.html#a2">00117</a> _dbus_watch_unref (<a class="code" href="structDBusWatch.html">DBusWatch</a> *watch)
00118 {
00119   _dbus_assert (watch != NULL);
00120   _dbus_assert (watch-&gt;<a class="code" href="structDBusWatch.html#m0">refcount</a> &gt; 0);
00121 
00122   watch-&gt;<a class="code" href="structDBusWatch.html#m0">refcount</a> -= 1;
00123   <font class="keywordflow">if</font> (watch-&gt;<a class="code" href="structDBusWatch.html#m0">refcount</a> == 0)
00124     {
00125       dbus_watch_set_data (watch, NULL, NULL); <font class="comment">/* call free_data_function */</font>
00126 
00127       <font class="keywordflow">if</font> (watch-&gt;<a class="code" href="structDBusWatch.html#m5">free_handler_data_function</a>)
00128         (* watch-&gt;<a class="code" href="structDBusWatch.html#m5">free_handler_data_function</a>) (watch-&gt;<a class="code" href="structDBusWatch.html#m4">handler_data</a>);
00129       
00130       dbus_free (watch);
00131     }
00132 }
00133 
00144 <font class="keywordtype">void</font>
<a name="l00145"></a><a class="code" href="group__DBusWatchInternals.html#a3">00145</a> _dbus_watch_invalidate (<a class="code" href="structDBusWatch.html">DBusWatch</a> *watch)
00146 {
00147   watch-&gt;<a class="code" href="structDBusWatch.html#m1">fd</a> = -1;
00148   watch-&gt;<a class="code" href="structDBusWatch.html#m2">flags</a> = 0;
00149 }
00150 
00160 <font class="keywordtype">void</font>
<a name="l00161"></a><a class="code" href="group__DBusWatchInternals.html#a4">00161</a> _dbus_watch_sanitize_condition (<a class="code" href="structDBusWatch.html">DBusWatch</a>    *watch,
00162                                 <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> *condition)
00163 {
00164   <font class="keywordflow">if</font> (!(watch-&gt;<a class="code" href="structDBusWatch.html#m2">flags</a> &amp; DBUS_WATCH_READABLE))
00165     *condition &amp;= ~DBUS_WATCH_READABLE;
00166   <font class="keywordflow">if</font> (!(watch-&gt;<a class="code" href="structDBusWatch.html#m2">flags</a> &amp; DBUS_WATCH_WRITABLE))
00167     *condition &amp;= ~DBUS_WATCH_WRITABLE;
00168 }
00169 
00170 
<a name="l00190"></a><a class="code" href="structDBusWatchList.html">00190</a> <font class="keyword">struct </font><a class="code" href="structDBusWatchList.html">DBusWatchList</a>
00191 {
<a name="l00192"></a><a class="code" href="structDBusWatchList.html#m0">00192</a>   <a class="code" href="structDBusList.html">DBusList</a> *<a class="code" href="structDBusWatchList.html#m0">watches</a>;           
<a name="l00194"></a><a class="code" href="structDBusWatchList.html#m1">00194</a>   DBusAddWatchFunction <a class="code" href="structDBusWatchList.html#m1">add_watch_function</a>;    
<a name="l00195"></a><a class="code" href="structDBusWatchList.html#m2">00195</a>   DBusRemoveWatchFunction <a class="code" href="structDBusWatchList.html#m2">remove_watch_function</a>; 
<a name="l00196"></a><a class="code" href="structDBusWatchList.html#m3">00196</a>   DBusWatchToggledFunction <a class="code" href="structDBusWatchList.html#m3">watch_toggled_function</a>; 
<a name="l00197"></a><a class="code" href="structDBusWatchList.html#m4">00197</a>   <font class="keywordtype">void</font> *<a class="code" href="structDBusWatchList.html#m4">watch_data</a>;                           
<a name="l00198"></a><a class="code" href="structDBusWatchList.html#m5">00198</a>   DBusFreeFunction <a class="code" href="structDBusWatchList.html#m5">watch_free_data_function</a>;  
00199 };
00200 
00207 <a class="code" href="structDBusWatchList.html">DBusWatchList</a>*
<a name="l00208"></a><a class="code" href="group__DBusWatchInternals.html#a5">00208</a> _dbus_watch_list_new (<font class="keywordtype">void</font>)
00209 {
00210   <a class="code" href="structDBusWatchList.html">DBusWatchList</a> *watch_list;
00211 
00212   watch_list = dbus_new0 (<a class="code" href="structDBusWatchList.html">DBusWatchList</a>, 1);
00213   <font class="keywordflow">if</font> (watch_list == NULL)
00214     <font class="keywordflow">return</font> NULL;
00215 
00216   <font class="keywordflow">return</font> watch_list;
00217 }
00218 
00224 <font class="keywordtype">void</font>
<a name="l00225"></a><a class="code" href="group__DBusWatchInternals.html#a6">00225</a> _dbus_watch_list_free (<a class="code" href="structDBusWatchList.html">DBusWatchList</a> *watch_list)
00226 {
00227   <font class="comment">/* free watch_data and removes watches as a side effect */</font>
00228   _dbus_watch_list_set_functions (watch_list,
00229                                   NULL, NULL, NULL, NULL, NULL);
00230   _dbus_list_foreach (&amp;watch_list-&gt;<a class="code" href="structDBusWatchList.html#m0">watches</a>,
00231                       (DBusForeachFunction) _dbus_watch_unref,
00232                       NULL);
00233   _dbus_list_clear (&amp;watch_list-&gt;<a class="code" href="structDBusWatchList.html#m0">watches</a>);
00234 
00235   dbus_free (watch_list);
00236 }
00237 
00252 dbus_bool_t
<a name="l00253"></a><a class="code" href="group__DBusWatchInternals.html#a7">00253</a> _dbus_watch_list_set_functions (<a class="code" href="structDBusWatchList.html">DBusWatchList</a>           *watch_list,
00254                                 DBusAddWatchFunction     add_function,
00255                                 DBusRemoveWatchFunction  remove_function,
00256                                 DBusWatchToggledFunction toggled_function,
00257                                 <font class="keywordtype">void</font>                    *data,
00258                                 DBusFreeFunction         free_data_function)
00259 {
00260   <font class="comment">/* Add watches with the new watch function, failing on OOM */</font>
00261   <font class="keywordflow">if</font> (add_function != NULL)
00262     {
00263       <a class="code" href="structDBusList.html">DBusList</a> *link;
00264       
00265       link = _dbus_list_get_first_link (&amp;watch_list-&gt;<a class="code" href="structDBusWatchList.html#m0">watches</a>);
00266       <font class="keywordflow">while</font> (link != NULL)
00267         {
00268           <a class="code" href="structDBusList.html">DBusList</a> *next = _dbus_list_get_next_link (&amp;watch_list-&gt;<a class="code" href="structDBusWatchList.html#m0">watches</a>,
00269                                                      link);
00270 
00271           _dbus_verbose (<font class="stringliteral">"Adding a watch on fd %d using newly-set add watch function\n"</font>,
00272                          dbus_watch_get_fd (link-&gt;<a class="code" href="structDBusList.html#m2">data</a>));
00273           
00274           <font class="keywordflow">if</font> (!(* add_function) (link-&gt;<a class="code" href="structDBusList.html#m2">data</a>, data))
00275             {
00276               <font class="comment">/* remove it all again and return FALSE */</font>
00277               <a class="code" href="structDBusList.html">DBusList</a> *link2;
00278               
00279               link2 = _dbus_list_get_first_link (&amp;watch_list-&gt;<a class="code" href="structDBusWatchList.html#m0">watches</a>);
00280               <font class="keywordflow">while</font> (link2 != link)
00281                 {
00282                   <a class="code" href="structDBusList.html">DBusList</a> *next = _dbus_list_get_next_link (&amp;watch_list-&gt;<a class="code" href="structDBusWatchList.html#m0">watches</a>,
00283                                                              link2);
00284                   
00285                   _dbus_verbose (<font class="stringliteral">"Removing watch on fd %d using newly-set remove function because initial add failed\n"</font>,
00286                                  dbus_watch_get_fd (link2-&gt;<a class="code" href="structDBusList.html#m2">data</a>));
00287                   
00288                   (* remove_function) (link2-&gt;<a class="code" href="structDBusList.html#m2">data</a>, data);
00289                   
00290                   link2 = next;
00291                 }
00292 
00293               <font class="keywordflow">return</font> FALSE;
00294             }
00295       
00296           link = next;
00297         }
00298     }
00299   
00300   <font class="comment">/* Remove all current watches from previous watch handlers */</font>
00301 
00302   <font class="keywordflow">if</font> (watch_list-&gt;<a class="code" href="structDBusWatchList.html#m2">remove_watch_function</a> != NULL)
00303     {
00304       _dbus_verbose (<font class="stringliteral">"Removing all pre-existing watches\n"</font>);
00305       
00306       _dbus_list_foreach (&amp;watch_list-&gt;<a class="code" href="structDBusWatchList.html#m0">watches</a>,
00307                           (DBusForeachFunction) watch_list-&gt;<a class="code" href="structDBusWatchList.html#m2">remove_watch_function</a>,
00308                           watch_list-&gt;<a class="code" href="structDBusWatchList.html#m4">watch_data</a>);
00309     }
00310 
00311   <font class="keywordflow">if</font> (watch_list-&gt;<a class="code" href="structDBusWatchList.html#m5">watch_free_data_function</a> != NULL)
00312     (* watch_list-&gt;<a class="code" href="structDBusWatchList.html#m5">watch_free_data_function</a>) (watch_list-&gt;<a class="code" href="structDBusWatchList.html#m4">watch_data</a>);
00313   
00314   watch_list-&gt;<a class="code" href="structDBusWatchList.html#m1">add_watch_function</a> = add_function;
00315   watch_list-&gt;<a class="code" href="structDBusWatchList.html#m2">remove_watch_function</a> = remove_function;
00316   watch_list-&gt;<a class="code" href="structDBusWatchList.html#m3">watch_toggled_function</a> = toggled_function;
00317   watch_list-&gt;<a class="code" href="structDBusWatchList.html#m4">watch_data</a> = data;
00318   watch_list-&gt;<a class="code" href="structDBusWatchList.html#m5">watch_free_data_function</a> = free_data_function;
00319 
00320   <font class="keywordflow">return</font> TRUE;
00321 }
00322 
00331 dbus_bool_t
<a name="l00332"></a><a class="code" href="group__DBusWatchInternals.html#a8">00332</a> _dbus_watch_list_add_watch (<a class="code" href="structDBusWatchList.html">DBusWatchList</a> *watch_list,
00333                             <a class="code" href="structDBusWatch.html">DBusWatch</a>     *watch)
00334 {
00335   <font class="keywordflow">if</font> (!_dbus_list_append (&amp;watch_list-&gt;<a class="code" href="structDBusWatchList.html#m0">watches</a>, watch))
00336     <font class="keywordflow">return</font> FALSE;
00337   
00338   _dbus_watch_ref (watch);
00339 
00340   <font class="keywordflow">if</font> (watch_list-&gt;<a class="code" href="structDBusWatchList.html#m1">add_watch_function</a> != NULL)
00341     {
00342       _dbus_verbose (<font class="stringliteral">"Adding watch on fd %d\n"</font>,
00343                      dbus_watch_get_fd (watch));
00344       
00345       <font class="keywordflow">if</font> (!(* watch_list-&gt;<a class="code" href="structDBusWatchList.html#m1">add_watch_function</a>) (watch,
00346                                                watch_list-&gt;<a class="code" href="structDBusWatchList.html#m4">watch_data</a>))
00347         {
00348           _dbus_list_remove_last (&amp;watch_list-&gt;<a class="code" href="structDBusWatchList.html#m0">watches</a>, watch);
00349           _dbus_watch_unref (watch);
00350           <font class="keywordflow">return</font> FALSE;
00351         }
00352     }
00353   
00354   <font class="keywordflow">return</font> TRUE;
00355 }
00356 
00364 <font class="keywordtype">void</font>
<a name="l00365"></a><a class="code" href="group__DBusWatchInternals.html#a9">00365</a> _dbus_watch_list_remove_watch  (<a class="code" href="structDBusWatchList.html">DBusWatchList</a> *watch_list,
00366                                 <a class="code" href="structDBusWatch.html">DBusWatch</a>     *watch)
00367 {
00368   <font class="keywordflow">if</font> (!_dbus_list_remove (&amp;watch_list-&gt;<a class="code" href="structDBusWatchList.html#m0">watches</a>, watch))
00369     _dbus_assert_not_reached (<font class="stringliteral">"Nonexistent watch was removed"</font>);
00370   
00371   <font class="keywordflow">if</font> (watch_list-&gt;<a class="code" href="structDBusWatchList.html#m2">remove_watch_function</a> != NULL)
00372     {
00373       _dbus_verbose (<font class="stringliteral">"Removing watch on fd %d\n"</font>,
00374                      dbus_watch_get_fd (watch));
00375       
00376       (* watch_list-&gt;<a class="code" href="structDBusWatchList.html#m2">remove_watch_function</a>) (watch,
00377                                              watch_list-&gt;<a class="code" href="structDBusWatchList.html#m4">watch_data</a>);
00378     }
00379   
00380   _dbus_watch_unref (watch);
00381 }
00382 
00391 <font class="keywordtype">void</font>
<a name="l00392"></a><a class="code" href="group__DBusWatchInternals.html#a10">00392</a> _dbus_watch_list_toggle_watch (<a class="code" href="structDBusWatchList.html">DBusWatchList</a>           *watch_list,
00393                                <a class="code" href="structDBusWatch.html">DBusWatch</a>               *watch,
00394                                dbus_bool_t              enabled)
00395 {
00396   enabled = !!enabled;
00397   
00398   <font class="keywordflow">if</font> (enabled == watch-&gt;<a class="code" href="structDBusWatch.html#m8">enabled</a>)
00399     <font class="keywordflow">return</font>;
00400 
00401   watch-&gt;<a class="code" href="structDBusWatch.html#m8">enabled</a> = enabled;
00402   
00403   <font class="keywordflow">if</font> (watch_list-&gt;<a class="code" href="structDBusWatchList.html#m3">watch_toggled_function</a> != NULL)
00404     {
00405       _dbus_verbose (<font class="stringliteral">"Toggling watch on fd %d to %d\n"</font>,
00406                      dbus_watch_get_fd (watch), watch-&gt;<a class="code" href="structDBusWatch.html#m8">enabled</a>);
00407       
00408       (* watch_list-&gt;<a class="code" href="structDBusWatchList.html#m3">watch_toggled_function</a>) (watch,
00409                                               watch_list-&gt;<a class="code" href="structDBusWatchList.html#m4">watch_data</a>);
00410     }
00411 }
00412 
00425 <font class="keywordtype">void</font>
<a name="l00426"></a><a class="code" href="group__DBusWatchInternals.html#a11">00426</a> _dbus_watch_set_handler (<a class="code" href="structDBusWatch.html">DBusWatch</a>        *watch,
00427                          DBusWatchHandler  handler,
00428                          <font class="keywordtype">void</font>             *data,
00429                          DBusFreeFunction  free_data_function)
00430 {
00431   <font class="keywordflow">if</font> (watch-&gt;<a class="code" href="structDBusWatch.html#m5">free_handler_data_function</a>)
00432     (* watch-&gt;<a class="code" href="structDBusWatch.html#m5">free_handler_data_function</a>) (watch-&gt;<a class="code" href="structDBusWatch.html#m4">handler_data</a>);
00433 
00434   watch-&gt;<a class="code" href="structDBusWatch.html#m3">handler</a> = handler;
00435   watch-&gt;<a class="code" href="structDBusWatch.html#m4">handler_data</a> = data;
00436   watch-&gt;<a class="code" href="structDBusWatch.html#m5">free_handler_data_function</a> = free_data_function;
00437 }
00438 
00467 <font class="keywordtype">int</font>
<a name="l00468"></a><a class="code" href="group__DBusWatch.html#a13">00468</a> dbus_watch_get_fd (<a class="code" href="structDBusWatch.html">DBusWatch</a> *watch)
00469 {
00470   <font class="keywordflow">return</font> watch-&gt;<a class="code" href="structDBusWatch.html#m1">fd</a>;
00471 }
00472 
00486 <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font>
<a name="l00487"></a><a class="code" href="group__DBusWatch.html#a14">00487</a> dbus_watch_get_flags (<a class="code" href="structDBusWatch.html">DBusWatch</a> *watch)
00488 {
00489   _dbus_assert ((watch-&gt;<a class="code" href="structDBusWatch.html#m2">flags</a> &amp; VALID_WATCH_FLAGS) == watch-&gt;<a class="code" href="structDBusWatch.html#m2">flags</a>);
00490 
00491   <font class="keywordflow">return</font> watch-&gt;<a class="code" href="structDBusWatch.html#m2">flags</a>;
00492 }
00493 
00501 <font class="keywordtype">void</font>*
<a name="l00502"></a><a class="code" href="group__DBusWatch.html#a15">00502</a> dbus_watch_get_data (<a class="code" href="structDBusWatch.html">DBusWatch</a> *watch)
00503 {
00504   <font class="keywordflow">return</font> watch-&gt;<a class="code" href="structDBusWatch.html#m6">data</a>;
00505 }
00506 
00518 <font class="keywordtype">void</font>
<a name="l00519"></a><a class="code" href="group__DBusWatch.html#a16">00519</a> dbus_watch_set_data (<a class="code" href="structDBusWatch.html">DBusWatch</a>        *watch,
00520                      <font class="keywordtype">void</font>             *data,
00521                      DBusFreeFunction  free_data_function)
00522 {
00523   _dbus_verbose (<font class="stringliteral">"Setting watch fd %d data to data = %p function = %p from data = %p function = %p\n"</font>,
00524                  dbus_watch_get_fd (watch),
00525                  data, free_data_function, watch-&gt;<a class="code" href="structDBusWatch.html#m6">data</a>, watch-&gt;<a class="code" href="structDBusWatch.html#m7">free_data_function</a>);
00526   
00527   <font class="keywordflow">if</font> (watch-&gt;<a class="code" href="structDBusWatch.html#m7">free_data_function</a> != NULL)
00528     (* watch-&gt;<a class="code" href="structDBusWatch.html#m7">free_data_function</a>) (watch-&gt;<a class="code" href="structDBusWatch.html#m6">data</a>);
00529   
00530   watch-&gt;<a class="code" href="structDBusWatch.html#m6">data</a> = data;
00531   watch-&gt;<a class="code" href="structDBusWatch.html#m7">free_data_function</a> = free_data_function;
00532 }
00533 
00541 dbus_bool_t
<a name="l00542"></a><a class="code" href="group__DBusWatch.html#a17">00542</a> dbus_watch_get_enabled (<a class="code" href="structDBusWatch.html">DBusWatch</a> *watch)
00543 {
00544   _dbus_assert (watch != NULL);
00545   <font class="keywordflow">return</font> watch-&gt;<a class="code" href="structDBusWatch.html#m8">enabled</a>;
00546 }
00547 
00548 
00571 dbus_bool_t
<a name="l00572"></a><a class="code" href="group__DBusWatch.html#a18">00572</a> dbus_watch_handle (<a class="code" href="structDBusWatch.html">DBusWatch</a>    *watch,
00573                    <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font>  flags)
00574 {
00575 <font class="preprocessor">#ifndef DBUS_DISABLE_CHECKS</font>
00576 <font class="preprocessor"></font>  <font class="keywordflow">if</font> (watch-&gt;<a class="code" href="structDBusWatch.html#m1">fd</a> &lt; 0 || watch-&gt;<a class="code" href="structDBusWatch.html#m2">flags</a> == 0)
00577     {
00578       _dbus_warn (<font class="stringliteral">"%s: Watch is invalid, it should have been removed\n"</font>,
00579                   _DBUS_FUNCTION_NAME);
00580       <font class="keywordflow">return</font> TRUE;
00581     }
00582 <font class="preprocessor">#endif</font>
00583 <font class="preprocessor"></font>    
00584   _dbus_return_val_if_fail (watch-&gt;<a class="code" href="structDBusWatch.html#m1">fd</a> &gt;= 0 <font class="comment">/* fails if watch was removed */</font>, TRUE);
00585   
00586   _dbus_watch_sanitize_condition (watch, &amp;flags);
00587 
00588   <font class="keywordflow">if</font> (flags == 0)
00589     {
00590       _dbus_verbose (<font class="stringliteral">"After sanitization, watch flags on fd %d were 0\n"</font>,
00591                      watch-&gt;<a class="code" href="structDBusWatch.html#m1">fd</a>);
00592       <font class="keywordflow">return</font> TRUE;
00593     }
00594   <font class="keywordflow">else</font>
00595     <font class="keywordflow">return</font> (* watch-&gt;<a class="code" href="structDBusWatch.html#m3">handler</a>) (watch, flags,
00596                                watch-&gt;<a class="code" href="structDBusWatch.html#m4">handler_data</a>);
00597 }
00598 
00599 
</pre></div><hr><address align="right"><small>Generated on Wed Jun 9 05:01:27 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>