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 1.2
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_if_fail (info != NULL);
74 g_return_if_fail (info->refcount > 0);
80 base_info_free (void *ptr)
91 base_info_unref (BaseInfo *info)
93 g_return_if_fail (info != NULL);
94 g_return_if_fail (info->refcount > 0);
96 /* This is sort of bizarre, BaseInfo was tacked on later */
101 node_info_unref ((NodeInfo*) info);
103 case INFO_TYPE_INTERFACE:
104 interface_info_unref ((InterfaceInfo*) info);
106 case INFO_TYPE_SIGNAL:
107 signal_info_unref ((SignalInfo*) info);
109 case INFO_TYPE_METHOD:
110 method_info_unref ((MethodInfo*) info);
113 arg_info_unref ((ArgInfo*) info);
119 base_info_get_type (BaseInfo *info)
125 base_info_get_name (BaseInfo *info)
131 base_info_set_name (BaseInfo *info,
137 info->name = g_strdup (name);
142 base_info_get_gtype (void)
144 static GType our_type = 0;
147 our_type = g_boxed_type_register_static ("BaseInfo",
148 (GBoxedCopyFunc) base_info_ref,
149 (GBoxedFreeFunc) base_info_unref);
155 free_interface_list (GSList **interfaces_p)
161 interface_info_unref (tmp->data);
164 g_slist_free (*interfaces_p);
165 *interfaces_p = NULL;
169 free_node_list (GSList **nodes_p)
175 node_info_unref (tmp->data);
178 g_slist_free (*nodes_p);
183 free_method_list (GSList **methods_p)
189 method_info_unref (tmp->data);
192 g_slist_free (*methods_p);
197 free_signal_list (GSList **signals_p)
203 signal_info_unref (tmp->data);
206 g_slist_free (*signals_p);
211 node_info_new (const char *name)
215 /* name can be NULL */
217 info = g_new0 (NodeInfo, 1);
218 info->base.refcount = 1;
219 info->base.name = g_strdup (name);
220 info->base.type = INFO_TYPE_NODE;
226 node_info_ref (NodeInfo *info)
228 info->base.refcount += 1;
232 node_info_unref (NodeInfo *info)
234 info->base.refcount -= 1;
235 if (info->base.refcount == 0)
237 free_interface_list (&info->interfaces);
238 free_node_list (&info->nodes);
239 base_info_free (info);
244 node_info_get_name (NodeInfo *info)
246 return info->base.name;
250 node_info_get_interfaces (NodeInfo *info)
252 return info->interfaces;
256 node_info_add_interface (NodeInfo *info,
257 InterfaceInfo *interface)
259 interface_info_ref (interface);
260 info->interfaces = g_slist_append (info->interfaces, interface);
264 node_info_get_nodes (NodeInfo *info)
270 node_info_add_node (NodeInfo *info,
273 node_info_ref (node);
274 info->nodes = g_slist_append (info->nodes, node);
278 interface_info_new (const char *name)
282 info = g_new0 (InterfaceInfo, 1);
283 info->base.refcount = 1;
284 info->base.name = g_strdup (name);
285 info->base.type = INFO_TYPE_INTERFACE;
291 interface_info_ref (InterfaceInfo *info)
293 info->base.refcount += 1;
297 interface_info_unref (InterfaceInfo *info)
299 info->base.refcount -= 1;
300 if (info->base.refcount == 0)
302 free_method_list (&info->methods);
303 free_signal_list (&info->signals);
304 base_info_free (info);
309 interface_info_get_name (InterfaceInfo *info)
311 return info->base.name;
315 interface_info_get_methods (InterfaceInfo *info)
317 return info->methods;
321 interface_info_get_signals (InterfaceInfo *info)
323 return info->signals;
327 interface_info_add_method (InterfaceInfo *info,
330 method_info_ref (method);
331 info->methods = g_slist_append (info->methods, method);
335 interface_info_add_signal (InterfaceInfo *info,
338 signal_info_ref (signal);
339 info->signals = g_slist_append (info->signals, signal);
343 free_arg_list (GSList **args_p)
349 arg_info_unref (tmp->data);
352 g_slist_free (*args_p);
357 method_info_new (const char *name)
361 info = g_new0 (MethodInfo, 1);
362 info->base.refcount = 1;
363 info->base.name = g_strdup (name);
364 info->base.type = INFO_TYPE_METHOD;
370 method_info_ref (MethodInfo *info)
372 info->base.refcount += 1;
376 method_info_unref (MethodInfo *info)
378 info->base.refcount -= 1;
379 if (info->base.refcount == 0)
381 free_arg_list (&info->args);
382 base_info_free (info);
387 method_info_get_name (MethodInfo *info)
389 return info->base.name;
393 method_info_get_args (MethodInfo *info)
399 method_info_add_arg (MethodInfo *info,
403 info->args = g_slist_append (info->args, arg);
407 signal_info_new (const char *name)
411 info = g_new0 (SignalInfo, 1);
412 info->base.refcount = 1;
413 info->base.name = g_strdup (name);
414 info->base.type = INFO_TYPE_SIGNAL;
420 signal_info_ref (SignalInfo *info)
422 info->base.refcount += 1;
426 signal_info_unref (SignalInfo *info)
428 info->base.refcount -= 1;
429 if (info->base.refcount == 0)
431 free_arg_list (&info->args);
432 base_info_free (info);
437 signal_info_get_name (SignalInfo *info)
439 return info->base.name;
443 signal_info_get_args (SignalInfo *info)
449 signal_info_add_arg (SignalInfo *info,
453 info->args = g_slist_append (info->args, arg);
457 arg_info_new (const char *name,
458 ArgDirection direction,
463 info = g_new0 (ArgInfo, 1);
464 info->base.refcount = 1;
465 info->base.type = INFO_TYPE_ARG;
467 /* name can be NULL */
468 info->base.name = g_strdup (name);
469 info->direction = direction;
476 arg_info_ref (ArgInfo *info)
478 info->base.refcount += 1;
482 arg_info_unref (ArgInfo *info)
484 info->base.refcount -= 1;
485 if (info->base.refcount == 0)
487 base_info_free (info);
491 arg_info_get_name (ArgInfo *info)
493 return info->base.name;
497 arg_info_get_type (ArgInfo *info)
503 arg_info_get_direction (ArgInfo *info)
505 return info->direction;
508 #ifdef DBUS_BUILD_TESTS
512 * Unit test for GLib IDL internals
513 * @returns #TRUE on success.
516 _dbus_gidl_test (void)
522 #endif /* DBUS_BUILD_TESTS */
524 #endif /* DOXYGEN_SHOULD_SKIP_THIS */