37
37
* ***** END LICENSE BLOCK ***** */
39
const { utils: Cu } = Components;
39
41
var EXPORTED_SYMBOLS = [ "glib" ];
41
43
const GLIB_LIBNAME = "glib-2.0";
42
44
const GLIB_ABIS = [ 0 ];
44
const Cu = Components.utils;
46
46
Cu.import("resource://gre/modules/ctypes.jsm");
47
Cu.import("resource://ubufox/libs/ctypes-utils.jsm");
47
Cu.import("resource://ubufox/modules/utils.jsm");
49
function getString(aWrappee) {
50
let res = aWrappee.apply(null, Array.prototype.slice.call(arguments, 1));
51
return res.isNull() ? null : res.readString();
49
54
function glib_defines(lib) {
53
this.gpointer = ctypes.voidptr_t;
54
this.gchar = ctypes.char;
55
this.gint = ctypes.int;
56
this.gint32 = ctypes.int32_t;
57
this.guint32 = ctypes.uint32_t;
58
this.gulong = ctypes.unsigned_long;
59
this.GQuark = this.guint32;
60
this.GError = ctypes.StructType("GError",
61
[{'domain': this.GQuark},
63
{'message': this.gchar.ptr}]);
64
this.GVariant = ctypes.StructType("GVariant");
65
this.GVariantBuilder = ctypes.StructType("GVariantBuilder", [{'x': ctypes.size_t.array(16)}]);
66
// XXX: Is this right?
67
this.GVariantType = ctypes.char;
58
CTypesUtils.defineSimple(this, "gpointer", ctypes.voidptr_t);
59
CTypesUtils.defineSimple(this, "gchar", ctypes.char);
60
CTypesUtils.defineSimple(this, "gint", ctypes.int);
61
CTypesUtils.defineSimple(this, "gint32", ctypes.int32_t);
62
CTypesUtils.defineSimple(this, "guint32", ctypes.uint32_t);
63
CTypesUtils.defineSimple(this, "gulong", ctypes.unsigned_long);
64
CTypesUtils.defineSimple(this, "GQuark", this.guint32);
65
CTypesUtils.defineSimple(this, "GError",
66
ctypes.StructType("GError",
67
[{'domain': this.GQuark},
69
{'message': this.gchar.ptr}]));
70
CTypesUtils.defineSimple(this, "GVariant", ctypes.StructType("GVariant"));
71
CTypesUtils.defineSimple(this, "GVariantBuilder",
72
ctypes.StructType("GVariantBuilder",
73
[{'x': ctypes.size_t.array(16)}]));
74
CTypesUtils.defineSimple(this, "GVariantType", ctypes.char);
72
lib.lazy_bind("g_error_free", ctypes.void_t, this.GError.ptr);
73
lib.lazy_bind("g_free", ctypes.void_t, this.gpointer);
79
lib.lazy_bind("g_error_free", ctypes.void_t, [this.GError.ptr]);
80
lib.lazy_bind("g_free", ctypes.void_t, [this.gpointer]);
74
81
lib.lazy_bind("g_variant_builder_new", this.GVariantBuilder.ptr,
75
this.GVariantType.ptr);
76
lib.lazy_bind("g_variant_builder_add", ctypes.void_t, this.GVariantBuilder.ptr,
77
this.gchar.ptr, "...");
82
[this.GVariantType.ptr]);
83
lib.lazy_bind("g_variant_builder_add", ctypes.void_t, [this.GVariantBuilder.ptr,
84
this.gchar.ptr, "..."]);
78
85
lib.lazy_bind("g_variant_builder_add_value", ctypes.void_t,
79
this.GVariantBuilder.ptr, this.GVariant.ptr);
86
[this.GVariantBuilder.ptr, this.GVariant.ptr]);
80
87
lib.lazy_bind("g_variant_builder_end", this.GVariant.ptr,
81
this.GVariantBuilder.ptr);
88
[this.GVariantBuilder.ptr]);
82
89
lib.lazy_bind("g_variant_builder_unref", ctypes.void_t,
83
this.GVariantBuilder.ptr);
90
[this.GVariantBuilder.ptr]);
84
91
lib.lazy_bind("g_variant_builder_init", ctypes.void_t,
85
this.GVariantBuilder.ptr, this.GVariantType.ptr);
92
[this.GVariantBuilder.ptr, this.GVariantType.ptr]);
86
93
lib.lazy_bind("g_variant_builder_clear", ctypes.void_t,
87
this.GVariantBuilder.ptr);
88
lib.lazy_bind("g_variant_unref", ctypes.void_t, this.GVariant.ptr);
89
lib.lazy_bind("g_variant_get_string", this.gchar.ptr, this.GVariant.ptr,
91
lib.lazy_bind("g_variant_get", ctypes.void_t, this.GVariant.ptr,
92
this.gchar.ptr, "...");
93
lib.lazy_bind("g_variant_get_int32", this.gint32, this.GVariant.ptr);
94
lib.lazy_bind("g_variant_new", this.GVariant.ptr, this.gchar.ptr, "...");
94
[this.GVariantBuilder.ptr]);
95
lib.lazy_bind("g_variant_unref", ctypes.void_t, [this.GVariant.ptr]);
96
lib.lazy_bind_with_wrapper("g_variant_get_string", getString, this.gchar.ptr,
97
[this.GVariant.ptr, ctypes.size_t.ptr]);
98
lib.lazy_bind("g_variant_get", ctypes.void_t, [this.GVariant.ptr,
99
this.gchar.ptr, "..."]);
100
lib.lazy_bind("g_variant_get_int32", this.gint32, [this.GVariant.ptr]);
101
lib.lazy_bind("g_variant_new", this.GVariant.ptr, [this.gchar.ptr, "..."]);
97
new ctypes_library(GLIB_LIBNAME, GLIB_ABIS, glib_defines, this);
104
var glib = new CTypesUtils.newLibrary(GLIB_LIBNAME, GLIB_ABIS, glib_defines);