[gjs] Gio: split GDBus implementation into helpers
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] Gio: split GDBus implementation into helpers
- Date: Wed, 20 Jun 2012 20:40:07 +0000 (UTC)
commit cdf07b06362e03ffa6cbacbba8c26e55ce32728e
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Thu Dec 8 00:20:09 2011 +0100
Gio: split GDBus implementation into helpers
Soon new API wrappers will be introduced, and this will help
reusing code.
https://bugzilla.gnome.org/show_bug.cgi?id=669350
modules/overrides/Gio.js | 114 +++++++++++++++++++++++++--------------------
1 files changed, 63 insertions(+), 51 deletions(-)
---
diff --git a/modules/overrides/Gio.js b/modules/overrides/Gio.js
index 8e2cdba..8db807a 100644
--- a/modules/overrides/Gio.js
+++ b/modules/overrides/Gio.js
@@ -261,6 +261,65 @@ function _makeOutSignature(args) {
return ret + ')';
}
+function _handleMethodCall(info, impl, method_name, parameters, invocation) {
+ // prefer a sync version if available
+ if (this[method_name]) {
+ var retval;
+ try {
+ retval = this[method_name].apply(this, parameters.deep_unpack());
+ } catch (e) {
+ if (e.name.indexOf('.') == -1) {
+ // likely to be a normal JS error
+ e.name = 'org.gnome.gjs.JSError.' + e.name;
+ }
+ invocation.return_dbus_error(name, e.message);
+ return;
+ }
+ if (retval === undefined) {
+ // undefined (no return value) is the empty tuple
+ retval = GLib.Variant.new('()', []);
+ }
+ try {
+ if (!(retval instanceof GLib.Variant)) {
+ // attempt packing according to out signature
+ let methodInfo = info.lookup_method(method_name);
+ let outArgs = methodInfo.out_args;
+ let outSignature = _makeOutSignature(outArgs);
+ if (outArgs.length == 1) {
+ // if one arg, we don't require the handler wrapping it
+ // into an Array
+ retval = [retval];
+ }
+ retval = GLib.Variant.new(outSignature, retval);
+ }
+ invocation.return_value(retval);
+ } catch(e) {
+ // if we don't do this, the other side will never see a reply
+ invocation.return_dbus_error('org.gnome.gjs.JSError.ValueError',
+ "The return value from the method handler was not in the correct format");
+ }
+ } else if (this[method_name + 'Async']) {
+ this[method_name + 'Async'](parameters.deep_unpack(), invocation);
+ } else {
+ log('Missing handler for DBus method ' + method_name);
+ invocation.return_dbus_error('org.gnome.gjs.NotImplementedError',
+ 'Method ' + method_name + ' is not implemented');
+ }
+}
+
+function _handlePropertyGet(info, impl, property_name) {
+ let propInfo = info.lookup_property(property_name);
+ let jsval = this[property_name];
+ if (jsval != undefined)
+ return GLib.Variant.new(propInfo.signature, jsval);
+ else
+ return null;
+}
+
+function _handlePropertySet(info, impl, property_name, new_value) {
+ this[property_name] = new_value.deep_unpack();
+}
+
function _wrapJSObject(interfaceInfo, jsObj) {
var info;
if (interfaceInfo instanceof Gio.DBusInterfaceInfo)
@@ -271,60 +330,13 @@ function _wrapJSObject(interfaceInfo, jsObj) {
var impl = new GjsPrivate.DBusImplementation({ g_interface_info: info });
impl.connect('handle-method-call', function(impl, method_name, parameters, invocation) {
- // prefer a sync version if available
- if (jsObj[method_name]) {
- var retval;
- try {
- retval = jsObj[method_name].apply(jsObj, parameters.deep_unpack());
- } catch (e) {
- if (e.name.indexOf('.') == -1) {
- // likely to be a normal JS error
- e.name = 'org.gnome.gjs.JSError.' + e.name;
- }
- invocation.return_dbus_error(e.name, e.message);
- return;
- }
- if (retval === undefined) {
- // undefined (no return value) is the empty tuple
- retval = GLib.Variant.new_tuple([], 0);
- }
- try {
- if (!(retval instanceof GLib.Variant)) {
- // attemp packing according to out signature
- var methodInfo = info.lookup_method(method_name);
- var outArgs = methodInfo.out_args;
- var outSignature = _makeOutSignature(outArgs);
- if (outArgs.length == 1) {
- // if one arg, we don't require the handler wrapping it
- // into an Array
- retval = [retval];
- }
- retval = GLib.Variant.new(outSignature, retval);
- }
- invocation.return_value(retval);
- } catch(e) {
- // if we don't do this, the other side will never see a reply
- invocation.return_dbus_error('org.gnome.gjs.JSError.ValueError',
- "The return value from the method handler was not in the correct format");
- }
- } else if (jsObj[method_name + 'Async']) {
- jsObj[method_name + 'Async'](parameters.deep_unpack(), invocation);
- } else {
- log('Missing handler for DBus method ' + method_name);
- invocation.return_dbus_error('org.gnome.gjs.NotImplementedError',
- 'Method ' + method_name + ' is not implemented');
- }
+ return _handleMethodCall.call(jsObj, info, impl, method_name, parameters, invocation)
});
impl.connect('handle-property-get', function(impl, property_name) {
- var propInfo = info.lookup_property(property_name);
- var jsval = jsObj[property_name];
- if (jsval != undefined)
- return GLib.Variant.new(propInfo.signature, jsval);
- else
- return null;
+ return _handlePropertyGet.call(jsObj, info, impl, property_name);
});
- impl.connect('handle-property-set', function(impl, property_name, new_value) {
- jsObj[property_name] = new_value.deep_unpack();
+ impl.connect('handle-property-set', function(impl, property_name, value) {
+ return _handlePropertySet.call(jsObj, info, impl, property_name, value);
});
return impl;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]