os/ossrv/ofdbus/dbus-glib/dbus/dbus-gidl.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* -*- mode: C; c-file-style: "gnu" -*- */
sl@0
     2
/* dbus-gidl.c data structure describing an interface, to be generated from IDL
sl@0
     3
 *             or something
sl@0
     4
 *
sl@0
     5
 * Copyright (C) 2003, 2005  Red Hat, Inc.
sl@0
     6
 * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0
     7
 * Licensed under the Academic Free License version 2.1
sl@0
     8
 *
sl@0
     9
 * This program is free software; you can redistribute it and/or modify
sl@0
    10
 * it under the terms of the GNU General Public License as published by
sl@0
    11
 * the Free Software Foundation; either version 2 of the License, or
sl@0
    12
 * (at your option) any later version.
sl@0
    13
 *
sl@0
    14
 * This program is distributed in the hope that it will be useful,
sl@0
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
sl@0
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
sl@0
    17
 * GNU General Public License for more details.
sl@0
    18
 *
sl@0
    19
 * You should have received a copy of the GNU General Public License
sl@0
    20
 * along with this program; if not, write to the Free Software
sl@0
    21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
sl@0
    22
 *
sl@0
    23
 */
sl@0
    24
sl@0
    25
#include "dbus-gidl.h"
sl@0
    26
sl@0
    27
#ifndef DOXYGEN_SHOULD_SKIP_THIS
sl@0
    28
sl@0
    29
struct BaseInfo
sl@0
    30
{
sl@0
    31
  unsigned int refcount : 28;
sl@0
    32
  unsigned int type     : 4;
sl@0
    33
  char *name;
sl@0
    34
};
sl@0
    35
sl@0
    36
struct NodeInfo
sl@0
    37
{
sl@0
    38
  BaseInfo base;
sl@0
    39
  GSList *interfaces;
sl@0
    40
  GSList *nodes;
sl@0
    41
};
sl@0
    42
sl@0
    43
struct InterfaceInfo
sl@0
    44
{
sl@0
    45
  BaseInfo base;
sl@0
    46
  GHashTable *annotations;
sl@0
    47
  /* Since we have BaseInfo now these could be one list */
sl@0
    48
  GSList *methods;
sl@0
    49
  GSList *signals;
sl@0
    50
  GSList *properties;
sl@0
    51
};
sl@0
    52
sl@0
    53
struct MethodInfo
sl@0
    54
{
sl@0
    55
  BaseInfo base;
sl@0
    56
  GHashTable *annotations;
sl@0
    57
  GSList *args;
sl@0
    58
};
sl@0
    59
sl@0
    60
struct SignalInfo
sl@0
    61
{
sl@0
    62
  BaseInfo base;
sl@0
    63
  GSList *args;
sl@0
    64
};
sl@0
    65
sl@0
    66
struct PropertyInfo
sl@0
    67
{
sl@0
    68
  BaseInfo base;
sl@0
    69
  char *type;
sl@0
    70
  PropertyAccessFlags access;
sl@0
    71
};
sl@0
    72
sl@0
    73
struct ArgInfo
sl@0
    74
{
sl@0
    75
  BaseInfo base;
sl@0
    76
  char *type;
sl@0
    77
  ArgDirection direction;
sl@0
    78
  GHashTable *annotations;
sl@0
    79
};
sl@0
    80
sl@0
    81
static void
sl@0
    82
get_hash_key (gpointer key, gpointer value, gpointer data)
sl@0
    83
{
sl@0
    84
  GSList **list = data;
sl@0
    85
  *list = g_slist_prepend (*list, key);
sl@0
    86
}
sl@0
    87
sl@0
    88
static GSList *
sl@0
    89
get_hash_keys (GHashTable *table)
sl@0
    90
{
sl@0
    91
  GSList *ret = NULL;
sl@0
    92
sl@0
    93
  g_hash_table_foreach (table, get_hash_key, &ret);
sl@0
    94
sl@0
    95
  return ret;
sl@0
    96
}
sl@0
    97
sl@0
    98
BaseInfo *
sl@0
    99
