Sophie

Sophie

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

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-glib-tool.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-glib-tool.c</h1><div class="fragment"><pre>00001 <font class="comment">/* -*- mode: C; c-file-style: "gnu" -*- */</font>
00002 <font class="comment">/* dbus-glib-tool.c Tool used by apps using glib bindings</font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * Copyright (C) 2003, 2004 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 &lt;config.h&gt;</font>
00025 <font class="preprocessor">#include "dbus-gidl.h"</font>
00026 <font class="preprocessor">#include "dbus-gparser.h"</font>
00027 <font class="preprocessor">#include "dbus-gutils.h"</font>
00028 <font class="preprocessor">#include &lt;locale.h&gt;</font>
00029 <font class="preprocessor">#include &lt;libintl.h&gt;</font>
00030 <font class="preprocessor">#define _(x) dgettext (GETTEXT_PACKAGE, x)</font>
00031 <font class="preprocessor"></font><font class="preprocessor">#define N_(x) x</font>
00032 <font class="preprocessor"></font><font class="preprocessor">#include &lt;stdio.h&gt;</font>
00033 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00034 <font class="preprocessor">#include &lt;string.h&gt;</font>
00035 
00036 <font class="preprocessor">#ifdef DBUS_BUILD_TESTS</font>
00037 <font class="preprocessor"></font><font class="keyword">static</font> <font class="keywordtype">void</font> run_all_tests (<font class="keyword">const</font> <font class="keywordtype">char</font> *test_data_dir);
00038 <font class="preprocessor">#endif</font>
00039 <font class="preprocessor"></font>
00040 <font class="keyword">static</font> <font class="keywordtype">void</font>
00041 indent (<font class="keywordtype">int</font> depth)
00042 {
00043   depth *= 2; <font class="comment">/* 2-space indent */</font>
00044   
00045   <font class="keywordflow">while</font> (depth &gt; 0)
00046     {
00047       putc (<font class="charliteral">' '</font>, stdout);
00048       --depth;
00049     }
00050 }
00051 
00052 <font class="keyword">static</font> <font class="keywordtype">void</font> pretty_print (BaseInfo *base,
00053                           <font class="keywordtype">int</font>       depth);
00054 
00055 <font class="keyword">static</font> <font class="keywordtype">void</font>
00056 pretty_print_list (GSList *list,
00057                    <font class="keywordtype">int</font>     depth)
00058 {
00059   GSList *tmp;
00060 
00061   tmp = list;
00062   <font class="keywordflow">while</font> (tmp != NULL)
00063     {
00064       pretty_print (tmp-&gt;data, depth);
00065       tmp = tmp-&gt;next;
00066     }
00067 }
00068 
00069 <font class="keyword">static</font> <font class="keywordtype">void</font>
00070 pretty_print (BaseInfo *base,
00071               <font class="keywordtype">int</font>       depth)
00072 {
00073   InfoType t;
00074   <font class="keyword">const</font> <font class="keywordtype">char</font> *name;
00075 
00076   t = base_info_get_type (base);
00077   name = base_info_get_name (base);
00078 
00079   indent (depth);
00080   
00081   <font class="keywordflow">switch</font> (t)
00082     {
00083     <font class="keywordflow">case</font> INFO_TYPE_NODE:
00084       {
00085         NodeInfo *n = (NodeInfo*) base;
00086         
00087         <font class="keywordflow">if</font> (name == NULL)
00088           printf (_(<font class="stringliteral">"&lt;anonymous node&gt; {\n"</font>));
00089         <font class="keywordflow">else</font>
00090           printf (_(<font class="stringliteral">"node \"%s\" {\n"</font>), name);
00091 
00092         pretty_print_list (node_info_get_interfaces (n), depth + 1);
00093         pretty_print_list (node_info_get_nodes (n), depth + 1);
00094 
00095         indent (depth);
00096         printf (<font class="stringliteral">"}\n"</font>);
00097       }
00098       <font class="keywordflow">break</font>;
00099     <font class="keywordflow">case</font> INFO_TYPE_INTERFACE:
00100       {
00101         InterfaceInfo *i = (InterfaceInfo*) base;
00102 
00103         g_assert (name != NULL);
00104 
00105         printf (_(<font class="stringliteral">"interface \"%s\" {\n"</font>), name);
00106 
00107         pretty_print_list (interface_info_get_methods (i), depth + 1);
00108         pretty_print_list (interface_info_get_signals (i), depth + 1);
00109 
00110         indent (depth);
00111         printf (<font class="stringliteral">"}\n"</font>);
00112       }
00113       <font class="keywordflow">break</font>;
00114     <font class="keywordflow">case</font> INFO_TYPE_METHOD:
00115       {
00116         MethodInfo *m = (MethodInfo*) base;
00117 
00118         g_assert (name != NULL);
00119 
00120         printf (_(<font class="stringliteral">"method \"%s\" (\n"</font>), name);
00121 
00122         pretty_print_list (method_info_get_args (m), depth + 1);
00123 
00124         indent (depth);
00125         printf (<font class="stringliteral">")\n"</font>);
00126       }
00127       <font class="keywordflow">break</font>;
00128     <font class="keywordflow">case</font> INFO_TYPE_SIGNAL:
00129       {
00130         SignalInfo *s = (SignalInfo*) base;
00131 
00132         g_assert (name != NULL);
00133 
00134         printf (_(<font class="stringliteral">"signal \"%s\" (\n"</font>), name);
00135 
00136         pretty_print_list (signal_info_get_args (s), depth + 1);
00137 
00138         indent (depth);
00139         printf (<font class="stringliteral">")\n"</font>);
00140       }
00141       <font class="keywordflow">break</font>;
00142     <font class="keywordflow">case</font> INFO_TYPE_ARG:
00143       {
00144         ArgInfo *a = (ArgInfo*) base;
00145         <font class="keywordtype">int</font> at = arg_info_get_type (a);
00146         ArgDirection d = arg_info_get_direction (a);
00147 
00148         printf (<font class="stringliteral">"%s %s"</font>,
00149                 d == ARG_IN ? <font class="stringliteral">"in"</font> : <font class="stringliteral">"out"</font>,
00150                 _dbus_gutils_type_to_string (at));
00151         <font class="keywordflow">if</font> (name)
00152           printf (<font class="stringliteral">" %s\n"</font>, name);
00153         <font class="keywordflow">else</font>
00154           printf (<font class="stringliteral">"\n"</font>);
00155       }
00156       <font class="keywordflow">break</font>;
00157     }
00158 }
00159 
00160 <font class="keyword">static</font> <font class="keywordtype">void</font>
00161 usage (<font class="keywordtype">int</font> ecode)
00162 {
00163   fprintf (stderr, <font class="stringliteral">"dbus-glib-tool [--version] [--help]\n"</font>);
00164   exit (ecode);
00165 }
00166 
00167 <font class="keyword">static</font> <font class="keywordtype">void</font>
00168 version (<font class="keywordtype">void</font>)
00169 {
00170   printf (<font class="stringliteral">"D-BUS GLib Tool %s\n"</font>
00171           <font class="stringliteral">"Copyright (C) 2003, 2004 Red Hat, Inc.\n"</font>
00172           <font class="stringliteral">"This is free software; see the source for copying conditions.\n"</font>
00173           <font class="stringliteral">"There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"</font>,
00174           VERSION);
00175   exit (0);
00176 }
00177 
00178 <font class="keywordtype">int</font>
00179 main (<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00180 {
00181   <font class="keyword">const</font> <font class="keywordtype">char</font> *prev_arg;
00182   <font class="keywordtype">int</font> i;
00183   GSList *files;
00184   gboolean end_of_args;
00185   GSList *tmp;
00186   gboolean just_pretty_print;
00187 
00188   setlocale (LC_ALL, <font class="stringliteral">""</font>);
00189   bindtextdomain (GETTEXT_PACKAGE, DBUS_LOCALEDIR);
00190   bind_textdomain_codeset (GETTEXT_PACKAGE, <font class="stringliteral">"UTF-8"</font>);
00191   textdomain (GETTEXT_PACKAGE); 
00192 
00193   just_pretty_print = FALSE;
00194   end_of_args = FALSE;
00195   files = NULL;
00196   prev_arg = NULL;
00197   i = 1;
00198   <font class="keywordflow">while</font> (i &lt; argc)
00199     {
00200       <font class="keyword">const</font> <font class="keywordtype">char</font> *arg = argv[i];
00201 
00202       <font class="keywordflow">if</font> (!end_of_args)
00203         {
00204           <font class="keywordflow">if</font> (strcmp (arg, <font class="stringliteral">"--help"</font>) == 0 ||
00205               strcmp (arg, <font class="stringliteral">"-h"</font>) == 0 ||
00206               strcmp (arg, <font class="stringliteral">"-?"</font>) == 0)
00207             usage (0);
00208           <font class="keywordflow">else</font> <font class="keywordflow">if</font> (strcmp (arg, <font class="stringliteral">"--version"</font>) == 0)
00209             version ();
00210 <font class="preprocessor">#ifdef DBUS_BUILD_TESTS</font>
00211 <font class="preprocessor"></font>          <font class="keywordflow">else</font> <font class="keywordflow">if</font> (strcmp (arg, <font class="stringliteral">"--self-test"</font>) == 0)
00212             run_all_tests (NULL);
00213 <font class="preprocessor">#endif </font><font class="comment">/* DBUS_BUILD_TESTS */</font>
00214           <font class="keywordflow">else</font> <font class="keywordflow">if</font> (strcmp (arg, <font class="stringliteral">"--pretty-print"</font>) == 0)
00215             just_pretty_print = TRUE;
00216           <font class="keywordflow">else</font> <font class="keywordflow">if</font> (arg[0] == <font class="charliteral">'-'</font> &amp;&amp;
00217                    arg[1] == <font class="charliteral">'-'</font> &amp;&amp;
00218                    arg[2] == <font class="charliteral">'\0'</font>)
00219             end_of_args = TRUE;
00220           <font class="keywordflow">else</font> <font class="keywordflow">if</font> (arg[0] == <font class="charliteral">'-'</font>)
00221             {
00222               usage (1);
00223             }
00224           <font class="keywordflow">else</font>
00225             {
00226               files = g_slist_prepend (files, (<font class="keywordtype">char</font>*) arg);
00227             }
00228         }
00229       <font class="keywordflow">else</font>
00230         files = g_slist_prepend (files, (<font class="keywordtype">char</font>*) arg);
00231       
00232       prev_arg = arg;
00233       
00234       ++i;
00235     }
00236 
00237   files = g_slist_reverse (files);
00238 
00239   tmp = files;
00240   <font class="keywordflow">while</font> (tmp != NULL)
00241     {
00242       NodeInfo *node;
00243       GError *error;
00244       <font class="keyword">const</font> <font class="keywordtype">char</font> *filename;
00245 
00246       filename = tmp-&gt;data;
00247 
00248       error = NULL;
00249       node = description_load_from_file (filename,
00250                                          &amp;error);
00251       <font class="keywordflow">if</font> (node == NULL)
00252         {
00253           g_assert (error != NULL);
00254           fprintf (stderr, _(<font class="stringliteral">"Unable to load \"%s\": %s\n"</font>),
00255                    filename, error-&gt;message);
00256           g_error_free (error);
00257           exit (1);
00258         }
00259       <font class="keywordflow">else</font> <font class="keywordflow">if</font> (just_pretty_print)
00260         {
00261           pretty_print ((BaseInfo*) node, 0);
00262         }
00263       <font class="keywordflow">else</font>
00264         {
00265           <font class="comment">/* FIXME process the file to generate metadata variable</font>
00266 <font class="comment">           * definition rather than just printing it.</font>
00267 <font class="comment">           * i.e. we want to create DBusGObjectInfo.</font>
00268 <font class="comment">           * This probably requires extending the introspection XML format to</font>
00269 <font class="comment">           * allow a "native function name":</font>
00270 <font class="comment">           *  &lt;method name="Frobate" native="my_object_frobate"&gt;</font>
00271 <font class="comment">           */</font>
00272           pretty_print ((BaseInfo*) node, 0);
00273         }
00274 
00275       <font class="keywordflow">if</font> (node)
00276         node_info_unref (node);
00277       
00278       tmp = tmp-&gt;next;
00279     }
00280   
00281   <font class="keywordflow">return</font> 0;
00282 }
00283 
00284 
00285 <font class="preprocessor">#ifdef DBUS_BUILD_TESTS</font>
00286 <font class="preprocessor"></font><font class="keyword">static</font> <font class="keywordtype">void</font>
00287 test_die (<font class="keyword">const</font> <font class="keywordtype">char</font> *failure)
00288 {
00289   fprintf (stderr, <font class="stringliteral">"Unit test failed: %s\n"</font>, failure);
00290   exit (1);
00291 }
00292 
00298 <font class="keyword">static</font> dbus_bool_t
00299 _dbus_gtool_test (<font class="keyword">const</font> <font class="keywordtype">char</font> *test_data_dir)
00300 {
00301 
00302   <font class="keywordflow">return</font> TRUE;
00303 }
00304 
00305 <font class="keyword">static</font> <font class="keywordtype">void</font>
00306 run_all_tests (<font class="keyword">const</font> <font class="keywordtype">char</font> *test_data_dir)
00307 {
00308   <font class="keywordflow">if</font> (test_data_dir == NULL)
00309     test_data_dir = g_getenv (<font class="stringliteral">"DBUS_TEST_DATA"</font>);
00310 
00311   <font class="keywordflow">if</font> (test_data_dir != NULL)
00312     printf (<font class="stringliteral">"Test data in %s\n"</font>, test_data_dir);
00313   <font class="keywordflow">else</font>
00314     printf (<font class="stringliteral">"No test data!\n"</font>);
00315 
00316   printf (<font class="stringliteral">"%s: running gtool tests\n"</font>, <font class="stringliteral">"dbus-glib-tool"</font>);
00317   <font class="keywordflow">if</font> (!_dbus_gtool_test (test_data_dir))
00318     test_die (<font class="stringliteral">"gtool"</font>);
00319 
00320   printf (<font class="stringliteral">"%s: completed successfully\n"</font>, <font class="stringliteral">"dbus-glib-tool"</font>);
00321 }
00322 
00323 <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>