home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / perl5 / Glib / Install / gperl.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-01-07  |  12.2 KB  |  400 lines

  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.54 2008/01/07 19:17:08 kaffeetisch 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. gboolean gperl_sv_is_defined (SV *sv);
  80.  
  81. #define gperl_sv_is_array_ref(sv) \
  82.     (gperl_sv_is_defined (sv) && SvROK (sv) && SvTYPE (SvRV(sv)) == SVt_PVAV)
  83. #define gperl_sv_is_code_ref(sv) \
  84.     (gperl_sv_is_defined (sv) && SvROK (sv) && SvTYPE (SvRV(sv)) == SVt_PVCV)
  85. #define gperl_sv_is_hash_ref(sv) \
  86.     (gperl_sv_is_defined (sv) && SvROK (sv) && SvTYPE (SvRV(sv)) == SVt_PVHV)
  87.  
  88. /* internal trickery */
  89. gpointer gperl_type_class (GType type);
  90. /*
  91.  * enums and flags
  92.  */
  93. gboolean gperl_try_convert_enum (GType type, SV * sv, gint * val);
  94. gint gperl_convert_enum (GType type, SV * val);
  95. SV * gperl_convert_back_enum_pass_unknown (GType type, gint val);
  96. SV * gperl_convert_back_enum (GType type, gint val);
  97.  
  98. gboolean gperl_try_convert_flag (GType type, const char * val_p, gint * val);
  99. gint gperl_convert_flag_one (GType type, const char * val_p);
  100. gint gperl_convert_flags (GType type, SV * val);
  101. SV * gperl_convert_back_flags (GType type, gint val);
  102.  
  103. /* register a fundamental type (enums, flags...) */
  104.  
  105. typedef struct _GPerlValueWrapperClass GPerlValueWrapperClass;
  106.  
  107. typedef SV*  (*GPerlValueWrapFunc)   (const GValue * value);
  108. typedef void (*GPerlValueUnwrapFunc) (GValue       * value,
  109.                                       SV           * sv);
  110.  
  111. struct _GPerlValueWrapperClass {
  112.     GPerlValueWrapFunc   wrap;
  113.     GPerlValueUnwrapFunc unwrap;
  114. };
  115.  
  116. void gperl_register_fundamental (GType gtype, const char * package);
  117. void gperl_register_fundamental_full (GType gtype, const char * package, GPerlValueWrapperClass * wrapper_class);
  118.  
  119. GType gperl_fundamental_type_from_package (const char * package);
  120. const char * gperl_fundamental_package_from_type (GType gtype);
  121. GPerlValueWrapperClass * gperl_fundamental_wrapper_class_from_type (GType gtype);
  122.  
  123. /*
  124.  * GErrors as exception objects
  125.  */
  126. /* it is rare that you should ever want or need these two functions. */
  127. SV * gperl_sv_from_gerror (GError * error);
  128. void gperl_gerror_from_sv (SV * sv, GError ** error);
  129.  
  130. void gperl_register_error_domain (GQuark domain,
  131.                                   GType error_enum,
  132.                                   const char * package);
  133.  
  134. void gperl_croak_gerror (const char * ignored, GError * err);
  135.  
  136. /*
  137.  * inheritance management
  138.  */
  139. /* push @{$parent_package}::ISA, $child_package */
  140. void gperl_set_isa (const char * child_package, const char * parent_package);
  141. /* unshift @{$parent_package}::ISA, $child_package */
  142. void gperl_prepend_isa (const char * child_package, const char * parent_package);
  143.  
  144. /* these work regardless of what the actual type is (GBoxed, GObject, GEnum,
  145.  * or GFlags).  in general it's safer to use the most specific one, but this
  146.  * is handy when you don't care. */
  147. GType gperl_type_from_package (const char * package);
  148. const char * gperl_package_from_type (GType type);
  149.  
  150.  
  151. /*
  152.  * we need a GBoxed wrapper for a generic SV, so we can store SVs
  153.  * in GObjects reliably.
  154.  */
  155. #define GPERL_TYPE_SV    (gperl_sv_get_type ())
  156. GType gperl_sv_get_type (void) G_GNUC_CONST;
  157. SV * gperl_sv_copy (SV * sv);
  158. void gperl_sv_free (SV * sv);
  159.  
  160.  
  161. /*
  162.  * clean function wrappers for treating gchar* as UTF8 strings, in the
  163.  * same idiom as the rest of the cast macros.  these are wrapped up
  164.  * as functions because comma expressions in macros get kinda tricky.
  165.  */
  166. /*const*/ gchar * SvGChar (SV * sv);
  167. SV * newSVGChar (const gchar * str);
  168.  
  169.  
  170. /*
  171.  * 64 bit integer converters
  172.  */
  173. gint64 SvGInt64 (SV *sv);
  174. SV * newSVGInt64 (gint64 value);
  175. guint64 SvGUInt64 (SV *sv);
  176. SV * newSVGUInt64 (guint64 value);
  177.  
  178.  
  179. /*
  180.  * GValues
  181.  */
  182. gboolean gperl_value_from_sv (GValue * value, SV * sv);
  183. SV * gperl_sv_from_value (const GValue * value);
  184.  
  185. /*
  186.  * GBoxed
  187.  */
  188.  
  189. typedef struct _GPerlBoxedWrapperClass GPerlBoxedWrapperClass;
  190.  
  191. typedef SV*      (*GPerlBoxedWrapFunc)    (GType        gtype,
  192.                        const char * package,
  193.                        gpointer     boxed,
  194.                        gboolean     own);
  195. typedef gpointer (*GPerlBoxedUnwrapFunc)  (GType        gtype,
  196.                        const char * package,
  197.                        SV         * sv);
  198. typedef void     (*GPerlBoxedDestroyFunc) (SV         * sv);
  199.  
  200. struct _GPerlBoxedWrapperClass {
  201.     GPerlBoxedWrapFunc    wrap;
  202.     GPerlBoxedUnwrapFunc  unwrap;
  203.     GPerlBoxedDestroyFunc destroy;
  204. };
  205.  
  206. GPerlBoxedWrapperClass * gperl_default_boxed_wrapper_class (void);
  207.  
  208. void gperl_register_boxed (GType gtype,
  209.                const char * package,
  210.                GPerlBoxedWrapperClass * wrapper_class);
  211.  
  212. SV * gperl_new_boxed (gpointer boxed, GType gtype, gboolean own);
  213. SV * gperl_new_boxed_copy (gpointer boxed, GType gtype);
  214. gpointer gperl_get_boxed_check (SV * sv, GType gtype);
  215.  
  216.  
  217. GType gperl_boxed_type_from_package (const char * package);
  218. const char * gperl_boxed_package_from_type (GType type);
  219.  
  220.  
  221. /*
  222.  * GObject
  223.  */
  224. void gperl_register_object (GType gtype, const char * package);
  225.  
  226. typedef void (*GPerlObjectSinkFunc) (GObject *);
  227. void gperl_register_sink_func (GType               gtype,
  228.                                GPerlObjectSinkFunc func);
  229.  
  230. void gperl_object_set_no_warn_unreg_subclass (GType gtype, gboolean nowarn);
  231.  
  232. const char * gperl_object_package_from_type (GType gtype);
  233. HV * gperl_object_stash_from_type (GType gtype);
  234. GType gperl_object_type_from_package (const char * package);
  235.  
  236. SV * gperl_new_object (GObject * object, gboolean own);
  237.  
  238. GObject * gperl_get_object (SV * sv);
  239. GObject * gperl_get_object_check (SV * sv, GType gtype);
  240.  
  241. SV * gperl_object_check_type (SV * sv, GType gtype);
  242.  
  243. /* typedefs and macros for use with the typemap */
  244. typedef gchar gchar_length;
  245. typedef gchar gchar_own;
  246. typedef gchar gchar_ornull;
  247. typedef gchar gchar_own_ornull;
  248. typedef char char_ornull;
  249. typedef char char_own;
  250. typedef char char_own_ornull;
  251. typedef GObject GObject_ornull;
  252. typedef GObject GObject_noinc;
  253. typedef gchar *GPerlFilename;
  254. typedef const gchar *GPerlFilename_const;
  255. typedef gchar *GPerlFilename_own;
  256. typedef GPerlFilename GPerlFilename_ornull;
  257.  
  258. #define newSVGObject(obj)    (gperl_new_object ((obj), FALSE))
  259. #define newSVGObject_noinc(obj)    (gperl_new_object ((obj), TRUE))
  260. #define SvGObject(sv)        (gperl_get_object_check (sv, G_TYPE_OBJECT))
  261. #define SvGObject_ornull(sv)    (gperl_sv_is_defined (sv) ? SvGObject (sv) : NULL)
  262.  
  263.  
  264. /*
  265.  * GSignal.xs
  266.  */
  267. SV * newSVGSignalFlags (GSignalFlags flags);
  268. GSignalFlags SvGSignalFlags (SV * sv);
  269. SV * newSVGSignalInvocationHint (GSignalInvocationHint * ihint);
  270. SV * newSVGSignalQuery (GSignalQuery * query);
  271.  
  272. void gperl_signal_set_marshaller_for (GType             instance_type,
  273.                                       char            * detailed_signal,
  274.                                       GClosureMarshal   marshaller);
  275. gulong gperl_signal_connect          (SV              * instance,
  276.                                       char            * detailed_signal,
  277.                                       SV              * callback,
  278.                                       SV              * data,
  279.                                       GConnectFlags     flags);
  280.  
  281.  
  282. /*
  283.  * GClosure
  284.  */
  285. typedef struct _GPerlClosure GPerlClosure;
  286. struct _GPerlClosure {
  287.     GClosure closure;
  288.     SV * callback;
  289.     SV * data; /* callback data */
  290.     gboolean swap; /* TRUE if target and data are to be swapped */
  291.     int id;
  292. };
  293.  
  294. /* evaluates to true if the instance and data are to be swapped on invocation */
  295. #define GPERL_CLOSURE_SWAP_DATA(gpc)    ((gpc)->swap)
  296.  
  297. /* this is the one you want. */
  298. GClosure * gperl_closure_new                 (SV              * callback, 
  299.                                               SV              * data, 
  300.                                               gboolean          swap);
  301. /* very scary, use only if you really know what you are doing */
  302. GClosure * gperl_closure_new_with_marshaller (SV              * callback, 
  303.                                               SV              * data, 
  304.                                               gboolean          swap,
  305.                                               GClosureMarshal   marshaller);
  306.  
  307. /*
  308.  * GPerlCallback
  309.  */
  310.  
  311. typedef struct _GPerlCallback GPerlCallback;
  312. struct _GPerlCallback {
  313.     gint    n_params;
  314.     GType * param_types;
  315.     GType   return_type;
  316.     SV    * func;
  317.     SV    * data;
  318.     void  * priv;
  319. };
  320.  
  321. GPerlCallback * gperl_callback_new     (SV            * func,
  322.                                         SV            * data,
  323.                                         gint            n_params,
  324.                                         GType           param_types[],
  325.                     GType           return_type);
  326.  
  327. void            gperl_callback_destroy (GPerlCallback * callback);
  328.  
  329. void            gperl_callback_invoke  (GPerlCallback * callback,
  330.                                         GValue        * return_value,
  331.                                         ...);
  332.  
  333. /*
  334.  * exception handling
  335.  */
  336.  
  337. int  gperl_install_exception_handler (GClosure * closure);
  338. void gperl_remove_exception_handler  (guint tag);
  339. void gperl_run_exception_handlers    (void);
  340.  
  341. /*
  342.  * to be used by extensions...
  343.  */
  344. gint gperl_handle_logs_for (const gchar * log_domain);
  345.  
  346. /*
  347.  * gparamspec.h / GParamSpec.xs
  348.  */
  349. SV * newSVGParamSpec (GParamSpec * pspec);
  350. GParamSpec * SvGParamSpec (SV * sv);
  351. SV * newSVGParamFlags (GParamFlags flags);
  352. GParamFlags SvGParamFlags (SV * sv);
  353.  
  354. /*
  355.  * gkeyfile.h / GKeyFile.xs
  356.  */
  357. #if GLIB_CHECK_VERSION (2, 6, 0)
  358. SV * newSVGKeyFile (GKeyFile * key_file);
  359. GKeyFile * SvGKeyFile (SV * sv);
  360. SV * newSVGKeyFileFlags (GKeyFileFlags flags);
  361. GKeyFileFlags SvGKeyFileFlags (SV * sv);
  362. #endif /* GLIB_CHECK_VERSION (2, 6, 0) */
  363.  
  364. /*
  365.  * gbookmarkfile.h / GBookmarkFile.xs
  366.  */
  367. #if GLIB_CHECK_VERSION (2, 12, 0)
  368. SV * newSVGBookmarkFile (GBookmarkFile * bookmark_file);
  369. GBookmarkFile * SvGBookmarkFile (SV * sv);
  370. #endif /* GLIB_CHECK_VERSION (2, 12, 0) */
  371.  
  372. const char * gperl_param_spec_package_from_type (GType gtype);
  373.  
  374. /*
  375.  * gutils.h / GUtils.xs
  376.  */
  377. #if GLIB_CHECK_VERSION (2, 14, 0)
  378. GUserDirectory SvGUserDirectory (SV *sv);
  379. SV * newSVGUserDirectory (GUserDirectory dir);
  380. #endif
  381.  
  382. /*
  383.  * helpful debugging stuff
  384.  */
  385. #define GPERL_OBJECT_VITALS(o) \
  386.     ((o)                            \
  387.       ? form ("%s(%p)[%d]", G_OBJECT_TYPE_NAME (o), (o),    \
  388.           G_OBJECT (o)->ref_count)            \
  389.       : "NULL")
  390. #define GPERL_WRAPPER_VITALS(w)    \
  391.     ((SvTRUE (w))                    \
  392.       ? ((SvROK (w))                \
  393.         ? form ("SvRV(%p)->%s(%p)[%d]", (w),    \
  394.              sv_reftype (SvRV (w), TRUE),    \
  395.              SvRV (w), SvREFCNT (SvRV (w)))    \
  396.          : "[not a reference!]")            \
  397.       : "undef")
  398.  
  399. #endif /* _GPERL_H_ */
  400.