1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-gidl.c data structure describing an interface, to be generated from IDL
5 * Copyright (C) 2003 Red Hat, Inc.
7 * Licensed under the Academic Free License version 2.0
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "dbus-gidl.h"
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 unsigned int refcount : 28;
32 unsigned int type : 4;
46 /* Since we have BaseInfo now these could be one list */
67 ArgDirection direction;
71 base_info_ref (BaseInfo *info)
73 g_return_val_if_fail (info != NULL, NULL);
74 g_return_val_if_fail (info->refcount > 0, NULL);
82 base_info_free (void *ptr)
93 base_info_unref (BaseInfo *info)
95 g_return_if_fail (info != NULL);
96 g_return_if_fail (info->refcount > 0);
98 /* This is sort of bizarre, BaseInfo was tacked on later */
103 node_info_unref ((NodeInfo*) info);
105 case INFO_TYPE_INTERFACE:
106 interface_info_unref ((InterfaceInfo*) info);
108 case INFO_TYPE_SIGNAL:
109 signal_info_unref ((SignalInfo*) info);
111 case INFO_TYPE_METHOD:
112 method_info_unref ((MethodInfo*) info);
115 arg_info_unref ((ArgInfo*) info);
121 base_info_get_type (BaseInfo *info)
127 base_info_get_name (BaseInfo *info)
133 base_info_set_name (BaseInfo *info,
139 info->name = g_strdup (name);
144 base_info_get_gtype (void)
146 static GType our_type = 0;
149 our_type = g_boxed_type_register_static ("BaseInfo",
150 (GBoxedCopyFunc) base_info_ref,
151 (GBoxedFreeFunc) base_info_unref);
157 free_interface_list (GSList **interfaces_p)
163 interface_info_unref (tmp->data);
166 g_slist_free (*interfaces_p);
167 *interfaces_p = NULL;
171 free_node_list (GSList **nodes_p)
177 node_info_unref (tmp->data);
180 g_slist_free (*nodes_p);
185 free_method_list (GSList **methods_p)
191 method_info_unref (tmp->data);
194 g_slist_free (*methods_p);
199 free_signal_list (GSList **signals_p)
205 signal_info_unref (tmp->data);
208 g_slist_free (*signals_p);
213 node_info_new (const char *name)
217 /* name can be NULL */
219 info = g_new0 (NodeInfo, 1);
220 info->base.refcount = 1;
221 info->base.name = g_strdup (name);
222 info->base.type = INFO_TYPE_NODE;
228 node_info_ref (NodeInfo *info)
230 info->base.refcount += 1;
236 node_info_unref (NodeInfo *info)
238 info->base.refcount -= 1;
239 if (info->base.refcount == 0)
241 free_interface_list (&info->interfaces);
242 free_node_list (&info->nodes);
243 base_info_free (info);
248 node_info_get_name (NodeInfo *info)
250 return info->base.name;
254 node_info_get_interfaces (NodeInfo *info)
256 return info->interfaces;
260 node_info_add_interface (NodeInfo *info,
261 InterfaceInfo *interface)
263 interface_info_ref (interface);
264 info->interfaces = g_slist_append (info->interfaces, interface);
268 node_info_get_nodes (NodeInfo *info)
274 node_info_add_node (NodeInfo *info,
277 node_info_ref (node);
278 info->nodes = g_slist_append (info->nodes, node);
282 interface_info_new (const char *name)
286 info = g_new0 (InterfaceInfo, 1);
287 info->base.refcount = 1;
288 info->base.name = g_strdup (name);
289 info->base.type = INFO_TYPE_INTERFACE;
295 interface_info_ref (InterfaceInfo *info)
297 info->base.refcount += 1;
303 interface_info_unref (InterfaceInfo *info)
305 info->base.refcount -= 1;
306 if (info->base.refcount == 0)
308 free_method_list (&info->methods);
309 free_signal_list (&info->signals);
310 base_info_free (info);
315 interface_info_get_name (InterfaceInfo *info)
317 return info->base.name;
321 interface_info_get_methods (InterfaceInfo *info)
323 return info->methods;
327 interface_info_get_signals (InterfaceInfo *info)
329 return info->signals;
333 interface_info_add_method (InterfaceInfo *info,
336 method_info_ref (method);
337 info->methods = g_slist_append (info->methods, method);
341 interface_info_add_signal (InterfaceInfo *info,
344 signal_info_ref (signal);
345 info->signals = g_slist_append (info->signals, signal);
349 free_arg_list (GSList **args_p)
355 arg_info_unref (tmp->data);
358 g_slist_free (*args_p);
363 method_info_new (const char *name)
367 info = g_new0 (MethodInfo, 1);
368 info->base.refcount = 1;
369 info->base.name = g_strdup (name);
370 info->base.type = INFO_TYPE_METHOD;
376 method_info_ref (MethodInfo *info)
378 info->base.refcount += 1;
384 method_info_unref (MethodInfo *info)
386 info->base.refcount -= 1;
387 if (info->base.refcount == 0)
389 free_arg_list (&info->args);
390 base_info_free (info);
395 method_info_get_name (MethodInfo *info)
397 return info->base.name;
401 method_info_get_args (MethodInfo *info)
407 args_sort_by_direction (const void *a,
410 const ArgInfo *arg_a = a;
411 const ArgInfo *arg_b = b;
413 if (arg_a->direction == arg_b->direction)
415 else if (arg_a->direction == ARG_IN)
416 return -1; /* in is less than out */
422 method_info_add_arg (MethodInfo *info,
426 info->args = g_slist_append (info->args, arg);
428 /* Keep "in" args sorted before "out" and otherwise maintain
429 * stable order (g_slist_sort is stable, at least in sufficiently
432 info->args = g_slist_sort (info->args, args_sort_by_direction);
436 signal_info_new (const char *name)
440 info = g_new0 (SignalInfo, 1);
441 info->base.refcount = 1;
442 info->base.name = g_strdup (name);
443 info->base.type = INFO_TYPE_SIGNAL;
449 signal_info_ref (SignalInfo *info)
451 info->base.refcount += 1;
457 signal_info_unref (SignalInfo *info)
459 info->base.refcount -= 1;
460 if (info->base.refcount == 0)
462 free_arg_list (&info->args);
463 base_info_free (info);
468 signal_info_get_name (SignalInfo *info)
470 return info->base.name;
474 signal_info_get_args (SignalInfo *info)
480 signal_info_add_arg (SignalInfo *info,
483 g_assert (arg->direction == ARG_OUT);
486 info->args = g_slist_append (info->args, arg);
488 /* signal args don't need sorting since only "out" is allowed */
492 arg_info_new (const char *name,
493 ArgDirection direction,
498 info = g_new0 (ArgInfo, 1);
499 info->base.refcount = 1;
500 info->base.type = INFO_TYPE_ARG;
502 /* name can be NULL */
503 info->base.name = g_strdup (name);
504 info->direction = direction;
511 arg_info_ref (ArgInfo *info)
513 info->base.refcount += 1;
519 arg_info_unref (ArgInfo *info)
521 info->base.refcount -= 1;
522 if (info->base.refcount == 0)
524 base_info_free (info);
528 arg_info_get_name (ArgInfo *info)
530 return info->base.name;
534 arg_info_get_type (ArgInfo *info)
540 arg_info_get_direction (ArgInfo *info)
542 return info->direction;
545 #ifdef DBUS_BUILD_TESTS
549 * Unit test for GLib IDL internals
550 * @returns #TRUE on success.
553 _dbus_gidl_test (void)
559 #endif /* DBUS_BUILD_TESTS */
561 #endif /* DOXYGEN_SHOULD_SKIP_THIS */