base_info_ref (BaseInfo *info)
sl@0
   100
{
sl@0
   101
  g_return_val_if_fail (info != NULL, NULL);
sl@0
   102
  g_return_val_if_fail (info->refcount > 0, NULL);
sl@0
   103
  
sl@0
   104
  info->refcount += 1;
sl@0
   105
sl@0
   106
  return info;
sl@0
   107
}
sl@0
   108
sl@0
   109
static void
sl@0
   110
base_info_free (void *ptr)
sl@0
   111
{
sl@0
   112
  BaseInfo *info;
sl@0
   113
sl@0
   114
  info = ptr;
sl@0
   115
  
sl@0
   116
  g_free (info->name);
sl@0
   117
  g_free (info);
sl@0
   118
}
sl@0
   119
sl@0
   120
void
sl@0
   121
base_info_unref (BaseInfo *info)
sl@0
   122
{
sl@0
   123
  g_return_if_fail (info != NULL);
sl@0
   124
  g_return_if_fail (info->refcount > 0);
sl@0
   125
  
sl@0
   126
  /* This is sort of bizarre, BaseInfo was tacked on later */
sl@0
   127
sl@0
   128
  switch (info->type)
sl@0
   129
    {
sl@0
   130
    case INFO_TYPE_NODE:
sl@0
   131
      node_info_unref ((NodeInfo*) info);
sl@0
   132
      break;
sl@0
   133
    case INFO_TYPE_INTERFACE:
sl@0
   134
      interface_info_unref ((InterfaceInfo*) info);
sl@0
   135
      break;
sl@0
   136
    case INFO_TYPE_SIGNAL:
sl@0
   137
      signal_info_unref ((SignalInfo*) info);
sl@0
   138
      break;
sl@0
   139
    case INFO_TYPE_METHOD:
sl@0
   140
      method_info_unref ((MethodInfo*) info);
sl@0
   141
      break;
sl@0
   142
    case INFO_TYPE_PROPERTY:
sl@0
   143
      property_info_unref ((PropertyInfo*) info);
sl@0
   144
      break;
sl@0
   145
    case INFO_TYPE_ARG:
sl@0
   146
      arg_info_unref ((ArgInfo*) info);
sl@0
   147
      break;
sl@0
   148
    }
sl@0
   149
}
sl@0
   150
sl@0
   151
InfoType
sl@0
   152
base_info_get_type (BaseInfo      *info)
sl@0
   153
{
sl@0
   154
  return info->type;
sl@0
   155
}
sl@0
   156
sl@0
   157
const char*
sl@0
   158
base_info_get_name (BaseInfo *info)
sl@0
   159
{
sl@0
   160
  return info->name;
sl@0
   161
}
sl@0
   162
sl@0
   163
void
sl@0
   164
base_info_set_name (BaseInfo      *info,
sl@0
   165
                    const char    *name)
sl@0
   166
{
sl@0
   167
  char *old;
sl@0
   168
sl@0
   169
  old = info->name;
sl@0
   170
  info->name = g_strdup (name);
sl@0
   171
  g_free (old);
sl@0
   172
}
sl@0
   173
sl@0
   174
GType
sl@0
   175
base_info_get_gtype (void)
sl@0
   176
{
sl@0
   177
 
sl@0
   178
  #if EMULATOR
sl@0
   179
GET_STATIC_VAR_FROM_TLS(out_type,dbus_gidl,GType )
sl@0
   180
#define our_type (*GET_DBUS_WSD_VAR_NAME(our_type,dbus_gidl,s)())
sl@0
   181
#else
sl@0
   182
  static GType our_type = 0;
sl@0
   183
#endif
sl@0
   184
sl@0
   185
  
sl@0
   186
  if (our_type == 0)
sl@0
   187
    our_type = g_boxed_type_register_static ("BaseInfo",
sl@0
   188
                                             (GBoxedCopyFunc) base_info_ref,
sl@0
   189
                                             (GBoxedFreeFunc) base_info_unref);
sl@0
   190
sl@0
   191
  return our_type;
sl@0
   192
}
sl@0
   193
sl@0
   194
static void
sl@0
   195
