2 * Copyright (c) 2005-2008 Zmanda Inc. All Rights Reserved.
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 2.1 as
6 * published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11 * License for more details.
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17 * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
18 * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
21 #ifndef AMANDA_AMGLUE_H
22 #define AMANDA_AMGLUE_H
28 #include <glib-object.h>
30 /* These defines are missing from older glibs, so we add them here */
32 #define G_MAXINT8 (127)
36 #define G_MININT8 (-127-1)
40 #define G_MAXUINT8 (255)
44 #define G_MAXINT16 (32767)
48 #define G_MININT16 (-32767-1)
52 #define G_MAXUINT16 (65535)
56 #define G_MAXINT32 (2147483647)
60 #define G_MININT32 (-2147483647-1)
64 #define G_MAXUINT32 (4294967295U)
68 * prototypes for ghashtable.c
71 /* Turn a GLib hash table (mapping strings to strings) into a reference
72 * to a Perl hash table.
74 * @param hash: GLib hash table
75 * @returns: Perl hashref
77 SV *g_hash_table_to_hashref(GHashTable *hash);
79 /* Turn a GLib hash table (mapping strings to GSList of strings) into a reference
80 * to a Perl hash table.
82 * @param hash: GLib hash table
83 * @returns: Perl hashref
85 SV *g_hash_table_to_hashref_gslist(GHashTable *hash);
87 /* Turn a GLib hash table (mapping strings to property_t) into a reference
88 * to a Perl hash table.
90 * @param hash: GLib hash table
91 * @returns: Perl hashref
93 SV *g_hash_table_to_hashref_property(GHashTable *hash);
96 * prototypes for bigint.c
100 * These functions handle conversion of integers to and from Perl-compatible
101 * values. Most perls do not natively support 64-bit integers, so these functions
102 * interface with the Math::BigInt module to support those integers. The functions
103 * also handle conversions from floating-point to integer values, with silent fraction
104 * truncation, as perl automatically promotes integers to doubles on overflow.
107 /* Convert an (unsigned) integer to a Perl SV. These will always produce a
108 * Math::BigInt object. Any failure is fatal. *All* C-to-Perl integer conversions
109 * must use these functions.
111 * @param v: value to convert
112 * @returns: pointer to a new SV (refcount=1)
114 SV *amglue_newSVi64(gint64 v);
115 SV *amglue_newSVu64(guint64 v);
117 /* Convert a Perl SV to an integer of the specified size. These functions should
118 * be used for *all* Perl-to-C integer conversions, since the Perl value may be a
119 * Math::BigInt object. All of these functions will call croak() on an overflow
120 * condition, rather than silently truncate.
122 * @param sv: perl value to convert
123 * @returns: value of the given type
125 gint64 amglue_SvI64(SV *sv);
126 guint64 amglue_SvU64(SV *sv);
127 gint32 amglue_SvI32(SV *sv);
128 guint32 amglue_SvU32(SV *sv);
129 gint16 amglue_SvI16(SV *sv);
130 guint16 amglue_SvU16(SV *sv);
131 gint8 amglue_SvI8(SV *sv);
132 guint8 amglue_SvU8(SV *sv);
135 * prototypes for source.c
138 typedef enum amglue_Source_state {
140 AMGLUE_SOURCE_ATTACHED,
141 AMGLUE_SOURCE_DESTROYED
142 } amglue_Source_state;
144 /* There is *one* amglue_Source object for each GSource; this
145 * allows us to attach amglue-related information to the
146 * GSource. See amglue/source.c for more detail. */
148 typedef struct amglue_Source {
150 GSourceFunc callback;
152 amglue_Source_state state;
156 /* Get the amglue_Source object associated with this GSource, creating a
157 * new one if necessary, and increment its refcount.
159 * The 'callback' parameter should be a C function with the
160 * appropriate signature for this GSource. The callback will
161 * be given the amglue_Source as its 'data' argument, and should
162 * invoke its callback_sv as a Perl sub with the appropriate
163 * parameters. Simple GSources can use amglue_source_callback_simple,
166 * This amglue_Source object can be returned directly to perl via a
167 * SWIG binding; it will be bound as an Amanda::MainLoop::Source
168 * object, and its memory management will be handled correctly.
170 * @param gsrc: the GSource object to wrap
171 * @param callback: function to trigger a perl callback
172 * @returns: an amglue_Source with appropriate refcount
174 amglue_Source *amglue_source_get(GSource *gsrc, GSourceFunc callback);
176 /* Create a new amglue_Source object for this GSource. Use this when
177 * the GSource was just created and does not yet have a corresponding
180 * @param gsrc: the GSource object to wrap
181 * @param callback: function to trigger a perl callback
182 * @returns: an amglue_Source with appropriate refcount
184 amglue_Source *amglue_source_new(GSource *gsrc, GSourceFunc callback);
186 /* Increment the refcount on an amglue_Source */
187 #define amglue_source_ref(aS) aS->refcount++
189 /* Unref an amglue_Source object, freeing it if its refcount reaches
191 #define amglue_source_unref(aS) if (!--(aS)->refcount) amglue_source_free((aS))
192 void amglue_source_free(amglue_Source *);
194 #endif /* AMANDA_AMGLUE_H */