Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

dbus-gidl.c

00001 /* -*- mode: C; c-file-style: "gnu" -*- */
00002 /* dbus-gidl.c data structure describing an interface, to be generated from IDL
00003  *             or something
00004  *
00005  * Copyright (C) 2003  Red Hat, Inc.
00006  *
00007  * Licensed under the Academic Free License version 1.2
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  */
00024 
00025 #include "dbus-gidl.h"
00026 
00027 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00028 
00029 struct BaseInfo
00030 {
00031   unsigned int refcount : 28;
00032   unsigned int type     : 4;
00033   char *name;
00034 };
00035 
00036 struct NodeInfo
00037 {
00038   BaseInfo base;
00039   GSList *interfaces;
00040   GSList *nodes;
00041 };
00042 
00043 struct InterfaceInfo
00044 {
00045   BaseInfo base;
00046   /* Since we have BaseInfo now these could be one list */
00047   GSList *methods;
00048   GSList *signals;
00049 };
00050 
00051 struct MethodInfo
00052 {
00053   BaseInfo base;
00054   GSList *args;
00055 };
00056 
00057 struct SignalInfo
00058 {
00059   BaseInfo base;
00060   GSList *args;
00061 };
00062 
00063 struct ArgInfo
00064 {
00065   BaseInfo base;
00066   int type;
00067   ArgDirection direction;
00068 };
00069 
00070 void
00071 base_info_ref (BaseInfo *info)
00072 {
00073   g_return_if_fail (info != NULL);
00074   g_return_if_fail (info->refcount > 0);
00075   
00076   info->refcount += 1;
00077 }
00078 
00079 static void
00080 base_info_free (void *ptr)
00081 {
00082   BaseInfo *info;
00083 
00084   info = ptr;
00085   
00086   g_free (info->name);
00087   g_free (info);
00088 }
00089 
00090 void
00091 base_info_unref (BaseInfo *info)
00092 {
00093   g_return_if_fail (info != NULL);
00094   g_return_if_fail (info->refcount > 0);
00095   
00096   /* This is sort of bizarre, BaseInfo was tacked on later */
00097 
00098   switch (info->type)
00099     {
00100     case INFO_TYPE_NODE:
00101       node_info_unref ((NodeInfo*) info);
00102       break;
00103     case INFO_TYPE_INTERFACE:
00104       interface_info_unref ((InterfaceInfo*) info);
00105       break;
00106     case INFO_TYPE_SIGNAL:
00107       signal_info_unref ((SignalInfo*) info);
00108       break;
00109     case INFO_TYPE_METHOD:
00110       method_info_unref ((MethodInfo*) info);
00111       break;
00112     case INFO_TYPE_ARG:
00113       arg_info_unref ((ArgInfo*) info);
00114       break;
00115     }
00116 }
00117 
00118 InfoType
00119 base_info_get_type (BaseInfo      *info)
00120 {
00121   return info->type;
00122 }
00123 
00124 const char*
00125 base_info_get_name (BaseInfo *info)
00126 {
00127   return info->name;
00128 }
00129 
00130 void
00131 base_info_set_name (BaseInfo      *info,
00132                     const char    *name)
00133 {
00134   char *old;
00135 
00136   old = info->name;
00137   info->name = g_strdup (name);
00138   g_free (old);
00139 }
00140 
00141 GType
00142 base_info_get_gtype (void)
00143 {
00144   static GType our_type = 0;
00145   
00146   if (our_type == 0)
00147     our_type = g_boxed_type_register_static ("BaseInfo",
00148                                              (GBoxedCopyFunc) base_info_ref,
00149                                              (GBoxedFreeFunc) base_info_unref);
00150 
00151   return our_type;
00152 }
00153 
00154 static void
00155 free_interface_list (GSList **interfaces_p)
00156 {
00157   GSList *tmp;
00158   tmp = *interfaces_p;
00159   while (tmp != NULL)
00160     {
00161       interface_info_unref (tmp->data);
00162       tmp = tmp->next;
00163     }
00164   g_slist_free (*interfaces_p);
00165   *interfaces_p = NULL;
00166 }
00167 
00168 static void
00169 free_node_list (GSList **nodes_p)
00170 {
00171   GSList *tmp;
00172   tmp = *nodes_p;
00173   while (tmp != NULL)
00174     {
00175       node_info_unref (tmp->data);
00176       tmp = tmp->next;
00177     }
00178   g_slist_free (*nodes_p);
00179   *nodes_p = NULL;
00180 }
00181 
00182 static void
00183 free_method_list (GSList **methods_p)
00184 {
00185   GSList *tmp;
00186   tmp = *methods_p;
00187   while (tmp != NULL)
00188     {
00189       method_info_unref (tmp->data);
00190       tmp = tmp->next;
00191     }
00192   g_slist_free (*methods_p);
00193   *methods_p = NULL;
00194 }
00195 
00196 static void
00197 free_signal_list (GSList **signals_p)
00198 {
00199   GSList *tmp;
00200   tmp = *signals_p;
00201   while (tmp != NULL)
00202     {
00203       signal_info_unref (tmp->data);
00204       tmp = tmp->next;
00205     }
00206   g_slist_free (*signals_p);
00207   *signals_p = NULL;
00208 }
00209 
00210 NodeInfo*
00211 node_info_new (const char *name)
00212 {
00213   NodeInfo *info;
00214 
00215   /* name can be NULL */
00216   
00217   info = g_new0 (NodeInfo, 1);
00218   info->base.refcount = 1;
00219   info->base.name = g_strdup (name);
00220   info->base.type = INFO_TYPE_NODE;
00221   
00222   return info;
00223 }
00224 
00225 void
00226 node_info_ref (NodeInfo *info)
00227 {
00228   info->base.refcount += 1;
00229 }
00230 
00231 void
00232 node_info_unref (NodeInfo *info)
00233 {
00234   info->base.refcount -= 1;
00235   if (info->base.refcount == 0)
00236     {
00237       free_interface_list (&info->interfaces);
00238       free_node_list (&info->nodes);
00239       base_info_free (info);
00240     }
00241 }
00242 
00243 const char*
00244 node_info_get_name (NodeInfo *info)
00245 {
00246   return info->base.name;
00247 }
00248 
00249 GSList*
00250 node_info_get_interfaces (NodeInfo *info)
00251 {
00252   return info->interfaces;
00253 }
00254 
00255 void
00256 node_info_add_interface (NodeInfo *info,
00257                          InterfaceInfo    *interface)
00258 {
00259   interface_info_ref (interface);
00260   info->interfaces = g_slist_append (info->interfaces, interface);
00261 }
00262 
00263 GSList*
00264 node_info_get_nodes (NodeInfo *info)
00265 {
00266   return info->nodes;
00267 }
00268 
00269 void
00270 node_info_add_node (NodeInfo *info,
00271                     NodeInfo *node)
00272 {
00273   node_info_ref (node);
00274   info->nodes = g_slist_append (info->nodes, node);
00275 }
00276 
00277 InterfaceInfo*
00278 interface_info_new (const char *name)
00279 {
00280   InterfaceInfo *info;
00281 
00282   info = g_new0 (InterfaceInfo, 1);
00283   info->base.refcount = 1;
00284   info->base.name = g_strdup (name);
00285   info->base.type = INFO_TYPE_INTERFACE;
00286   
00287   return info;
00288 }
00289 
00290 void
00291 interface_info_ref (InterfaceInfo *info)
00292 {
00293   info->base.refcount += 1;
00294 }
00295 
00296 void
00297 interface_info_unref (InterfaceInfo *info)
00298 {
00299   info->base.refcount -= 1;
00300   if (info->base.refcount == 0)
00301     {
00302       free_method_list (&info->methods);
00303       free_signal_list (&info->signals);
00304       base_info_free (info);
00305     }
00306 }
00307 
00308 const char*
00309 interface_info_get_name (InterfaceInfo *info)
00310 {
00311   return info->base.name;
00312 }
00313 
00314 GSList*
00315 interface_info_get_methods (InterfaceInfo *info)
00316 {
00317   return info->methods;
00318 }
00319 
00320 GSList*
00321 interface_info_get_signals (InterfaceInfo *info)
00322 {
00323   return info->signals;
00324 }
00325 
00326 void
00327 interface_info_add_method (InterfaceInfo *info,
00328                            MethodInfo    *method)
00329 {
00330   method_info_ref (method);
00331   info->methods = g_slist_append (info->methods, method);
00332 }
00333 
00334 void
00335 interface_info_add_signal (InterfaceInfo *info,
00336                            SignalInfo    *signal)
00337 {
00338   signal_info_ref (signal);
00339   info->signals = g_slist_append (info->signals, signal);
00340 }
00341 
00342 static void
00343 free_arg_list (GSList **args_p)
00344 {
00345   GSList *tmp;
00346   tmp = *args_p;
00347   while (tmp != NULL)
00348     {
00349       arg_info_unref (tmp->data);
00350       tmp = tmp->next;
00351     }
00352   g_slist_free (*args_p);
00353   *args_p = NULL;
00354 }
00355 
00356 MethodInfo*
00357 method_info_new (const char *name)
00358 {
00359   MethodInfo *info;
00360 
00361   info = g_new0 (MethodInfo, 1);
00362   info->base.refcount = 1;
00363   info->base.name = g_strdup (name);
00364   info->base.type = INFO_TYPE_METHOD;
00365   
00366   return info;
00367 }
00368 
00369 void
00370 method_info_ref (MethodInfo *info)
00371 {
00372   info->base.refcount += 1;
00373 }
00374 
00375 void
00376 method_info_unref (MethodInfo *info)
00377 {
00378   info->base.refcount -= 1;
00379   if (info->base.refcount == 0)
00380     {
00381       free_arg_list (&info->args);
00382       base_info_free (info);
00383     }
00384 }
00385 
00386 const char*
00387 method_info_get_name (MethodInfo *info)
00388 {
00389   return info->base.name;
00390 }
00391 
00392 GSList*
00393 method_info_get_args (MethodInfo *info)
00394 {
00395   return info->args;
00396 }
00397 
00398 void
00399 method_info_add_arg (MethodInfo    *info,
00400                      ArgInfo       *arg)
00401 {
00402   arg_info_ref (arg);
00403   info->args = g_slist_append (info->args, arg);
00404 }
00405 
00406 SignalInfo*
00407 signal_info_new (const char *name)
00408 {
00409   SignalInfo *info;
00410 
00411   info = g_new0 (SignalInfo, 1);
00412   info->base.refcount = 1;
00413   info->base.name = g_strdup (name);
00414   info->base.type = INFO_TYPE_SIGNAL;
00415   
00416   return info;
00417 }
00418 
00419 void
00420 signal_info_ref (SignalInfo *info)
00421 {
00422   info->base.refcount += 1;
00423 }
00424 
00425 void
00426 signal_info_unref (SignalInfo *info)
00427 {
00428   info->base.refcount -= 1;
00429   if (info->base.refcount == 0)
00430     {
00431       free_arg_list (&info->args);
00432       base_info_free (info);
00433     }
00434 }
00435 
00436 const char*
00437 signal_info_get_name (SignalInfo *info)
00438 {
00439   return info->base.name;
00440 }
00441 
00442 GSList*
00443 signal_info_get_args (SignalInfo *info)
00444 {
00445   return info->args;
00446 }
00447 
00448 void
00449 signal_info_add_arg (SignalInfo    *info,
00450                      ArgInfo       *arg)
00451 {
00452   arg_info_ref (arg);
00453   info->args = g_slist_append (info->args, arg);
00454 }
00455 
00456 ArgInfo*
00457 arg_info_new (const char  *name,
00458               ArgDirection direction,
00459               int          type)
00460 {
00461   ArgInfo *info;
00462 
00463   info = g_new0 (ArgInfo, 1);
00464   info->base.refcount = 1;
00465   info->base.type = INFO_TYPE_ARG;
00466   
00467   /* name can be NULL */
00468   info->base.name = g_strdup (name);
00469   info->direction = direction;
00470   info->type = type;
00471 
00472   return info;
00473 }
00474 
00475 void
00476 arg_info_ref (ArgInfo *info)
00477 {
00478   info->base.refcount += 1;
00479 }
00480 
00481 void
00482 arg_info_unref (ArgInfo *info)
00483 {
00484   info->base.refcount -= 1;
00485   if (info->base.refcount == 0)
00486     {
00487       base_info_free (info);
00488     }
00489 }
00490 const char*
00491 arg_info_get_name (ArgInfo *info)
00492 {
00493   return info->base.name;
00494 }
00495 
00496 int
00497 arg_info_get_type (ArgInfo *info)
00498 {
00499   return info->type;
00500 }
00501 
00502 ArgDirection
00503 arg_info_get_direction (ArgInfo *info)
00504 {
00505   return info->direction;
00506 }
00507 
00508 #ifdef DBUS_BUILD_TESTS
00509 
00515 dbus_bool_t
00516 _dbus_gidl_test (void)
00517 {
00518 
00519   return TRUE;
00520 }
00521 
00522 #endif /* DBUS_BUILD_TESTS */
00523 
00524 #endif /* DOXYGEN_SHOULD_SKIP_THIS */

Generated on Tue Feb 10 18:14:02 2004 for D-BUS by doxygen 1.3.5