free_interface_list (GSList **interfaces_p)
sl@0
   196
{
sl@0
   197
  GSList *tmp;
sl@0
   198
  tmp = *interfaces_p;
sl@0
   199
  while (tmp != NULL)
sl@0
   200
    {
sl@0
   201
      interface_info_unref (tmp->data);
sl@0
   202
      tmp = tmp->next;
sl@0
   203
    }
sl@0
   204
  g_slist_free (*interfaces_p);
sl@0
   205
  *interfaces_p = NULL;
sl@0
   206
}
sl@0
   207
sl@0
   208
static void
sl@0
   209
free_node_list (GSList **nodes_p)
sl@0
   210
{
sl@0
   211
  GSList *tmp;
sl@0
   212
  tmp = *nodes_p;
sl@0
   213
  while (tmp != NULL)
sl@0
   214
    {
sl@0
   215
      node_info_unref (tmp->data);
sl@0
   216
      tmp = tmp->next;
sl@0
   217
    }
sl@0
   218
  g_slist_free (*nodes_p);
sl@0
   219
  *nodes_p = NULL;
sl@0
   220
}
sl@0
   221
sl@0
   222
static void
sl@0
   223
free_method_list (GSList **methods_p)
sl@0
   224
{
sl@0
   225
  GSList *tmp;
sl@0
   226
  tmp = *methods_p;
sl@0
   227
  while (tmp != NULL)
sl@0
   228
    {
sl@0
   229
      method_info_unref (tmp->data);
sl@0
   230
      tmp = tmp->next;
sl@0
   231
    }
sl@0
   232
  g_slist_free (*methods_p);
sl@0
   233
  *methods_p = NULL;
sl@0
   234
}
sl@0
   235
sl@0
   236
static void
sl@0
   237
free_signal_list (GSList **signals_p)
sl@0
   238
{
sl@0
   239
  GSList *tmp;
sl@0
   240
  tmp = *signals_p;
sl@0
   241
  while (tmp != NULL)
sl@0
   242
    {
sl@0
   243
      signal_info_unref (tmp->data);
sl@0
   244
      tmp = tmp->next;
sl@0
   245
    }
sl@0
   246
  g_slist_free (*signals_p);
sl@0
   247
  *signals_p = NULL;
sl@0
   248
}
sl@0
   249
sl@0
   250
static void
sl@0
   251
free_property_list (GSList **props_p)
sl@0
   252
{
sl@0
   253
  GSList *tmp;
sl@0
   254
  tmp = *props_p;
sl@0
   255
  while (tmp != NULL)
sl@0
   256
    {
sl@0
   257
      property_info_unref (tmp->data);
sl@0
   258
      tmp = tmp->next;
sl@0
   259
    }
sl@0
   260
  g_slist_free (*props_p);
sl@0
   261
  *props_p = NULL;
sl@0
   262
}
sl@0
   263
sl@0
   264
NodeInfo*
sl@0
   265
node_info_new (const char *name)
sl@0
   266
{
sl@0
   267
  NodeInfo *info;
sl@0
   268
sl@0
   269
  /* name can be NULL */
sl@0
   270
  
sl@0
   271
  info = g_new0 (NodeInfo, 1);
sl@0
   272
  info->base.refcount = 1;
sl@0
   273
  info->base.name = g_strdup (name);
sl@0
   274
  info->base.type = INFO_TYPE_NODE;
sl@0
   275
  
sl@0
   276
  return info;
sl@0
   277
}
sl@0
   278
sl@0
   279
NodeInfo *
sl@0
   280
node_info_ref (NodeInfo *info)
sl@0
   281
{
sl@0
   282
  info->base.refcount += 1;
sl@0
   283
sl@0
   284
  return info;
sl@0
   285
}
sl@0
   286
sl@0
   287
void
sl@0
   288
node_info_unref (NodeInfo *info)
sl@0
   289
{
sl@0
   290
  info->base.refcount -= 1;
sl@0
   291
  if (info->base.refcount == 0)
sl@0
   292
    {
sl@0
   293
      free_interface_list (&info->interfaces);
sl@0
   294
      free_node_list (&info->nodes);
sl@0
   295
      base_info_free (info);
sl@0
   296
    }
sl@0
   297
}
sl@0
   298
