1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
/*
* Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
* Copyright (c) 2013-2016 Carbonite, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact information: Carbonite Inc., 756 N Pastoria Ave
* Sunnyvale, CA 94085, or: http://www.zmanda.com
*/
#ifndef AMANDA_AMGLUE_H
#define AMANDA_AMGLUE_H
#include "../config/config.h"
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <glib.h>
#include <glib-object.h>
/* These defines are missing from older glibs, so we add them here */
#ifndef G_MAXINT8
#define G_MAXINT8 (127)
#endif
#ifndef G_MININT8
#define G_MININT8 (-127-1)
#endif
#ifndef G_MAXUINT8
#define G_MAXUINT8 (255)
#endif
#ifndef G_MAXINT16
#define G_MAXINT16 (32767)
#endif
#ifndef G_MININT16
#define G_MININT16 (-32767-1)
#endif
#ifndef G_MAXUINT16
#define G_MAXUINT16 (65535)
#endif
#ifndef G_MAXINT32
#define G_MAXINT32 (2147483647)
#endif
#ifndef G_MININT32
#define G_MININT32 (-2147483647-1)
#endif
#ifndef G_MAXUINT32
#define G_MAXUINT32 (4294967295U)
#endif
/*
* prototypes for ghashtable.c
*/
/* Turn a GLib hash table (mapping strings to strings) into a reference
* to a Perl hash table.
*
* @param hash: GLib hash table
* @returns: Perl hashref
*/
SV *g_hash_table_to_hashref(GHashTable *hash);
/* Turn a GLib hash table (mapping strings to GSList of strings) into a reference
* to a Perl hash table.
*
* @param hash: GLib hash table
* @returns: Perl hashref
*/
SV *g_hash_table_to_hashref_gslist(GHashTable *hash);
/* Turn a GLib hash table (mapping strings to property_t) into a reference
* to a Perl hash table.
*
* @param hash: GLib hash table
* @returns: Perl hashref
*/
SV *g_hash_table_to_hashref_property(GHashTable *hash);
/*
* prototypes for gerror.c
*/
/* Call perl's croak (die) for a GError (if there is one)
*
* @note This is not thread-safe
* @note This function does not return if error is non-NULL
*
* @param domain: String to prefix to error message (followed by ": ")
* @param error: The GError pointer
*/
void croak_gerror(const char *domain, GError **error);
/*
* prototypes for bigint.c
*/
/*
* These functions handle conversion of integers to and from Perl-compatible
* values. Most perls do not natively support 64-bit integers, so these functions
* interface with the Math::BigInt module to support those integers. The functions
* also handle conversions from floating-point to integer values, with silent fraction
* truncation, as perl automatically promotes integers to doubles on overflow.
*/
/* Convert an (unsigned) integer to a Perl SV. These will always produce a
* Math::BigInt object. Any failure is fatal. *All* C-to-Perl integer conversions
* must use these functions.
*
* NOTE - NOTE - NOTE
*
* Due to the way SWIG constructs return values, *any* outgoing typemap (out or
* argout) must use the following syntax:
* SP += argvi; PUTBACK;
* $result = sv_2mortal(amglue_newSVi64(...));
* SPAGAIN; SP -= argvi; argvi++;
* This has the effect of saving the arguments added to the perl stack so far, by
* setting the global perl stack to a point above them.
*
* @param v: value to convert
* @returns: pointer to a new SV (refcount=1)
*/
SV *amglue_newSVi64(gint64 v);
SV *amglue_newSVu64(guint64 v);
/* Convert a Perl SV to an integer of the specified size. These functions should
* be used for *all* Perl-to-C integer conversions, since the Perl value may be a
* Math::BigInt object. All of these functions will call croak() on an overflow
* condition, rather than silently truncate.
*
* @param sv: perl value to convert
* @returns: value of the given type
*/
gint64 amglue_SvI64(SV *sv, gchar **err);
guint64 amglue_SvU64(SV *sv, gchar **err);
gint32 amglue_SvI32(SV *sv, gchar **err);
guint32 amglue_SvU32(SV *sv, gchar **err);
gint16 amglue_SvI16(SV *sv, gchar **err);
guint16 amglue_SvU16(SV *sv, gchar **err);
gint8 amglue_SvI8(SV *sv, gchar **err);
guint8 amglue_SvU8(SV *sv, gchar **err);
/*
* prototypes for objwrap.c
*/
/* Return a new SV with refcount 1 representing the given C object
* with the given class.
*
* @param c_obj: the object to represent
* @param perl_class: the perl with which to bless and tie the SV
*/
SV * new_sv_for_c_obj(gpointer c_obj, const char *perl_class);
/* Return the C object buried in an SV, asserting that the perl SV is
* derived from derived_from. Returns NULL for undefined perl values.
*
* This function is based on SWIG's SWIG_Perl_ConvertPtr. The INT2PTR
* situation certainly looks strange, but is documented in perlxs.
*
* @param sv: the SV to convert
* @param derived_from: perl class from which the SV should be derived
* @return: underlying pointer
*/
gpointer c_obj_from_sv(SV *sv, const char *derived_from);
/*
* prototypes for xferwrap.c
*/
/* declare structs */
struct Xfer;
struct XferElement;
/* Return a new SV representing a transfer.
*
* @param xfer: the transfer to represent
*/
SV *new_sv_for_xfer(struct Xfer *xfer);
/* Return a new SV representing a transfer element.
*
* @param xe: the transfer element to represent
*/
SV *new_sv_for_xfer_element(struct XferElement *xe);
/* Convert an SV to an Xfer. The Xfer's reference count is not
* incremented -- this is a "borrowed" reference.
*
* @param sv: the perl value
* @returns: pointer to the corresponding transfer, or NULL
*/
struct Xfer *xfer_from_sv(SV *sv);
/* Convert an SV to an XferElement. The element's reference count is
* not incremented -- this is a "borrowed" reference.
*
* @param sv: the perl value
* @returns: pointer to the corresponding transfer element, or NULL.
*/
struct XferElement *xfer_element_from_sv(SV *sv);
/*
* prototypes for source.c
*/
typedef enum amglue_Source_state {
AMGLUE_SOURCE_NEW,
AMGLUE_SOURCE_ATTACHED,
AMGLUE_SOURCE_DESTROYED
} amglue_Source_state;
/* There is *one* amglue_Source object for each GSource; this
* allows us to attach amglue-related information to the
* GSource. See amglue/source.c for more detail. */
typedef struct amglue_Source {
GSource *src;
GSourceFunc callback;
gint refcount;
amglue_Source_state state;
SV *callback_sv;
} amglue_Source;
/* Get the amglue_Source object associated with this GSource, creating a
* new one if necessary, and increment its refcount.
*
* The 'callback' parameter should be a C function with the
* appropriate signature for this GSource. The callback will
* be given the amglue_Source as its 'data' argument, and should
* invoke its callback_sv as a Perl sub with the appropriate
* parameters. Simple GSources can use amglue_source_callback_simple,
* below.
*
* This amglue_Source object can be returned directly to perl via a
* SWIG binding; it will be bound as an Amanda::MainLoop::Source
* object, and its memory management will be handled correctly.
*
* @param gsrc: the GSource object to wrap
* @param callback: function to trigger a perl callback
* @returns: an amglue_Source with appropriate refcount
*/
amglue_Source *amglue_source_get(GSource *gsrc, GSourceFunc callback);
/* Create a new amglue_Source object for this GSource. Use this when
* the GSource was just created and does not yet have a corresponding
* amglue_Source.
*
* @param gsrc: the GSource object to wrap
* @param callback: function to trigger a perl callback
* @returns: an amglue_Source with appropriate refcount
*/
amglue_Source *amglue_source_new(GSource *gsrc, GSourceFunc callback);
/* Increment the refcount on an amglue_Source */
#define amglue_source_ref(aS) aS->refcount++
/* Unref an amglue_Source object, freeing it if its refcount reaches
* zero. */
#define amglue_source_unref(aS) if (!--(aS)->refcount) amglue_source_free((aS))
void amglue_source_free(amglue_Source *);
#endif /* AMANDA_AMGLUE_H */
|