Merge remote branch 'gvdb/master'
[platform/upstream/glib.git] / docs / reference / gobject / glib-genmarshal.xml
1 <refentry id="glib-genmarshal" lang="en">
2
3 <refmeta>
4 <refentrytitle>glib-genmarshal</refentrytitle>
5 <manvolnum>1</manvolnum>
6 <refmiscinfo class="manual">User Commands</refmiscinfo>
7 </refmeta>
8
9 <refnamediv>
10 <refname>glib-genmarshal</refname>
11 <refpurpose>C code marshaller generation utility for GLib closures</refpurpose>
12 </refnamediv>
13
14 <refsynopsisdiv>
15 <cmdsynopsis>
16 <command>glib-genmarshal</command>
17 <arg choice="opt" rep="repeat">options</arg>
18 <arg choice="opt" rep="repeat">files</arg>
19 </cmdsynopsis>
20 </refsynopsisdiv>
21
22 <refsect1><title>Description</title>
23 <para><command>glib-genmarshal</command> is a small utility that generates C code 
24 marshallers for callback functions of the GClosure mechanism in the GObject 
25 sublibrary of GLib. The marshaller functions have a standard signature, 
26 they get passed in the invoking closure, an array of value structures holding
27 the callback function parameters and a value structure for the return value 
28 of the callback. The marshaller is then responsible to call the respective C 
29 code function of the closure with all the parameters on the stack and to 
30 collect its return value.
31 </para>
32 </refsect1>
33
34 <refsect1><title>Invocation</title>
35 <para><command>glib-genmarshal</command> takes a list of marshallers to generate as 
36 input. The marshaller list is either read from standard input or from files
37 passed as additional arguments on the command line.
38 </para>
39
40 <refsect2><title>Options</title>
41 <variablelist>
42
43 <varlistentry>
44 <term><option>--header</option></term>
45 <listitem><para>
46 Generate header file contents of the marshallers.
47 </para></listitem>
48 </varlistentry>
49
50 <varlistentry>
51 <term><option>--body</option></term>
52 <listitem><para>
53 Generate C code file contents of the marshallers.
54 </para></listitem>
55 </varlistentry>
56
57 <varlistentry>
58 <term><option>--prefix=string</option>, <option>--prefix string</option></term>
59 <listitem><para>
60 Specify marshaller prefix. The default prefix is <literal>`g_cclosure_marshal'</literal>.
61 </para></listitem>
62 </varlistentry>
63
64 <varlistentry>
65 <term><option>--skip-source</option></term>
66 <listitem><para>
67 Skip source location remarks in generated comments.
68 </para></listitem>
69 </varlistentry>
70
71 <varlistentry>
72 <term><option>--nostdinc</option></term>
73 <listitem><para>
74 Do not use the standard marshallers of the GObject library, and skip 
75 <filename>gmarshal.h</filename> include directive in generated header files.
76 </para></listitem>
77 </varlistentry>
78
79 <varlistentry>
80 <term><option>--g-fatal-warnings</option></term>
81 <listitem><para>
82 Make warnings fatal, that is, exit immediately once a warning occurs.
83 </para></listitem>
84 </varlistentry>
85
86 <varlistentry>
87 <term><option>-h</option>, <option>--help</option></term>
88 <listitem><para>
89 Print brief help and exit.
90 </para></listitem>
91 </varlistentry>
92
93 <varlistentry>
94 <term><option>-v</option>, <option>--version</option></term>
95 <listitem><para>
96 Print version and exit.
97 </para></listitem>
98 </varlistentry>
99
100 </variablelist>
101 </refsect2>
102
103 <refsect2><title>Marshaller list format</title>
104 <para>
105 The marshaller lists are processed line by line, a line can contain a
106 comment in the form of
107 <programlisting>
108 # this is a comment
109 </programlisting>
110 or a marshaller specification of the form
111 <programlisting>
112 <replaceable>RTYPE</replaceable>:<replaceable>PTYPE</replaceable>
113 <replaceable>RTYPE</replaceable>:<replaceable>PTYPE</replaceable>,<replaceable>PTYPE</replaceable>
114 <replaceable>RTYPE</replaceable>:<replaceable>PTYPE</replaceable>,<replaceable>PTYPE</replaceable>,<replaceable>PTYPE</replaceable>
115 </programlisting>
116 (up to 16 <replaceable>PTYPE</replaceable>s may be present).
117 </para>
118 <para>
119 The <replaceable>RTYPE</replaceable> part specifies the callback's return 
120 type and the <replaceable>PTYPE</replaceable>s right to the colon specify 
121 the callback's parameter list, except for the first and the last arguments 
122 which are always pointers.
123 </para>
124 </refsect2>
125 <refsect2><title>Parameter types</title>
126 <para>
127 Currently, the following types are supported:
128 <variablelist>
129 <varlistentry>
130 <term><replaceable>VOID</replaceable></term>
131 <listitem><para>
132 indicates no return type, or no extra parameters. 
133 If <replaceable>VOID</replaceable> is used as the parameter list, no 
134 additional parameters may be present.
135 </para></listitem>
136 </varlistentry>
137
138 <varlistentry>
139 <term><replaceable>BOOLEAN</replaceable></term>
140 <listitem><para>
141 for boolean types (gboolean)
142 </para></listitem>
143 </varlistentry>
144
145 <varlistentry>
146 <term><replaceable>CHAR</replaceable></term>
147 <listitem><para>
148 for signed char types (gchar)
149 </para></listitem>
150 </varlistentry>
151
152 <varlistentry>
153 <term><replaceable>UCHAR</replaceable></term>
154 <listitem><para>
155 for unsigned char types (guchar)
156 </para></listitem>
157 </varlistentry>
158
159 <varlistentry>
160 <term><replaceable>INT</replaceable></term>
161 <listitem><para>
162 for signed integer types (gint)
163 </para></listitem>
164 </varlistentry>
165
166 <varlistentry>
167 <term><replaceable>UINT</replaceable></term>
168 <listitem><para>
169 for unsigned integer types (guint)
170 </para></listitem>
171 </varlistentry>
172
173 <varlistentry>
174 <term><replaceable>LONG</replaceable></term>
175 <listitem><para>
176 for signed long integer types (glong)
177 </para></listitem>
178 </varlistentry>
179
180 <varlistentry>
181 <term><replaceable>ULONG</replaceable></term>
182 <listitem><para>
183 for unsigned long integer types (gulong)
184 </para></listitem>
185 </varlistentry>
186
187 <varlistentry>
188 <term><replaceable>INT64</replaceable></term>
189 <listitem><para>
190 for signed 64bit integer types (gint64)
191 </para></listitem>
192 </varlistentry>
193
194 <varlistentry>
195 <term><replaceable>UINT64</replaceable></term>
196 <listitem><para>
197 for unsigned 64bit integer types (guint64)
198 </para></listitem>
199 </varlistentry>
200
201 <varlistentry>
202 <term><replaceable>ENUM</replaceable></term>
203 <listitem><para>
204 for enumeration types (gint)
205 </para></listitem>
206 </varlistentry>
207
208 <varlistentry>
209 <term><replaceable>FLAGS</replaceable></term>
210 <listitem><para>
211 for flag enumeration types (guint)
212 </para></listitem>
213 </varlistentry>
214
215 <varlistentry>
216 <term><replaceable>FLOAT</replaceable></term>
217 <listitem><para>
218 for single-precision float types (gfloat)
219 </para></listitem>
220 </varlistentry>
221
222 <varlistentry>
223 <term><replaceable>DOUBLE</replaceable></term>
224 <listitem><para>
225 for double-precision float types (gdouble)
226 </para></listitem>
227 </varlistentry>
228
229 <varlistentry>
230 <term><replaceable>STRING</replaceable></term>
231 <listitem><para>
232 for string types (gchar*)
233 </para></listitem>
234 </varlistentry>
235
236 <varlistentry>
237 <term><replaceable>BOXED</replaceable></term>
238 <listitem><para>
239 for boxed (anonymous but reference counted) types (GBoxed*)
240 </para></listitem>
241 </varlistentry>
242
243 <varlistentry>
244 <term><replaceable>PARAM</replaceable></term>
245 <listitem><para>
246 for GParamSpec or derived types (GParamSpec*)
247 </para></listitem>
248 </varlistentry>
249
250 <varlistentry>
251 <term><replaceable>POINTER</replaceable></term>
252 <listitem><para>
253 for anonymous pointer types (gpointer)
254 </para></listitem>
255 </varlistentry>
256
257 <varlistentry>
258 <term><replaceable>OBJECT</replaceable></term>
259 <listitem><para>
260 for GObject or derived types (GObject*)
261 </para></listitem>
262 </varlistentry>
263
264 <varlistentry>
265 <term><replaceable>VARIANT</replaceable></term>
266 <listitem><para>
267 for GVariant types (GVariant*)
268 </para></listitem>
269 </varlistentry>
270
271 <varlistentry>
272 <term><replaceable>NONE</replaceable></term>
273 <listitem><para>
274 deprecated alias for <replaceable>VOID</replaceable>
275 </para></listitem>
276 </varlistentry>
277
278 <varlistentry>
279 <term><replaceable>BOOL</replaceable></term>
280 <listitem><para>
281 deprecated alias for <replaceable>BOOLEAN</replaceable>
282 </para></listitem>
283 </varlistentry>
284 </variablelist>
285 </para>
286 </refsect2>
287 </refsect1>
288 <refsect1><title>Example</title>
289 <para>
290 To generate marshallers for the following callback functions:
291 </para>
292 <programlisting>
293 void   foo (gpointer data1,
294             gpointer data2);
295 void   bar (gpointer data1,
296             gint     param1,
297             gpointer data2);
298 gfloat baz (gpointer data1,
299             gboolean param1,
300             guchar   param2,
301             gpointer data2);
302 </programlisting>
303 <para>
304 The marshaller list has to look like this:
305 </para>
306 <programlisting>
307 VOID:VOID
308 VOID:INT
309 FLOAT:BOOLEAN,UCHAR
310 </programlisting>
311 <para>
312 The generated marshallers have the arguments encoded in their function name. 
313 For this particular list, they are
314 </para>
315 <programlisting>
316 g_cclosure_marshal_VOID__VOID(),
317 g_cclosure_marshal_VOID__INT(), 
318 g_cclosure_marshal_FLOAT__BOOLEAN_UCHAR().
319 </programlisting>
320 <para>
321 They can be used directly for GClosures or be passed in as the 
322 GSignalCMarshaller c_marshaller; argument upon creation of signals:
323 </para>
324 <programlisting>
325 GClosure *cc_foo, *cc_bar, *cc_baz;
326
327 cc_foo = g_cclosure_new (NULL, foo, NULL);
328 g_closure_set_marshal (cc_foo, g_cclosure_marshal_VOID__VOID);
329 cc_bar = g_cclosure_new (NULL, bar, NULL);
330 g_closure_set_marshal (cc_bar, g_cclosure_marshal_VOID__INT);
331 cc_baz = g_cclosure_new (NULL, baz, NULL);
332 g_closure_set_marshal (cc_baz, g_cclosure_marshal_FLOAT__BOOLEAN_UCHAR);
333 </programlisting>
334 </refsect1>
335 <refsect1><title>See also</title>
336 <para>
337 <command>glib-mkenums</command>(1)
338 </para>
339 </refsect1>
340 <refsect1><title>Bugs</title>
341 <para>
342 None known yet.
343 </para>
344 </refsect1>
345 <refsect1><title>Author</title>
346 <para><command>glib-genmarshal</command> has been written by Tim Janik 
347 <email>timj@gtk.org</email>.
348 </para>
349 <para>
350 This manual page was provided by Tim Janik <email>timj@gtk.org</email>.
351 </para>
352 </refsect1>
353 </refentry>
354
355