sl@0
   299
const char*
sl@0
   300
node_info_get_name (NodeInfo *info)
sl@0
   301
{
sl@0
   302
  return info->base.name;
sl@0
   303
}
sl@0
   304
sl@0
   305
GSList*
sl@0
   306
node_info_get_interfaces (NodeInfo *info)
sl@0
   307
{
sl@0
   308
  return info->interfaces;
sl@0
   309
}
sl@0
   310
sl@0
   311
void
sl@0
   312
node_info_add_interface (NodeInfo *info,
sl@0
   313
                         InterfaceInfo    *interface)
sl@0
   314
{
sl@0
   315
  interface_info_ref (interface);
sl@0
   316
  info->interfaces = g_slist_append (info->interfaces, interface);
sl@0
   317
}
sl@0
   318
sl@0
   319
GSList*
sl@0
   320
node_info_get_nodes (NodeInfo *info)
sl@0
   321
{
sl@0
   322
  return info->nodes;
sl@0
   323
}
sl@0
   324
sl@0
   325
void
sl@0
   326
node_info_add_node (NodeInfo *info,
sl@0
   327
                    NodeInfo *node)
sl@0
   328
{
sl@0
   329
  node_info_ref (node);
sl@0
   330
  info->nodes = g_slist_append (info->nodes, node);
sl@0
   331
}
sl@0
   332
sl@0
   333
void
sl@0
   334
node_info_replace_node (NodeInfo            *info,
sl@0
   335
                        NodeInfo            *old_child,
sl@0
   336
                        NodeInfo            *new_child)
sl@0
   337
{
sl@0
   338
  GSList *link;
sl@0
   339
sl@0
   340
  node_info_ref (new_child); /* before unref old_child in case they are the same */
sl@0
   341
  link = g_slist_find (info->nodes, old_child);
sl@0
   342
  g_assert (link != NULL);
sl@0
   343
  node_info_unref (old_child);
sl@0
   344
  link->data = new_child;
sl@0
   345
}
sl@0
   346
sl@0
   347
InterfaceInfo*
sl@0
   348
interface_info_new (const char *name)
sl@0
   349
{
sl@0
   350
  InterfaceInfo *info;
sl@0
   351
sl@0
   352
  info = g_new0 (InterfaceInfo, 1);
sl@0
   353
  info->base.refcount = 1;
sl@0
   354
  info->base.name = g_strdup (name);
sl@0
   355
  info->base.type = INFO_TYPE_INTERFACE;
sl@0
   356
  info->annotations = g_hash_table_new_full (g_str_hash, g_str_equal,
sl@0
   357
					     (GDestroyNotify) g_free,
sl@0
   358
					     (GDestroyNotify) g_free);
sl@0
   359
  
sl@0
   360
  return info;
sl@0
   361
}
sl@0
   362
sl@0
   363
InterfaceInfo *
sl@0
   364
interface_info_ref (InterfaceInfo *info)
sl@0
   365
{
sl@0
   366
  info->base.refcount += 1;
sl@0
   367
sl@0
   368
  return info;
sl@0
   369
}
sl@0
   370
sl@0
   371
void
sl@0
   372
interface_info_unref (InterfaceInfo *info)
sl@0
   373
{
sl@0
   374
  info->base.refcount -= 1;
sl@0
   375
  if (info->base.refcount == 0)
sl@0
   376
    {
sl@0
   377
      g_hash_table_destroy (info->annotations);
sl@0
   378
      free_method_list (&info->methods);
sl@0
   379
      free_signal_list (&info->signals);
sl@0
   380
      free_property_list (&info->properties);
sl@0
   381
      base_info_free (info);
sl@0
   382
    }
sl@0
   383
}
sl@0
   384
sl@0
   385
const char*
sl@0
   386
interface_info_get_name (InterfaceInfo *info)
sl@0
   387
{
sl@0
   388
  return info->base.name;
sl@0
   389
}
sl@0
   390
sl@0
   391
GSList *
sl@0
   392
