~ubuntu-branches/ubuntu/utopic/ubufox/utopic-proposed

« back to all changes in this revision

Viewing changes to modules/libs/gio.jsm~

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-03-22 00:10:41 UTC
  • mfrom: (1.1.30)
  • Revision ID: package-import@ubuntu.com-20120322001041-nmvbxlrvwfx7vz0m
Tags: 2.0.1-0ubuntu1
* New upstream release
  - Fix an error when no plugins are found

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
 
/* ***** BEGIN LICENSE BLOCK *****
3
 
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 
 *
5
 
 * The contents of this file are subject to the Mozilla Public License Version
6
 
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 
 * the License. You may obtain a copy of the License at
8
 
 * http://www.mozilla.org/MPL/
9
 
 *
10
 
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 
 * for the specific language governing rights and limitations under the
13
 
 * License.
14
 
 *
15
 
 * The Original Code is ubufox.
16
 
 *
17
 
 * The Initial Developer of the Original Code is
18
 
 * Canonical Ltd.
19
 
 * Portions created by the Initial Developer are Copyright (C) 2011
20
 
 * the Initial Developer. All Rights Reserved.
21
 
 *
22
 
 * Contributor(s):
23
 
 *   Chris Coulson <chris.coulson@canonical.com>
24
 
 *
25
 
 * Alternatively, the contents of this file may be used under the terms of
26
 
 * either the GNU General Public License Version 2 or later (the "GPL"), or
27
 
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
 
 * in which case the provisions of the GPL or the LGPL are applicable instead
29
 
 * of those above. If you wish to allow use of your version of this file only
30
 
 * under the terms of either the GPL or the LGPL, and not to allow others to
31
 
 * use your version of this file under the terms of the MPL, indicate your
32
 
 * decision by deleting the provisions above and replace them with the notice
33
 
 * and other provisions required by the GPL or the LGPL. If you do not delete
34
 
 * the provisions above, a recipient may use your version of this file under
35
 
 * the terms of any one of the MPL, the GPL or the LGPL.
36
 
 *
37
 
 * ***** END LICENSE BLOCK ***** */
38
 
 
39
 
var EXPORTED_SYMBOLS = [ "gio" ];
40
 
 
41
 
const GIO_LIBNAME = "gio-2.0";
42
 
const GIO_ABIS = [ 0 ];
43
 
 
44
 
const Cu = Components.utils;
45
 
 
46
 
Cu.import("resource://gre/modules/ctypes.jsm");
47
 
Cu.import("resource://ubufox/libs/ctypes-utils.jsm");
48
 
Cu.import("resource://ubufox/libs/gobject.jsm");
49
 
Cu.import("resource://ubufox/libs/glib.jsm");
50
 
 
51
 
["LOG", "WARN", "ERROR"].forEach(function(aName) {
52
 
  this.__defineGetter__(aName, function() {
53
 
    Components.utils.import("resource://gre/modules/AddonLogging.jsm");
54
 
 
55
 
    LogManager.getLogger("ubufox.gio", this);
56
 
    return this[aName];
57
 
  });
58
 
}, this);
59
 
 
60
 
var asyncCbHandlers = {};
61
 
var asyncCbIdSerial = 0;
62
 
 
63
 
function AsyncCbData(cb, ccb) {
64
 
  this.cb = cb,
65
 
  this.ccb = ccb;
66
 
}
67
 
 
68
 
function newAsyncCbId() {
69
 
  while (asyncCbHandlers[++asyncCbIdSerial]) {}
70
 
  return asyncCbIdSerial;
71
 
}
72
 
 
73
 
