~0k-hans-f8/libgtk2-appindicator-perl/trunk

« back to all changes in this revision

Viewing changes to gperl.h

  • Committer: Hans Oesterholt
  • Date: 2012-07-19 23:50:01 UTC
  • Revision ID: debian@oesterholt.net-20120719235001-021nfwd89dk8rtjp
initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003-2005 by the gtk2-perl team (see the file AUTHORS for
 
3
 * the full list)
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or modify it
 
6
 * under the terms of the GNU Library General Public License as published by
 
7
 * the Free Software Foundation; either version 2.1 of the License, or (at your
 
8
 * option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful, but WITHOUT
 
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
 
13
 * License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Library General Public License
 
16
 * along with this library; if not, write to the Free Software Foundation,
 
17
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307  USA.
 
18
 *
 
19
 * $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/gperl.h,v 1.41 2005/04/26 22:56:56 ebassi Exp $
 
20
 */
 
21
 
 
22
#ifndef _GPERL_H_
 
23
#define _GPERL_H_
 
24
 
 
25
#include "EXTERN.h"
 
26
#include "perl.h"
 
27
#include "XSUB.h"
 
28
 
 
29
#ifdef WIN32
 
30
  /* perl and glib disagree on a few macros... let the wookie win. */
 
31
# undef pipe
 
32
# undef malloc
 
33
# undef realloc
 
34
# undef free
 
35
#endif
 
36
 
 
37
#include <glib-object.h>
 
38
 
 
39
/*
 
40
 * miscellaneous
 
41
 */
 
42
 
 
43
/* never use this function directly.  use GPERL_CALL_BOOT. */
 
44
void _gperl_call_XS (pTHX_ void (*subaddr) (pTHX_ CV *), CV * cv, SV ** mark);
 
45
 
 
46
/*
 
47
 * call the boot code of a module by symbol rather than by name.
 
48
 *
 
49
 * in a perl extension which uses several xs files but only one pm, you
 
50
 * need to bootstrap the other xs files in order to get their functions
 
51
 * exported to perl.  if the file has MODULE = Foo::Bar, the boot symbol
 
52
 * would be boot_Foo__Bar.
 
53
 */
 
54
#define GPERL_CALL_BOOT(name)   \
 
55
        {                                               \
 
56
                extern XS(name);                        \
 
57
                _gperl_call_XS (aTHX_ name, cv, mark);  \
 
58
        }
 
59
 
 
60
gpointer gperl_alloc_temp (int nbytes);
 
61
gchar *gperl_filename_from_sv (SV *sv);
 
62
SV *gperl_sv_from_filename (const gchar *filename);
 
63
 
 
64
gboolean gperl_str_eq (const char * a, const char * b);
 
65
guint    gperl_str_hash (gconstpointer key);
 
66
 
 
67
typedef struct {
 
68
  int argc;
 
69
  char **argv;
 
70
  char **shadow;
 
71
} GPerlArgv;
 
72
 
 
73
GPerlArgv * gperl_argv_new ();
 
74
void gperl_argv_update (GPerlArgv *pargv);
 
75
void gperl_argv_free (GPerlArgv *pargv);
 
76
 
 
77
char * gperl_format_variable_for_output (SV * sv);
 
78
 
 
79
/* internal trickery */
 
80
gpointer gperl_type_class (GType type);
 
81
/*
 
82
 * enums and flags
 
83
 */
 
84
gboolean gperl_try_convert_enum (GType type, SV * sv, gint * val);
 
85
gint gperl_convert_enum (GType type, SV * val);
 
86
SV * gperl_convert_back_enum_pass_unknown (GType type, gint val);
 
87
SV * gperl_convert_back_enum (GType type, gint val);
 
88
 
 
89
gboolean gperl_try_convert_flag (GType type, const char * val_p, gint * val);
 
90
gint gperl_convert_flag_one (GType type, const char * val_p);
 
91
gint gperl_convert_flags (GType type, SV * val);
 
92
SV * gperl_convert_back_flags (GType type, gint val);
 
93
 
 
94
/* register a fundamental type (enums, flags...) */
 
95
 
 
96
typedef struct _GPerlValueWrapperClass GPerlValueWrapperClass;
 
97
 
 
98
typedef SV*  (*GPerlValueWrapFunc)   (const GValue * value);
 
99
typedef void (*GPerlValueUnwrapFunc) (GValue       * value,
 
100
                                      SV           * sv);
 
101
 
 
102
struct _GPerlValueWrapperClass {
 
103
        GPerlValueWrapFunc   wrap;
 
104
        GPerlValueUnwrapFunc unwrap;
 
105
};
 
106
 
 
107
void gperl_register_fundamental (GType gtype, const char * package);
 
108
void gperl_register_fundamental_full (GType gtype, const char * package, GPerlValueWrapperClass * wrapper_class);
 
109
 
 
110
GType gperl_fundamental_type_from_package (const char * package);
 
111
const char * gperl_fundamental_package_from_type (GType gtype);
 
112
GPerlValueWrapperClass * gperl_fundamental_wrapper_class_from_type (GType gtype);
 
113
 
 
114
/*
 
115
 * GErrors as exception objects
 
116
 */
 
117
/* it is rare that you should ever want or need these two functions. */
 
118
SV * gperl_sv_from_gerror (GError * error);
 
119
void gperl_gerror_from_sv (SV * sv, GError ** error);
 
120
 
 
121
void gperl_register_error_domain (GQuark domain,
 
122
                                  GType error_enum,
 
123
                                  const char * package);
 
124
 
 
125
void gperl_croak_gerror (const char * ignored, GError * err);
 
126
 
 
127
/*
 
128
 * inheritance management
 
129
 */
 
130
/* push @{$parent_package}::ISA, $child_package */
 
131
void gperl_set_isa (const char * child_package, const char * parent_package);
 
132
/* unshift @{$parent_package}::ISA, $child_package */
 
133
void gperl_prepend_isa (const char * child_package, const char * parent_package);
 
134
 
 
135
/* these work regardless of what the actual type is (GBoxed, GObject, GEnum,
 
136
 * or GFlags).  in general it's safer to use the most specific one, but this
 
137
 * is handy when you don't care. */
 
138
GType gperl_type_from_package (const char * package);
 
139
const char * gperl_package_from_type (GType type);
 
140
 
 
141
 
 
142
/*
 
143
 * we need a GBoxed wrapper for a generic SV, so we can store SVs
 
144
 * in GObjects reliably.
 
145
 */
 
146
#define GPERL_TYPE_SV   (gperl_sv_get_type ())
 
147
GType gperl_sv_get_type (void) G_GNUC_CONST;
 
148
SV * gperl_sv_copy (SV * sv);
 
149
void gperl_sv_free (SV * sv);
 
150
 
 
151
 
 
152
/*
 
153
 * clean function wrappers for treating gchar* as UTF8 strings, in the
 
154
 * same idiom as the rest of the cast macros.  these are wrapped up
 
155
 * as functions because comma expressions in macros get kinda tricky.
 
156
 */
 
157
/*const*/ gchar * SvGChar (SV * sv);
 
158
SV * newSVGChar (const gchar * str);
 
159
 
 
160
 
 
161
 
 
162
/*
 
163
 * GValues
 
164
 */
 
165
gboolean gperl_value_from_sv (GValue * value, SV * sv);
 
166
SV * gperl_sv_from_value (const GValue * value);
 
167
 
 
168
/*
 
169
 * GBoxed
 
170
 */
 
171
 
 
172
typedef struct _GPerlBoxedWrapperClass GPerlBoxedWrapperClass;
 
173
 
 
174
typedef SV*      (*GPerlBoxedWrapFunc)    (GType        gtype,
 
175
                                           const char * package,
 
176
                                           gpointer     boxed,
 
177
                                           gboolean     own);
 
178
typedef gpointer (*GPerlBoxedUnwrapFunc)  (GType        gtype,
 
179
                                           const char * package,
 
180
                                           SV         * sv);
 
181
typedef void     (*GPerlBoxedDestroyFunc) (SV         * sv);
 
182
 
 
183
struct _GPerlBoxedWrapperClass {
 
184
        GPerlBoxedWrapFunc    wrap;
 
185
        GPerlBoxedUnwrapFunc  unwrap;
 
186
        GPerlBoxedDestroyFunc destroy;
 
187
};
 
188
 
 
189
GPerlBoxedWrapperClass * gperl_default_boxed_wrapper_class (void);
 
190
 
 
191
void gperl_register_boxed (GType gtype,
 
192
                           const char * package,
 
193
                           GPerlBoxedWrapperClass * wrapper_class);
 
194
 
 
195
SV * gperl_new_boxed (gpointer boxed, GType gtype, gboolean own);
 
196
SV * gperl_new_boxed_copy (gpointer boxed, GType gtype);
 
197
gpointer gperl_get_boxed_check (SV * sv, GType gtype);
 
198
 
 
199
 
 
200
GType gperl_boxed_type_from_package (const char * package);
 
201
const char * gperl_boxed_package_from_type (GType type);
 
202
 
 
203
 
 
204
/*
 
205
 * GObject
 
206
 */
 
207
void gperl_register_object (GType gtype, const char * package);
 
208
 
 
209
typedef void (*GPerlObjectSinkFunc) (GObject *);
 
210
void gperl_register_sink_func (GType               gtype,
 
211
                               GPerlObjectSinkFunc func);
 
212
 
 
213
void gperl_object_set_no_warn_unreg_subclass (GType gtype, gboolean nowarn);
 
214
 
 
215
const char * gperl_object_package_from_type (GType gtype);
 
216
HV * gperl_object_stash_from_type (GType gtype);
 
217
GType gperl_object_type_from_package (const char * package);
 
218
 
 
219
SV * gperl_new_object (GObject * object, gboolean own);
 
220
 
 
221
GObject * gperl_get_object (SV * sv);
 
222
GObject * gperl_get_object_check (SV * sv, GType gtype);
 
223
 
 
224
SV * gperl_object_check_type (SV * sv, GType gtype);
 
225
 
 
226
/* typedefs and macros for use with the typemap */
 
227
typedef gchar gchar_length;
 
228
typedef gchar gchar_own;
 
229
typedef gchar gchar_ornull;
 
230
typedef char char_ornull;
 
231
typedef char char_own;
 
232
typedef GObject GObject_ornull;
 
233
typedef GObject GObject_noinc;
 
234
typedef gchar *GPerlFilename;
 
235
typedef const gchar *GPerlFilename_const;
 
236
typedef gchar *GPerlFilename_own;
 
237
typedef GPerlFilename GPerlFilename_ornull;
 
238
 
 
239
#define newSVGObject(obj)       (gperl_new_object ((obj), FALSE))
 
240
#define newSVGObject_noinc(obj) (gperl_new_object ((obj), TRUE))
 
241
#define SvGObject(sv)           (gperl_get_object (sv))
 
242
#define SvGObject_ornull(sv)    ((sv && SvOK (sv)) ? SvGObject (sv) : NULL)
 
243
 
 
244
 
 
245
/*
 
246
 * GSignal.xs
 
247
 */
 
248
SV * newSVGSignalFlags (GSignalFlags flags);
 
249
GSignalFlags SvGSignalFlags (SV * sv);
 
250
SV * newSVGSignalInvocationHint (GSignalInvocationHint * ihint);
 
251
SV * newSVGSignalQuery (GSignalQuery * query);
 
252
 
 
253
void gperl_signal_set_marshaller_for (GType             instance_type,
 
254
                                      char            * detailed_signal,
 
255
                                      GClosureMarshal   marshaller);
 
256
gulong gperl_signal_connect          (SV              * instance,
 
257
                                      char            * detailed_signal,
 
258
                                      SV              * callback,
 
259
                                      SV              * data,
 
260
                                      GConnectFlags     flags);
 
261
 
 
262
 
 
263
/*
 
264
 * GClosure
 
265
 */
 
266
typedef struct _GPerlClosure GPerlClosure;
 
267
struct _GPerlClosure {
 
268
        GClosure closure;
 
269
        SV * callback;
 
270
        SV * data; /* callback data */
 
271
        gboolean swap; /* TRUE if target and data are to be swapped */
 
272
        int id;
 
273
};
 
274
 
 
275
/* evaluates to true if the instance and data are to be swapped on invocation */
 
276
#define GPERL_CLOSURE_SWAP_DATA(gpc)    ((gpc)->swap)
 
277
 
 
278
/* this is the one you want. */
 
279
GClosure * gperl_closure_new                 (SV              * callback, 
 
280
                                              SV              * data, 
 
281
                                              gboolean          swap);
 
282
/* very scary, use only if you really know what you are doing */
 
283
GClosure * gperl_closure_new_with_marshaller (SV              * callback, 
 
284
                                              SV              * data, 
 
285
                                              gboolean          swap,
 
286
                                              GClosureMarshal   marshaller);
 
287
 
 
288
/*
 
289
 * GPerlCallback
 
290
 */
 
291
 
 
292
typedef struct _GPerlCallback GPerlCallback;
 
293
struct _GPerlCallback {
 
294
        gint    n_params;
 
295
        GType * param_types;
 
296
        GType   return_type;
 
297
        SV    * func;
 
298
        SV    * data;
 
299
        void  * priv;
 
300
};
 
301
 
 
302
GPerlCallback * gperl_callback_new     (SV            * func,
 
303
                                        SV            * data,
 
304
                                        gint            n_params,
 
305
                                        GType           param_types[],
 
306
                                        GType           return_type);
 
307
 
 
308
void            gperl_callback_destroy (GPerlCallback * callback);
 
309
 
 
310
void            gperl_callback_invoke  (GPerlCallback * callback,
 
311
                                        GValue        * return_value,
 
312
                                        ...);
 
313
 
 
314
/*
 
315
 * exception handling
 
316
 */
 
317
 
 
318
int  gperl_install_exception_handler (GClosure * closure);
 
319
void gperl_remove_exception_handler  (guint tag);
 
320
void gperl_run_exception_handlers    (void);
 
321
 
 
322
/*
 
323
 * to be used by extensions...
 
324
 */
 
325
gint gperl_handle_logs_for (const gchar * log_domain);
 
326
 
 
327
/*
 
328
 * gparamspec.h / GParamSpec.xs
 
329
 */
 
330
SV * newSVGParamSpec (GParamSpec * pspec);
 
331
GParamSpec * SvGParamSpec (SV * sv);
 
332
SV * newSVGParamFlags (GParamFlags flags);
 
333
GParamFlags SvGParamFlags (SV * sv);
 
334
 
 
335
/*
 
336
 * gkeyfile.h / GKeyFile.xs
 
337
 */
 
338
#if GLIB_CHECK_VERSION (2, 6, 0)
 
339
SV * newSVGKeyFile (GKeyFile * key_file);
 
340
GKeyFile * SvGKeyFile (SV * sv);
 
341
SV * newSVGKeyFileFlags (GKeyFileFlags flags);
 
342
GKeyFileFlags SvGKeyFileFlags (SV * sv);
 
343
#endif /* GLIB_CHECK_VERSION (2, 6, 0) */
 
344
 
 
345
const char * gperl_param_spec_package_from_type (GType gtype);
 
346
 
 
347
/*
 
348
 * helpful debugging stuff
 
349
 */
 
350
#define GPERL_OBJECT_VITALS(o) \
 
351
        ((o)                                                    \
 
352
          ? form ("%s(%p)[%d]", G_OBJECT_TYPE_NAME (o), (o),    \
 
353
                  G_OBJECT (o)->ref_count)                      \
 
354
          : "NULL")
 
355
#define GPERL_WRAPPER_VITALS(w) \
 
356
        ((SvTRUE (w))                                   \
 
357
          ? ((SvROK (w))                                \
 
358
            ? form ("SvRV(%p)->%s(%p)[%d]", (w),        \
 
359
                     sv_reftype (SvRV (w), TRUE),       \
 
360
                     SvRV (w), SvREFCNT (SvRV (w)))     \
 
361
             : "[not a reference!]")                    \
 
362
          : "undef")
 
363
 
 
364
#endif /* _GPERL_H_ */