interface_info_get_annotations (InterfaceInfo *info)
sl@0
   393
{
sl@0
   394
  return get_hash_keys (info->annotations);
sl@0
   395
}
sl@0
   396
sl@0
   397
const char*
sl@0
   398
interface_info_get_annotation (InterfaceInfo *info,
sl@0
   399
			       const char    *name)
sl@0
   400
{
sl@0
   401
  return g_hash_table_lookup (info->annotations, name);
sl@0
   402
}
sl@0
   403
sl@0
   404
GSList*
sl@0
   405
interface_info_get_methods (InterfaceInfo *info)
sl@0
   406
{
sl@0
   407
  return info->methods;
sl@0
   408
}
sl@0
   409
sl@0
   410
GSList*
sl@0
   411
interface_info_get_signals (InterfaceInfo *info)
sl@0
   412
{
sl@0
   413
  return info->signals;
sl@0
   414
}
sl@0
   415
sl@0
   416
GSList*
sl@0
   417
interface_info_get_properties (InterfaceInfo *info)
sl@0
   418
{
sl@0
   419
  return info->properties;
sl@0
   420
}
sl@0
   421
sl@0
   422
void
sl@0
   423
interface_info_add_annotation (InterfaceInfo *info,
sl@0
   424
			       const char    *name,
sl@0
   425
			       const char    *value)
sl@0
   426
{
sl@0
   427
  g_hash_table_insert (info->annotations,
sl@0
   428
		       g_strdup (name),
sl@0
   429
		       g_strdup (value));
sl@0
   430
}
sl@0
   431
sl@0
   432
void
sl@0
   433
interface_info_add_method (InterfaceInfo *info,
sl@0
   434
                           MethodInfo    *method)
sl@0
   435
{
sl@0
   436
  method_info_ref (method);
sl@0
   437
  info->methods = g_slist_append (info->methods, method);
sl@0
   438
}
sl@0
   439
sl@0
   440
void
sl@0
   441
interface_info_add_signal (InterfaceInfo *info,
sl@0
   442
                           SignalInfo    *signal)
sl@0
   443
{
sl@0
   444
  signal_info_ref (signal);
sl@0
   445
  info->signals = g_slist_append (info->signals, signal);
sl@0
   446
}
sl@0
   447
sl@0
   448
void
sl@0
   449
interface_info_add_property (InterfaceInfo *info,
sl@0
   450
                             PropertyInfo  *property)
sl@0
   451
{
sl@0
   452
  property_info_ref (property);
sl@0
   453
  info->properties = g_slist_append (info->properties, property);
sl@0
   454
}
sl@0
   455
sl@0
   456
static void
sl@0
   457
free_arg_list (GSList **args_p)
sl@0
   458
{
sl@0
   459
  GSList *tmp;
sl@0
   460
  tmp = *args_p;
sl@0
   461
  while (tmp != NULL)
sl@0
   462
    {
sl@0
   463
      ArgInfo *ai = tmp->data;
sl@0
   464
      g_assert (ai->base.type == INFO_TYPE_ARG);
sl@0
   465
      arg_info_unref (tmp->data);
sl@0
   466
      tmp = tmp->next;
sl@0
   467
    }
sl@0
   468
  g_slist_free (*args_p);
sl@0
   469
  *args_p = NULL;
sl@0
   470
}
sl@0
   471
sl@0
   472
MethodInfo*
sl@0
   473
method_info_new (const char *name)
sl@0
   474
{
sl@0
   475
  MethodInfo *info;
sl@0
   476
sl@0
   477
  info = g_new0 (MethodInfo, 1);
sl@0
   478
  info->base.refcount = 1;
sl@0
   479
  info->base.name = g_strdup (name);
sl@0
   480
  info->base.type = INFO_TYPE_METHOD;
sl@0
   481
  info->annotations = g_hash_table_new_full (g_str_hash, g_str_equal,
sl@0
   482
					  (GDestroyNotify) g_free,
sl@0
   483
					  (GDestroyNotify) g_free);
sl@0
   484
  
sl@0
   485
  return info;
sl@0
   486
}
sl@0
   487
sl@0
   488
MethodInfo *
sl@0
   489
