1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-gtype-specialized.h: Non-DBus-specific functions for specialized GTypes
3  *
4  * Copyright (C) 2005 Red Hat, Inc.
5  *
6  * SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
7  *
8  * Licensed under the Academic Free License version 2.1
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23  *
24  */
25 
26 #ifndef DBUS_GOBJECT_TYPE_SPECIALIZED_H
27 #define DBUS_GOBJECT_TYPE_SPECIALIZED_H
28 
29 #include <glib.h>
30 #include <glib-object.h>
31 
32 G_BEGIN_DECLS
33 
34 GType          dbus_g_type_get_collection                   (const char *container,
35 							     GType       specialization);
36 GType          dbus_g_type_get_map                          (const char *container,
37 							     GType       key_specialization,
38 							     GType       value_specialization);
39 GType          dbus_g_type_get_structv                      (const char *container,
40 							     guint       num_members,
41 							     GType      *types);
42 GType          dbus_g_type_get_struct                       (const char *container,
43                                                              GType       first_type,
44                                                              ...);
45 gboolean       dbus_g_type_is_collection                    (GType       gtype);
46 gboolean       dbus_g_type_is_map                           (GType       gtype);
47 gboolean       dbus_g_type_is_struct                        (GType       gtype);
48 GType          dbus_g_type_get_collection_specialization    (GType       gtype);
49 GType          dbus_g_type_get_map_key_specialization       (GType       gtype);
50 GType          dbus_g_type_get_map_value_specialization     (GType       gtype);
51 GType          dbus_g_type_get_struct_member_type           (GType       gtype,
52                                                              guint       member);
53 guint          dbus_g_type_get_struct_size                  (GType       gtype);
54 
55 typedef void   (*DBusGTypeSpecializedCollectionIterator)    (const GValue *value,
56 							     gpointer      user_data);
57 typedef void   (*DBusGTypeSpecializedMapIterator)           (const GValue *key_val,
58 							     const GValue *value_val,
59 							     gpointer      user_data);
60 
61 gpointer       dbus_g_type_specialized_construct            (GType gtype);
62 
63 typedef struct {
64   /* public */
65   GValue *val;
66   GType specialization_type;
67   /*< private >*/
68   /* padding */
69   gpointer b;
70   guint c;
71   gpointer d;
72 } DBusGTypeSpecializedAppendContext;
73 
74 void           dbus_g_type_specialized_init_append             (GValue *value, DBusGTypeSpecializedAppendContext *ctx);
75 
76 void           dbus_g_type_specialized_collection_append       (DBusGTypeSpecializedAppendContext *ctx, GValue *elt);
77 
78 void           dbus_g_type_specialized_collection_end_append   (DBusGTypeSpecializedAppendContext *ctx);
79 
80 void           dbus_g_type_specialized_map_append              (DBusGTypeSpecializedAppendContext *ctx,
81 								GValue                            *key,
82 								GValue                            *val);
83 
84 
85 gboolean       dbus_g_type_collection_get_fixed             (GValue                                 *value,
86 							     gpointer                               *data_ret,
87 							     guint                                  *len_ret);
88 
89 void           dbus_g_type_collection_value_iterate         (const GValue                           *value,
90 							     DBusGTypeSpecializedCollectionIterator  iterator,
91 							     gpointer                                user_data);
92 
93 void           dbus_g_type_map_value_iterate                (const GValue                           *value,
94 							     DBusGTypeSpecializedMapIterator         iterator,
95 							     gpointer                                user_data);
96 
97 gboolean       dbus_g_type_struct_get_member            (const GValue *value,
98                                                          guint member,
99                                                          GValue *dest);
100 gboolean       dbus_g_type_struct_set_member            (GValue *value,
101                                                          guint member,
102                                                          const GValue *src);
103 
104 gboolean       dbus_g_type_struct_get                   (const GValue *value,
105                                                          guint member,
106                                                          ...);
107 
108 gboolean       dbus_g_type_struct_set                   (GValue *value,
109                                                          guint member,
110                                                          ...);
111 
112 typedef gpointer (*DBusGTypeSpecializedConstructor)     (GType type);
113 typedef void     (*DBusGTypeSpecializedFreeFunc)        (GType type, gpointer val);
114 typedef gpointer (*DBusGTypeSpecializedCopyFunc)        (GType type, gpointer src);
115 
116 typedef struct {
117   DBusGTypeSpecializedConstructor    constructor;
118   DBusGTypeSpecializedFreeFunc       free_func;
119   DBusGTypeSpecializedCopyFunc       copy_func;
120   GDestroyNotify                     simple_free_func; /* for type-independent freeing if possible */
121   /*<private>*/
122   gpointer                           padding2;
123   gpointer                           padding3;
124 } DBusGTypeSpecializedVtable;
125 
126 typedef gboolean (*DBusGTypeSpecializedCollectionFixedAccessorFunc) (GType type, gpointer instance, gpointer *values, guint *len);
127 typedef void     (*DBusGTypeSpecializedCollectionIteratorFunc)      (GType type, gpointer instance, DBusGTypeSpecializedCollectionIterator iterator, gpointer user_data);
128 typedef void     (*DBusGTypeSpecializedCollectionAppendFunc)        (DBusGTypeSpecializedAppendContext *ctx, GValue *val);
129 typedef void     (*DBusGTypeSpecializedCollectionEndAppendFunc)     (DBusGTypeSpecializedAppendContext *ctx);
130 
131 typedef struct {
132   DBusGTypeSpecializedVtable                        base_vtable;
133   DBusGTypeSpecializedCollectionFixedAccessorFunc   fixed_accessor;
134   DBusGTypeSpecializedCollectionIteratorFunc        iterator;
135   DBusGTypeSpecializedCollectionAppendFunc          append_func;
136   DBusGTypeSpecializedCollectionEndAppendFunc       end_append_func;
137 } DBusGTypeSpecializedCollectionVtable;
138 
139 typedef void (*DBusGTypeSpecializedMapIteratorFunc) (GType type, gpointer instance, DBusGTypeSpecializedMapIterator iterator, gpointer user_data);
140 typedef void (*DBusGTypeSpecializedMapAppendFunc)   (DBusGTypeSpecializedAppendContext *ctx, GValue *key, GValue *val);
141 
142 typedef struct {
143   DBusGTypeSpecializedVtable                        base_vtable;
144   DBusGTypeSpecializedMapIteratorFunc               iterator;
145   DBusGTypeSpecializedMapAppendFunc                 append_func;
146 } DBusGTypeSpecializedMapVtable;
147 
148 typedef gboolean (*DBusGTypeSpecializedStructGetMember) (GType type, gpointer instance, guint member, GValue *ret_value);
149 typedef gboolean (*DBusGTypeSpecializedStructSetMember) (GType type, gpointer instance, guint member, const GValue *new_value);
150 
151 typedef struct {
152   DBusGTypeSpecializedVtable                        base_vtable;
153   DBusGTypeSpecializedStructGetMember               get_member;
154   DBusGTypeSpecializedStructSetMember               set_member;
155 } DBusGTypeSpecializedStructVtable;
156 
157 void           dbus_g_type_specialized_init           (void);
158 
159 void           dbus_g_type_register_collection        (const char                                   *name,
160 						       const DBusGTypeSpecializedCollectionVtable   *vtable,
161 						       guint                                         flags);
162 
163 void           dbus_g_type_register_map               (const char                                   *name,
164 						       const DBusGTypeSpecializedMapVtable          *vtable,
165 						       guint                                         flags);
166 
167 void           dbus_g_type_register_struct             (const char                                   *name,
168 						       const DBusGTypeSpecializedStructVtable        *vtable,
169 						       guint                                          flags);
170 
171 const DBusGTypeSpecializedMapVtable* dbus_g_type_map_peek_vtable (GType map_type);
172 const DBusGTypeSpecializedCollectionVtable* dbus_g_type_collection_peek_vtable (GType collection_type);
173 
174 const DBusGTypeSpecializedStructVtable* dbus_g_type_struct_peek_vtable (GType struct_type);
175 
176 GVariant *dbus_g_value_build_g_variant (const GValue *value);
177 
178 G_END_DECLS
179 
180 #endif
181