Sophie

Sophie

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

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-gidl.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-gidl.c</h1><div class="fragment"><pre>00001 <font class="comment">/* -*- mode: C; c-file-style: "gnu" -*- */</font>
00002 <font class="comment">/* dbus-gidl.c data structure describing an interface, to be generated from IDL</font>
00003 <font class="comment"> *             or something</font>
00004 <font class="comment"> *</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-gidl.h"</font>
00026 
00027 <font class="preprocessor">#ifndef DOXYGEN_SHOULD_SKIP_THIS</font>
00028 <font class="preprocessor"></font>
00029 <font class="keyword">struct </font>BaseInfo
00030 {
00031   <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> refcount : 28;
00032   <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> type     : 4;
00033   <font class="keywordtype">char</font> *name;
00034 };
00035 
00036 <font class="keyword">struct </font>NodeInfo
00037 {
00038   BaseInfo base;
00039   GSList *interfaces;
00040   GSList *nodes;
00041 };
00042 
00043 <font class="keyword">struct </font>InterfaceInfo
00044 {
00045   BaseInfo base;
00046   <font class="comment">/* Since we have BaseInfo now these could be one list */</font>
00047   GSList *methods;
00048   GSList *signals;
00049 };
00050 
00051 <font class="keyword">struct </font>MethodInfo
00052 {
00053   BaseInfo base;
00054   GSList *args;
00055 };
00056 
00057 <font class="keyword">struct </font>SignalInfo
00058 {
00059   BaseInfo base;
00060   GSList *args;
00061 };
00062 
00063 <font class="keyword">struct </font>ArgInfo
00064 {
00065   BaseInfo base;
00066   <font class="keywordtype">int</font> type;
00067   ArgDirection direction;
00068 };
00069 
00070 BaseInfo *
00071 base_info_ref (BaseInfo *info)
00072 {
00073   g_return_val_if_fail (info != NULL, NULL);
00074   g_return_val_if_fail (info-&gt;refcount &gt; 0, NULL);
00075   
00076   info-&gt;refcount += 1;
00077 
00078   <font class="keywordflow">return</font> info;
00079 }
00080 
00081 <font class="keyword">static</font> <font class="keywordtype">void</font>
00082 base_info_free (<font class="keywordtype">void</font> *ptr)
00083 {
00084   BaseInfo *info;
00085 
00086   info = ptr;
00087   
00088   g_free (info-&gt;name);
00089   g_free (info);
00090 }
00091 
00092 <font class="keywordtype">void</font>
00093 base_info_unref (BaseInfo *info)
00094 {
00095   g_return_if_fail (info != NULL);
00096   g_return_if_fail (info-&gt;refcount &gt; 0);
00097   
00098   <font class="comment">/* This is sort of bizarre, BaseInfo was tacked on later */</font>
00099 
00100   <font class="keywordflow">switch</font> (info-&gt;type)
00101     {
00102     <font class="keywordflow">case</font> INFO_TYPE_NODE:
00103       node_info_unref ((NodeInfo*) info);
00104       <font class="keywordflow">break</font>;
00105     <font class="keywordflow">case</font> INFO_TYPE_INTERFACE:
00106       interface_info_unref ((InterfaceInfo*) info);
00107       <font class="keywordflow">break</font>;
00108     <font class="keywordflow">case</font> INFO_TYPE_SIGNAL:
00109       signal_info_unref ((SignalInfo*) info);
00110       <font class="keywordflow">break</font>;
00111     <font class="keywordflow">case</font> INFO_TYPE_METHOD:
00112       method_info_unref ((MethodInfo*) info);
00113       <font class="keywordflow">break</font>;
00114     <font class="keywordflow">case</font> INFO_TYPE_ARG:
00115       arg_info_unref ((ArgInfo*) info);
00116       <font class="keywordflow">break</font>;
00117     }
00118 }
00119 
00120 InfoType
00121 base_info_get_type (BaseInfo      *info)
00122 {
00123   <font class="keywordflow">return</font> info-&gt;type;
00124 }
00125 
00126 <font class="keyword">const</font> <font class="keywordtype">char</font>*
00127 base_info_get_name (BaseInfo *info)
00128 {
00129   <font class="keywordflow">return</font> info-&gt;name;
00130 }
00131 
00132 <font class="keywordtype">void</font>
00133 base_info_set_name (BaseInfo      *info,
00134                     <font class="keyword">const</font> <font class="keywordtype">char</font>    *name)
00135 {
00136   <font class="keywordtype">char</font> *old;
00137 
00138   old = info-&gt;name;
00139   info-&gt;name = g_strdup (name);
00140   g_free (old);
00141 }
00142 
00143 GType
00144 base_info_get_gtype (<font class="keywordtype">void</font>)
00145 {
00146   <font class="keyword">static</font> GType our_type = 0;
00147   
00148   <font class="keywordflow">if</font> (our_type == 0)
00149     our_type = g_boxed_type_register_static (<font class="stringliteral">"BaseInfo"</font>,
00150                                              (GBoxedCopyFunc) base_info_ref,
00151                                              (GBoxedFreeFunc) base_info_unref);
00152 
00153   <font class="keywordflow">return</font> our_type;
00154 }
00155 
00156 <font class="keyword">static</font> <font class="keywordtype">void</font>
00157 free_interface_list (GSList **interfaces_p)
00158 {
00159   GSList *tmp;
00160   tmp = *interfaces_p;
00161   <font class="keywordflow">while</font> (tmp != NULL)
00162     {
00163       interface_info_unref (tmp-&gt;data);
00164       tmp = tmp-&gt;next;
00165     }
00166   g_slist_free (*interfaces_p);
00167   *interfaces_p = NULL;
00168 }
00169 
00170 <font class="keyword">static</font> <font class="keywordtype">void</font>
00171 free_node_list (GSList **nodes_p)
00172 {
00173   GSList *tmp;
00174   tmp = *nodes_p;
00175   <font class="keywordflow">while</font> (tmp != NULL)
00176     {
00177       node_info_unref (tmp-&gt;data);
00178       tmp = tmp-&gt;next;
00179     }
00180   g_slist_free (*nodes_p);
00181   *nodes_p = NULL;
00182 }
00183 
00184 <font class="keyword">static</font> <font class="keywordtype">void</font>
00185 free_method_list (GSList **methods_p)
00186 {
00187   GSList *tmp;
00188   tmp = *methods_p;
00189   <font class="keywordflow">while</font> (tmp != NULL)
00190     {
00191       method_info_unref (tmp-&gt;data);
00192       tmp = tmp-&gt;next;
00193     }
00194   g_slist_free (*methods_p);
00195   *methods_p = NULL;
00196 }
00197 
00198 <font class="keyword">static</font> <font class="keywordtype">void</font>
00199 free_signal_list (GSList **signals_p)
00200 {
00201   GSList *tmp;
00202   tmp = *signals_p;
00203   <font class="keywordflow">while</font> (tmp != NULL)
00204     {
00205       signal_info_unref (tmp-&gt;data);
00206       tmp = tmp-&gt;next;
00207     }
00208   g_slist_free (*signals_p);
00209   *signals_p = NULL;
00210 }
00211 
00212 NodeInfo*
00213 node_info_new (<font class="keyword">const</font> <font class="keywordtype">char</font> *name)
00214 {
00215   NodeInfo *info;
00216 
00217   <font class="comment">/* name can be NULL */</font>
00218   
00219   info = g_new0 (NodeInfo, 1);
00220   info-&gt;base.refcount = 1;
00221   info-&gt;base.name = g_strdup (name);
00222   info-&gt;base.type = INFO_TYPE_NODE;
00223   
00224   <font class="keywordflow">return</font> info;
00225 }
00226 
00227 NodeInfo *
00228 node_info_ref (NodeInfo *info)
00229 {
00230   info-&gt;base.refcount += 1;
00231 
00232   <font class="keywordflow">return</font> info;
00233 }
00234 
00235 <font class="keywordtype">void</font>
00236 node_info_unref (NodeInfo *info)
00237 {
00238   info-&gt;base.refcount -= 1;
00239   <font class="keywordflow">if</font> (info-&gt;base.refcount == 0)
00240     {
00241       free_interface_list (&amp;info-&gt;interfaces);
00242       free_node_list (&amp;info-&gt;nodes);
00243       base_info_free (info);
00244     }
00245 }
00246 
00247 <font class="keyword">const</font> <font class="keywordtype">char</font>*
00248 node_info_get_name (NodeInfo *info)
00249 {
00250   <font class="keywordflow">return</font> info-&gt;base.name;
00251 }
00252 
00253 GSList*
00254 node_info_get_interfaces (NodeInfo *info)
00255 {
00256   <font class="keywordflow">return</font> info-&gt;interfaces;
00257 }
00258 
00259 <font class="keywordtype">void</font>
00260 node_info_add_interface (NodeInfo *info,
00261                          InterfaceInfo    *interface)
00262 {
00263   interface_info_ref (interface);
00264   info-&gt;interfaces = g_slist_append (info-&gt;interfaces, interface);
00265 }
00266 
00267 GSList*
00268 node_info_get_nodes (NodeInfo *info)
00269 {
00270   <font class="keywordflow">return</font> info-&gt;nodes;
00271 }
00272 
00273 <font class="keywordtype">void</font>
00274 node_info_add_node (NodeInfo *info,
00275                     NodeInfo *node)
00276 {
00277   node_info_ref (node);
00278   info-&gt;nodes = g_slist_append (info-&gt;nodes, node);
00279 }
00280 
00281 InterfaceInfo*
00282 interface_info_new (<font class="keyword">const</font> <font class="keywordtype">char</font> *name)
00283 {
00284   InterfaceInfo *info;
00285 
00286   info = g_new0 (InterfaceInfo, 1);
00287   info-&gt;base.refcount = 1;
00288   info-&gt;base.name = g_strdup (name);
00289   info-&gt;base.type = INFO_TYPE_INTERFACE;
00290   
00291   <font class="keywordflow">return</font> info;
00292 }
00293 
00294 InterfaceInfo *
00295 interface_info_ref (InterfaceInfo *info)
00296 {
00297   info-&gt;base.refcount += 1;
00298 
00299   <font class="keywordflow">return</font> info;
00300 }
00301 
00302 <font class="keywordtype">void</font>
00303 interface_info_unref (InterfaceInfo *info)
00304 {
00305   info-&gt;base.refcount -= 1;
00306   <font class="keywordflow">if</font> (info-&gt;base.refcount == 0)
00307     {
00308       free_method_list (&amp;info-&gt;methods);
00309       free_signal_list (&amp;info-&gt;signals);
00310       base_info_free (info);
00311     }
00312 }
00313 
00314 <font class="keyword">const</font> <font class="keywordtype">char</font>*
00315 interface_info_get_name (InterfaceInfo *info)
00316 {
00317   <font class="keywordflow">return</font> info-&gt;base.name;
00318 }
00319 
00320 GSList*
00321 interface_info_get_methods (InterfaceInfo *info)
00322 {
00323   <font class="keywordflow">return</font> info-&gt;methods;
00324 }
00325 
00326 GSList*
00327 interface_info_get_signals (InterfaceInfo *info)
00328 {
00329   <font class="keywordflow">return</font> info-&gt;signals;
00330 }
00331 
00332 <font class="keywordtype">void</font>
00333 interface_info_add_method (InterfaceInfo *info,
00334                            MethodInfo    *method)
00335 {
00336   method_info_ref (method);
00337   info-&gt;methods = g_slist_append (info-&gt;methods, method);
00338 }
00339 
00340 <font class="keywordtype">void</font>
00341 interface_info_add_signal (InterfaceInfo *info,
00342                            SignalInfo    *signal)
00343 {
00344   signal_info_ref (signal);
00345   info-&gt;signals = g_slist_append (info-&gt;signals, signal);
00346 }
00347 
00348 <font class="keyword">static</font> <font class="keywordtype">void</font>
00349 free_arg_list (GSList **args_p)
00350 {
00351   GSList *tmp;
00352   tmp = *args_p;
00353   <font class="keywordflow">while</font> (tmp != NULL)
00354     {
00355       arg_info_unref (tmp-&gt;data);
00356       tmp = tmp-&gt;next;
00357     }
00358   g_slist_free (*args_p);
00359   *args_p = NULL;
00360 }
00361 
00362 MethodInfo*
00363 method_info_new (<font class="keyword">const</font> <font class="keywordtype">char</font> *name)
00364 {
00365   MethodInfo *info;
00366 
00367   info = g_new0 (MethodInfo, 1);
00368   info-&gt;base.refcount = 1;
00369   info-&gt;base.name = g_strdup (name);
00370   info-&gt;base.type = INFO_TYPE_METHOD;
00371   
00372   <font class="keywordflow">return</font> info;
00373 }
00374 
00375 MethodInfo *
00376 method_info_ref (MethodInfo *info)
00377 {
00378   info-&gt;base.refcount += 1;
00379 
00380   <font class="keywordflow">return</font> info;
00381 }
00382 
00383 <font class="keywordtype">void</font>
00384 method_info_unref (MethodInfo *info)
00385 {
00386   info-&gt;base.refcount -= 1;
00387   <font class="keywordflow">if</font> (info-&gt;base.refcount == 0)
00388     {
00389       free_arg_list (&amp;info-&gt;args);
00390       base_info_free (info);
00391     }
00392 }
00393 
00394 <font class="keyword">const</font> <font class="keywordtype">char</font>*
00395 method_info_get_name (MethodInfo *info)
00396 {
00397   <font class="keywordflow">return</font> info-&gt;base.name;
00398 }
00399 
00400 GSList*
00401 method_info_get_args (MethodInfo *info)
00402 {
00403   <font class="keywordflow">return</font> info-&gt;args;
00404 }
00405 
00406 <font class="keyword">static</font> <font class="keywordtype">int</font>
00407 args_sort_by_direction (<font class="keyword">const</font> <font class="keywordtype">void</font> *a,
00408                         <font class="keyword">const</font> <font class="keywordtype">void</font> *b)
00409 {
00410   <font class="keyword">const</font> ArgInfo *arg_a = a;
00411   <font class="keyword">const</font> ArgInfo *arg_b = b;
00412 
00413   <font class="keywordflow">if</font> (arg_a-&gt;direction == arg_b-&gt;direction)
00414     <font class="keywordflow">return</font> 0;
00415   <font class="keywordflow">else</font> <font class="keywordflow">if</font> (arg_a-&gt;direction == ARG_IN)
00416     <font class="keywordflow">return</font> -1; <font class="comment">/* in is less than out */</font>
00417   <font class="keywordflow">else</font>
00418     <font class="keywordflow">return</font> 1;
00419 }                  
00420 
00421 <font class="keywordtype">void</font>
00422 method_info_add_arg (MethodInfo    *info,
00423                      ArgInfo       *arg)
00424 {
00425   arg_info_ref (arg);
00426   info-&gt;args = g_slist_append (info-&gt;args, arg);
00427 
00428   <font class="comment">/* Keep "in" args sorted before "out" and otherwise maintain</font>
00429 <font class="comment">   * stable order (g_slist_sort is stable, at least in sufficiently</font>
00430 <font class="comment">   * new glib)</font>
00431 <font class="comment">   */</font>
00432   info-&gt;args = g_slist_sort (info-&gt;args, args_sort_by_direction);
00433 }
00434 
00435 SignalInfo*
00436 signal_info_new (<font class="keyword">const</font> <font class="keywordtype">char</font> *name)
00437 {
00438   SignalInfo *info;
00439 
00440   info = g_new0 (SignalInfo, 1);
00441   info-&gt;base.refcount = 1;
00442   info-&gt;base.name = g_strdup (name);
00443   info-&gt;base.type = INFO_TYPE_SIGNAL;
00444   
00445   <font class="keywordflow">return</font> info;
00446 }
00447 
00448 SignalInfo *
00449 signal_info_ref (SignalInfo *info)
00450 {
00451   info-&gt;base.refcount += 1;
00452 
00453   <font class="keywordflow">return</font> info;
00454 }
00455 
00456 <font class="keywordtype">void</font>
00457 signal_info_unref (SignalInfo *info)
00458 {
00459   info-&gt;base.refcount -= 1;
00460   <font class="keywordflow">if</font> (info-&gt;base.refcount == 0)
00461     {
00462       free_arg_list (&amp;info-&gt;args);
00463       base_info_free (info);
00464     }
00465 }
00466 
00467 <font class="keyword">const</font> <font class="keywordtype">char</font>*
00468 signal_info_get_name (SignalInfo *info)
00469 {
00470   <font class="keywordflow">return</font> info-&gt;base.name;
00471 }
00472 
00473 GSList*
00474 signal_info_get_args (SignalInfo *info)
00475 {
00476   <font class="keywordflow">return</font> info-&gt;args;
00477 }
00478 
00479 <font class="keywordtype">void</font>
00480 signal_info_add_arg (SignalInfo    *info,
00481                      ArgInfo       *arg)
00482 {
00483   g_assert (arg-&gt;direction == ARG_OUT);
00484   
00485   arg_info_ref (arg);
00486   info-&gt;args = g_slist_append (info-&gt;args, arg);
00487 
00488   <font class="comment">/* signal args don't need sorting since only "out" is allowed */</font>
00489 }
00490 
00491 ArgInfo*
00492 arg_info_new (<font class="keyword">const</font> <font class="keywordtype">char</font>  *name,
00493               ArgDirection direction,
00494               <font class="keywordtype">int</font>          type)
00495 {
00496   ArgInfo *info;
00497 
00498   info = g_new0 (ArgInfo, 1);
00499   info-&gt;base.refcount = 1;
00500   info-&gt;base.type = INFO_TYPE_ARG;
00501   
00502   <font class="comment">/* name can be NULL */</font>
00503   info-&gt;base.name = g_strdup (name);
00504   info-&gt;direction = direction;
00505   info-&gt;type = type;
00506 
00507   <font class="keywordflow">return</font> info;
00508 }
00509 
00510 ArgInfo *
00511 arg_info_ref (ArgInfo *info)
00512 {
00513   info-&gt;base.refcount += 1;
00514 
00515   <font class="keywordflow">return</font> info;
00516 }
00517 
00518 <font class="keywordtype">void</font>
00519 arg_info_unref (ArgInfo *info)
00520 {
00521   info-&gt;base.refcount -= 1;
00522   <font class="keywordflow">if</font> (info-&gt;base.refcount == 0)
00523     {
00524       base_info_free (info);
00525     }
00526 }
00527 <font class="keyword">const</font> <font class="keywordtype">char</font>*
00528 arg_info_get_name (ArgInfo *info)
00529 {
00530   <font class="keywordflow">return</font> info-&gt;base.name;
00531 }
00532 
00533 <font class="keywordtype">int</font>
00534 arg_info_get_type (ArgInfo *info)
00535 {
00536   <font class="keywordflow">return</font> info-&gt;type;
00537 }
00538 
00539 ArgDirection
00540 arg_info_get_direction (ArgInfo *info)
00541 {
00542   <font class="keywordflow">return</font> info-&gt;direction;
00543 }
00544 
00545 <font class="preprocessor">#ifdef DBUS_BUILD_TESTS</font>
00546 <font class="preprocessor"></font>
00552 dbus_bool_t
00553 _dbus_gidl_test (<font class="keywordtype">void</font>)
00554 {
00555 
00556   <font class="keywordflow">return</font> TRUE;
00557 }
00558 
00559 <font class="preprocessor">#endif </font><font class="comment">/* DBUS_BUILD_TESTS */</font>
00560 
00561 <font class="preprocessor">#endif </font><font class="comment">/* DOXYGEN_SHOULD_SKIP_THIS */</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>