method_info_ref (MethodInfo *info)
sl@0
   490
{
sl@0
   491
  info->base.refcount += 1;
sl@0
   492
sl@0
   493
  return info;
sl@0
   494
}
sl@0
   495
sl@0
   496
void
sl@0
   497
method_info_unref (MethodInfo *info)
sl@0
   498
{
sl@0
   499
  info->base.refcount -= 1;
sl@0
   500
  if (info->base.refcount == 0)
sl@0
   501
    {
sl@0
   502
      g_hash_table_destroy (info->annotations);
sl@0
   503
      free_arg_list (&info->args);
sl@0
   504
      base_info_free (info);
sl@0
   505
    }
sl@0
   506
}
sl@0
   507
sl@0
   508
const char*
sl@0
   509
method_info_get_name (MethodInfo *info)
sl@0
   510
{
sl@0
   511
  return info->base.name;
sl@0
   512
}
sl@0
   513
sl@0
   514
GSList *
sl@0
   515
method_info_get_annotations (MethodInfo *info)
sl@0
   516
{
sl@0
   517
  return get_hash_keys (info->annotations);
sl@0
   518
}
sl@0
   519
sl@0
   520
const char*
sl@0
   521
method_info_get_annotation (MethodInfo *info,
sl@0
   522
			    const char *name)
sl@0
   523
{
sl@0
   524
  return g_hash_table_lookup (info->annotations, name);
sl@0
   525
}
sl@0
   526
sl@0
   527
GSList*
sl@0
   528
method_info_get_args (MethodInfo *info)
sl@0
   529
{
sl@0
   530
  return info->args;
sl@0
   531
}
sl@0
   532
sl@0
   533
int
sl@0
   534
method_info_get_n_args (MethodInfo *info)
sl@0
   535
{
sl@0
   536
  return g_slist_length (info->args);
sl@0
   537
}
sl@0
   538
sl@0
   539
static int
sl@0
   540
args_sort_by_direction (const void *a,
sl@0
   541
                        const void *b)
sl@0
   542
{
sl@0
   543
  const ArgInfo *arg_a = a;
sl@0
   544
  const ArgInfo *arg_b = b;
sl@0
   545
sl@0
   546
  if (arg_a->direction == arg_b->direction)
sl@0
   547
    return 0;
sl@0
   548
  else if (arg_a->direction == ARG_IN)
sl@0
   549
    return -1; /* in is less than out */
sl@0
   550
  else
sl@0
   551
    return 1;
sl@0
   552
}                  
sl@0
   553
sl@0
   554
void
sl@0
   555
method_info_add_annotation (MethodInfo  *info,
sl@0
   556
			    const char  *name,
sl@0
   557
			    const char  *value)
sl@0
   558
{
sl@0
   559
  g_hash_table_insert (info->annotations,
sl@0
   560
		       g_strdup (name),
sl@0
   561
		       g_strdup (value));
sl@0
   562
}
sl@0
   563
sl@0
   564
void
sl@0
   565
method_info_add_arg (MethodInfo    *info,
sl@0
   566
                     ArgInfo       *arg)
sl@0
   567
{
sl@0
   568
  arg_info_ref (arg);
sl@0
   569
  info->args = g_slist_append (info->args, arg);
sl@0
   570
sl@0
   571
  /* Keep "in" args sorted before "out" and otherwise maintain
sl@0
   572
   * stable order (g_slist_sort is stable, at least in sufficiently
sl@0
   573
   * new glib)
sl@0
   574
   */
sl@0
   575
  info->args = g_slist_sort (info->args, args_sort_by_direction);
sl@0
   576
}
sl@0
   577
sl@0
   578
SignalInfo*
sl@0
   579
signal_info_new (const char *name)
sl@0
   580
{
sl@0
   581
  SignalInfo *info;
sl@0
   582
sl@0
   583
  info = g_new0 (SignalInfo, 1);
sl@0
   584
  info->base.refcount = 1;
sl@0
   585
  info->base.name = g_strdup (name);
sl@0
   586
  info->base.type = INFO_TYPE_SIGNAL;
sl@0
   587
  
sl@0
   588
  return info;
sl@0
   589
}
sl@0
   590