function gio_defines(lib) {
74
 
  // Enums
75
 
  // GBusType
76
 
  this.GBusType = ctypes.int;
77
 
  this.G_BUS_TYPE_STARTER = -1;
78
 
  this.G_BUS_TYPE_NONE = 0;
79
 
  this.G_BUS_TYPE_SYSTEM = 1;
80
 
  this.G_BUS_TYPE_SESSION = 2;
81
 
 
82
 
  // GDBusProxyFlags
83
 
  this.GDBusProxyFlags = ctypes.int;
84
 
  this.G_DBUS_PROXY_FLAGS_NONE = 0;
85
 
  this.G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES = (1<<0);
86
 
  this.G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS = (1<<1);
87
 
  this.G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START = (1<<2);
88
 
 
89
 
  // GDBusCallFlags
90
 
  this.GDBusCallFlags = ctypes.int;
91
 
  this.G_DBUS_CALL_FLAGS_NONE = 0;
92
 
  this.G_DBUS_CALL_FLAGS_NO_AUTO_START = (1<<0);
93
 
 
94
 
  // GIOErrorEnum
95
 
  this.G_IO_ERROR_DBUS_ERROR = 36;
96
 
 
97
 
  // Types
98
 
  this.GDBusInterfaceInfo = ctypes.StructType("GDBusInterfaceInfo");
99
 
  this.GCancellable = ctypes.StructType("GCancellable");
100
 
  this.GAsyncResult = ctypes.StructType("GAsyncResult");
101
 
  this.GDBusProxy = ctypes.StructType("GDBusProxy");
102
 
 
103
 
  // Templates
104
 
  this.GAsyncReadyCallback = ctypes.FunctionType(ctypes.default_abi,
105
 
                                                 ctypes.void_t,
106
 
                                                 [gobject.GObject.ptr,
107
 
                                                  this.GAsyncResult.ptr,
108
 
                                                  glib.gpointer]).ptr;
109
 
 
110
 
  // Functions
111
 
  lib.lazy_bind("g_dbus_proxy_new_for_bus", ctypes.void_t, this.GBusType,
112
 
                this.GDBusProxyFlags, this.GDBusInterfaceInfo.ptr,
113
 
                glib.gchar.ptr, glib.gchar.ptr, glib.gchar.ptr,
114
 
                this.GCancellable.ptr, this.GAsyncReadyCallback, glib.gpointer);
115
 
  lib.lazy_bind("g_dbus_proxy_new_for_bus_finish", this.GDBusProxy.ptr,
116
 
                this.GAsyncResult.ptr, glib.GError.ptr.ptr);
117
 
  lib.lazy_bind("g_dbus_proxy_call", ctypes.void_t, this.GDBusProxy.ptr,
118
 
                glib.gchar.ptr, glib.GVariant.ptr, this.GDBusCallFlags,
119
 
                glib.gint, this.GCancellable.ptr, this.GAsyncReadyCallback,
120
 
                glib.gpointer);
121
 
  lib.lazy_bind("g_dbus_proxy_call_finish", glib.GVariant.ptr,
122
 
                this.GDBusProxy.ptr, this.GAsyncResult.ptr, glib.GError.ptr.ptr);
123
 
  lib.lazy_bind("g_io_error_quark", glib.GQuark);
124
 
  lib.lazy_bind("g_dbus_error_get_remote_error", glib.gchar.ptr, glib.GError.ptr);
125
 
  lib.lazy_bind("g_dbus_proxy_get_name_owner", glib.gchar.ptr, this.GDBusProxy.ptr);
126
 
 
127
 
  // Helpers to work around jsctypes limitations
128
 
  this.GDbusProxyNewForBus = function(aType, aFlags, aInfo, aName,
129
 
                                      aPath, aInterface, aCancellable,
130
 
                                      aCallback) {
131
 
    let cb = function(aObject, aResult, aData) {
132
 
      try {
133
 
        aCallback(aObject, aResult);
134
 
      } catch(e) {
135
 
        Cu.reportError(e);
136
 
      }
137
 
      delete asyncCbHandlers[id];
138
 
    };
139
 
    let ccb = gio.GAsyncReadyCallback(cb);
140
 
 
141
 
    var id = newAsyncCbId();
142
 
    asyncCbHandlers[id] = new AsyncCbData(cb, ccb);
143
 
 
144
 
    gio.g_dbus_proxy_new_for_bus(aType, aFlags, aInfo, aName, aPath,
145
 
                                 aInterface, aCancellable, ccb, null);
146
 
  };
147
 
 
148
 
  this.GDbusProxyCall = function(aProxy, aMethod, aParams, aFlags, aTimeout,
149
 
                                 aCancellable, aCallback) {
150
 
    let cb = function(aObject, aResult, aData) {
151
 
      try {
152
 
        aCallback(aObject, aResult);
153
 
      } catch(e) {
154
 
        Cu.reportError(e);
155
 
      }
156
 
      delete asyncCbHandlers[id];
157
 
    };
158
 
    let ccb = gio.GAsyncReadyCallback(cb);
159
 
 
160
 
    var id = newAsyncCbId();
161
 
    asyncCbHandlers[id] = new AsyncCbData(cb, ccb);
162
 
 
163
 
    gio.g_dbus_proxy_call(aProxy, aMethod, aParams, aFlags, aTimeout,
164
 
                          aCancellable, ccb, null);
165
 
  };
166
 
 
167
 
  this.G_IO_ERROR = this.g_io_error_quark();
168
 
}
169
 
 
170
 
new ctypes_library(GIO_LIBNAME, GIO_ABIS, gio_defines, this);