sl@0
   591
SignalInfo *
sl@0
   592
signal_info_ref (SignalInfo *info)
sl@0
   593
{
sl@0
   594
  info->base.refcount += 1;
sl@0
   595
sl@0
   596
  return info;
sl@0
   597
}
sl@0
   598
sl@0
   599
void
sl@0
   600
signal_info_unref (SignalInfo *info)
sl@0
   601
{
sl@0
   602
  info->base.refcount -= 1;
sl@0
   603
  if (info->base.refcount == 0)
sl@0
   604
    {
sl@0
   605
      free_arg_list (&info->args);
sl@0
   606
      base_info_free (info);
sl@0
   607
    }
sl@0
   608
}
sl@0
   609
sl@0
   610
const char*
sl@0
   611
signal_info_get_name (SignalInfo *info)
sl@0
   612
{
sl@0
   613
  return info->base.name;
sl@0
   614
}
sl@0
   615
sl@0
   616
GSList*
sl@0
   617
signal_info_get_args (SignalInfo *info)
sl@0
   618
{
sl@0
   619
  return info->args;
sl@0
   620
}
sl@0
   621
sl@0
   622
int
sl@0
   623
signal_info_get_n_args (SignalInfo *info)
sl@0
   624
{
sl@0
   625
  return g_slist_length (info->args);
sl@0
   626
}
sl@0
   627
sl@0
   628
void
sl@0
   629
signal_info_add_arg (SignalInfo    *info,
sl@0
   630
                     ArgInfo       *arg)
sl@0
   631
{
sl@0
   632
  g_assert (arg->direction == ARG_OUT);
sl@0
   633
  
sl@0
   634
  arg_info_ref (arg);
sl@0
   635
  info->args = g_slist_append (info->args, arg);
sl@0
   636
  
sl@0
   637
  /* signal args don't need sorting since only "out" is allowed */
sl@0
   638
}
sl@0
   639
sl@0
   640
PropertyInfo*
sl@0
   641
property_info_new (const char          *name,
sl@0
   642
                   const char          *type,
sl@0
   643
                   PropertyAccessFlags  access)
sl@0
   644
{
sl@0
   645
  PropertyInfo *info;
sl@0
   646
sl@0
   647
  info = g_new0 (PropertyInfo, 1);
sl@0
   648
  info->base.refcount = 1;
sl@0
   649
  info->base.name = g_strdup (name);
sl@0
   650
  info->base.type = INFO_TYPE_PROPERTY;
sl@0
   651
sl@0
   652
  info->type = g_strdup (type);
sl@0
   653
  info->access = access;
sl@0
   654
  
sl@0
   655
  return info;
sl@0
   656
}
sl@0
   657
sl@0
   658
PropertyInfo*
sl@0
   659
property_info_ref (PropertyInfo *info)
sl@0
   660
{
sl@0
   661
  info->base.refcount += 1;
sl@0
   662
  
sl@0
   663
  return info;
sl@0
   664
}
sl@0
   665
sl@0
   666
void
sl@0
   667
property_info_unref (PropertyInfo *info)
sl@0
   668
{
sl@0
   669
  info->base.refcount -= 1;
sl@0
   670
  if (info->base.refcount == 0)
sl@0
   671
    {
sl@0
   672
      g_free (info->type);
sl@0
   673
      base_info_free (info);
sl@0
   674
    }
sl@0
   675
}
sl@0
   676
sl@0
   677
const char*
sl@0
   678
property_info_get_name (PropertyInfo *info)
sl@0
   679
{
sl@0
   680
  return info->base.name;
sl@0
   681
}
sl@0
   682
sl@0
   683
const char *
sl@0
   684
property_info_get_type (PropertyInfo *info)
sl@0
   685
{
sl@0
   686
  return info->type;
sl@0
   687
}
sl@0
   688
sl@0
   689
PropertyAccessFlags
sl@0
   690
property_info_get_access (PropertyInfo *info)
sl@0
   691
{
sl@0
   692
  return info->access;
sl@0
   693
}
sl@0
   694
sl@0
   695
ArgInfo*
sl@0
   696
arg_info_new (const char  *name,
sl@0
   697
              ArgDirection direction,
sl@0
   698
              const char  *type)
sl@0
   699
{
sl@0
   700
  ArgInfo *info;
sl@0
   701
sl@0
   702
  info = g_new0 (ArgInfo, 1);
sl@0
   703
  info->base.refcount = 1;
sl@0
   704
  info->base.type = INFO_TYPE_ARG;
sl@0
   705
  
sl@0
   706
  /* name can be NULL */
sl@0
   707
  info->base.name = g_strdup (name);
sl@0
   708
  info->direction = direction;
sl@0
   709
  info->type = g_strdup (type);
sl@0
   710
  info->annotations = g_hash_table_new_full (g_str_hash, g_str_equal,
sl@0
   711
					     (GDestroyNotify) g_free,
sl@0
   712
					     (GDestroyNotify) g_free);
sl@0
   713
sl@0
   714
  return info;
sl@0
   715
}
sl@0
   716
sl@0
   717
ArgInfo *
sl@0
   718
arg_info_ref (ArgInfo *info)
sl@0
   719
{
sl@0
   720
  info->base.refcount += 1;
sl@0
   721
sl@0
   722
  return info;
sl@0
   723
}
sl@0
   724
sl@0
   725
void
sl@0
   726
arg_info_unref (ArgInfo *info)
sl@0
   727
{
sl@0
   728
  info->base.refcount -= 1;
sl@0
   729
  if (info->base.refcount == 0)
sl@0
   730
    {
sl@0
   731
      g_hash_table_destroy (info->annotations);
sl@0
   732
      g_free (info->type);
sl@0
   733
      base_info_free (info);
sl@0
   734
    }
sl@0
   735
}
sl@0
   736
sl@0
   737
const char*
sl@0
   738
arg_info_get_name (ArgInfo *info)
sl@0
   739
{
sl@0
   740
  return info->base.name;
sl@0
   741
}
sl@0
   742
sl@0
   743
const char *
sl@0
   744
arg_info_get_type (ArgInfo *info)
sl@0
   745
{
sl@0
   746
  return info->type;
sl@0
   747
}
sl@0
   748
sl@0
   749
ArgDirection
sl@0
   750
arg_info_get_direction (ArgInfo *info)
sl@0
   751
{
sl@0
   752
  return info->direction;
sl@0
   753
}
sl@0
   754
sl@0
   755
GSList*
sl@0
   756
arg_info_get_annotations (ArgInfo *info)
sl@0
   757
{
sl@0
   758
  return get_hash_keys (info->annotations);
sl@0
   759
}
sl@0
   760
sl@0
   761
const char*
sl@0
   762
arg_info_get_annotation (ArgInfo    *info,
sl@0
   763
			 const char *annotation)
sl@0
   764
{
sl@0
   765
  return g_hash_table_lookup (info->annotations, annotation);
sl@0
   766
}
sl@0
   767
sl@0
   768
void
sl@0
   769
arg_info_add_annotation (ArgInfo             *info,
sl@0
   770
			 const char          *name,
sl@0
   771
			 const char          *value)
sl@0
   772
{
sl@0
   773
  g_hash_table_insert (info->annotations,
sl@0
   774
		       g_strdup (name),
sl@0
   775
		       g_strdup (value));
sl@0
   776
}
sl@0
   777
sl@0
   778
sl@0
   779
#ifdef DBUS_BUILD_TESTS
sl@0
   780
sl@0
   781
/**
sl@0
   782
 * @ingroup DBusGIDL
sl@0
   783
 * Unit test for GLib IDL internals
sl@0
   784
 * Returns: #TRUE on success.
sl@0
   785
 */
sl@0
   786
gboolean
sl@0
   787
_dbus_gidl_test (void)
sl@0
   788
{
sl@0
   789
sl@0
   790
  return TRUE;
sl@0
   791
}
sl@0
   792
sl@0
   793
#endif /* DBUS_BUILD_TESTS */
sl@0
   794
sl@0
   795
#endif /* DOXYGEN_SHOULD_SKIP_THIS */