Port client side code to GDBus

This continues the series of patches for GDBus porting, affecting
all code that accesses remote DBus objects. This includes modemManager,
automount, autorun (for the hotplug sniffer), calendar, network (for
nm-applet only), power, scripting (for perf monitor interface)

https://bugzilla.gnome.org/show_bug.cgi?id=648651
This commit is contained in:
Giovanni Campagna 2011-08-16 14:28:53 +02:00 committed by Colin Walters
parent 827bf506a7
commit 6547f75b12
6 changed files with 172 additions and 182 deletions

View File

@ -1,6 +1,6 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const DBus = imports.dbus; const Gio = imports.gi.Gio;
const Lang = imports.lang; const Lang = imports.lang;
const Shell = imports.gi.Shell; const Shell = imports.gi.Shell;
const Signals = imports.signals; const Signals = imports.signals;
@ -8,33 +8,43 @@ const Signals = imports.signals;
// The following are not the complete interfaces, just the methods we need // The following are not the complete interfaces, just the methods we need
// (or may need in the future) // (or may need in the future)
const ModemGsmNetworkInterface = { const ModemGsmNetworkInterface = <interface name="org.freedesktop.ModemManager.Modem.Gsm.Network">
name: 'org.freedesktop.ModemManager.Modem.Gsm.Network', <method name="GetRegistrationInfo">
methods: [ <arg type="u" direction="out" />
{ name: 'GetRegistrationInfo', inSignature: '', outSignature: 'uss' }, <arg type="s" direction="out" />
{ name: 'GetSignalQuality', inSignature: '', outSignature: 'u' } <arg type="s" direction="out" />
], </method>
properties: [ <method name="GetSignalQuality">
{ name: 'AccessTechnology', signature: 'u', access: 'read' } <arg type="u" direction="out" />
], </method>
signals: [ <property name="AccessTechnology" type="u" access="read" />
{ name: 'SignalQuality', inSignature: 'u' }, <signal name="SignalQuality">
{ name: 'RegistrationInfo', inSignature: 'uss' } <arg type="u" direction="out" />
] </signal>
}; <signal name="RegistrationInfo">
const ModemGsmNetworkProxy = DBus.makeProxyClass(ModemGsmNetworkInterface); <arg type="u" direction="out" />
<arg type="s" direction="out" />
<arg type="s" direction="out" />
</signal>
</interface>;
const ModemCdmaInterface = { const ModemGsmNetworkProxy = Gio.DBusProxy.makeProxyWrapper(ModemGsmNetworkInterface);
name: 'org.freedesktop.ModemManager.Modem.Cdma',
methods: [ const ModemCdmaInterface = <interface name="org.freedesktop.ModemManager.Modem.Cdma">
{ name: 'GetSignalQuality', inSignature: '', outSignature: 'u' }, <method name="GetSignalQuality">
{ name: 'GetServingSystem', inSignature: '', outSignature: 'usu' } <arg type="u" direction="out" />
], </method>
signals: [ <method name="GetServingSystem">
{ name: 'SignalQuality', inSignature: 'u' } <arg type="u" direction="out" />
] <arg type="s" direction="out" />
}; <arg type="u" direction="out" />
const ModemCdmaProxy = DBus.makeProxyClass(ModemCdmaInterface); </method>
<signal name="SignalQuality">
<arg type="u" direction="out" />
</signal>
</interface>;
const ModemCdmaProxy = Gio.DBusProxy.makeProxyWrapper(ModemCdmaInterface);
let _providersTable; let _providersTable;
function _getProvidersTable() { function _getProvidersTable() {
@ -50,17 +60,17 @@ function ModemGsm() {
ModemGsm.prototype = { ModemGsm.prototype = {
_init: function(path) { _init: function(path) {
this._proxy = new ModemGsmNetworkProxy(DBus.system, 'org.freedesktop.ModemManager', path); this._proxy = new ModemGsmNetworkProxy(Gio.DBus.system, 'org.freedesktop.ModemManager', path);
this.signal_quality = 0; this.signal_quality = 0;
this.operator_name = null; this.operator_name = null;
// Code is duplicated because the function have different signatures // Code is duplicated because the function have different signatures
this._proxy.connect('SignalQuality', Lang.bind(this, function(proxy, quality) { this._proxy.connectSignal('SignalQuality', Lang.bind(this, function(proxy, sender, [quality]) {
this.signal_quality = quality; this.signal_quality = quality;
this.emit('notify::signal-quality'); this.emit('notify::signal-quality');
})); }));
this._proxy.connect('RegistrationInfo', Lang.bind(this, function(proxy, status, code, name) { this._proxy.connectSignal('RegistrationInfo', Lang.bind(this, function(proxy, sender, [status, code, name]) {
this.operator_name = this._findOperatorName(name, code); this.operator_name = this._findOperatorName(name, code);
this.emit('notify::operator-name'); this.emit('notify::operator-name');
})); }));
@ -155,12 +165,12 @@ function ModemCdma() {
ModemCdma.prototype = { ModemCdma.prototype = {
_init: function(path) { _init: function(path) {
this._proxy = new ModemCdmaProxy(DBus.system, 'org.freedesktop.ModemManager', path); this._proxy = new ModemCdmaProxy(Gio.DBus.system, 'org.freedesktop.ModemManager', path);
this.signal_quality = 0; this.signal_quality = 0;
this.operator_name = null; this.operator_name = null;
this._proxy.connect('SignalQuality', Lang.bind(this, function(proxy, quality) { this._proxy.connect('SignalQuality', Lang.bind(this, function(proxy, sender, params) {
this.signal_quality = quality; this.signal_quality = params[0];
this.emit('notify::signal-quality'); this.emit('notify::signal-quality');
// receiving this signal means the device got activated // receiving this signal means the device got activated

View File

@ -1,7 +1,6 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Lang = imports.lang; const Lang = imports.lang;
const DBus = imports.dbus;
const Mainloop = imports.mainloop; const Mainloop = imports.mainloop;
const Gio = imports.gi.Gio; const Gio = imports.gi.Gio;
const Params = imports.misc.params; const Params = imports.misc.params;
@ -16,63 +15,54 @@ const SETTING_ENABLE_AUTOMOUNT = 'automount';
const AUTORUN_EXPIRE_TIMEOUT_SECS = 10; const AUTORUN_EXPIRE_TIMEOUT_SECS = 10;
const ConsoleKitSessionIface = { const ConsoleKitSessionIface = <interface name="org.freedesktop.ConsoleKit.Session">
name: 'org.freedesktop.ConsoleKit.Session', <method name="IsActive">
methods: [{ name: 'IsActive', <arg type="b" direction="out" />
inSignature: '', </method>
outSignature: 'b' }], <signal name="ActiveChanged">
signals: [{ name: 'ActiveChanged', <arg type="b" direction="out" />
inSignature: 'b' }] </signal>
}; </interface>;
const ConsoleKitSessionProxy = DBus.makeProxyClass(ConsoleKitSessionIface); const ConsoleKitSessionProxy = Gio.DBusProxy.makeProxyWrapper(ConsoleKitSessionIface);
const ConsoleKitManagerIface = { const ConsoleKitManagerIface = <interface name="org.freedesktop.ConsoleKit.Manager">
name: 'org.freedesktop.ConsoleKit.Manager', <method name="GetCurrentSession">
methods: [{ name: 'GetCurrentSession', <arg type="o" direction="out" />
inSignature: '', </method>
outSignature: 'o' }] </interface>;
};
const ConsoleKitManagerInfo = Gio.DBusInterfaceInfo.new_for_xml(ConsoleKitManagerIface);
function ConsoleKitManager() { function ConsoleKitManager() {
this._init(); var self = new Gio.DBusProxy({ g_connection: Gio.DBus.system,
}; g_interface_name: ConsoleKitManagerInfo.name,
g_interface_info: ConsoleKitManagerInfo,
g_name: 'org.freedesktop.ConsoleKit',
g_object_path: '/org/freedesktop/ConsoleKit/Manager',
g_flags: (Gio.DBusProxyFlags.DO_NOT_AUTO_START |
Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES) });
ConsoleKitManager.prototype = { self.connect('notify::g-name-owner', function() {
_init: function() { if (self.g_name_owner) {
this.sessionActive = true; self.GetCurrentSessionRemote(function([session]) {
self._ckSession = new ConsoleKitSessionProxy(Gio.DBus.system, 'org.freedesktop.ConsoleKit', session);
DBus.system.proxifyObject(this, self._ckSession.connectSignal('ActiveChanged', function(object, senderName, [isActive]) {
'org.freedesktop.ConsoleKit', self.sessionActive = isActive;
'/org/freedesktop/ConsoleKit/Manager'); });
self._ckSession.IsActiveRemote(function([isActive]) {
DBus.system.watch_name('org.freedesktop.ConsoleKit', self.sessionActive = isActive;
false, // do not launch a name-owner if none exists });
Lang.bind(this, this._onManagerAppeared), });
Lang.bind(this, this._onManagerVanished)); } else {
}, self.sessionActive = true;
}
_onManagerAppeared: function(owner) { });
this.GetCurrentSessionRemote(Lang.bind(this, this._onCurrentSession));
}, self.init(null);
return self;
_onManagerVanished: function(oldOwner) {
this.sessionActive = true;
},
_onCurrentSession: function(session) {
this._ckSession = new ConsoleKitSessionProxy(DBus.system, 'org.freedesktop.ConsoleKit', session);
this._ckSession.connect
('ActiveChanged', Lang.bind(this, function(object, isActive) {
this.sessionActive = isActive;
}));
this._ckSession.IsActiveRemote(Lang.bind(this, function(isActive) {
this.sessionActive = isActive;
}));
} }
};
DBus.proxifyPrototype(ConsoleKitManager.prototype, ConsoleKitManagerIface);
function AutomountManager() { function AutomountManager() {
this._init(); this._init();

View File

@ -1,7 +1,6 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Lang = imports.lang; const Lang = imports.lang;
const DBus = imports.dbus;
const Gio = imports.gi.Gio; const Gio = imports.gi.Gio;
const St = imports.gi.St; const St = imports.gi.St;
@ -62,25 +61,19 @@ function startAppForMount(app, mount) {
/******************************************/ /******************************************/
const HotplugSnifferIface = { const HotplugSnifferIface = <interface name="org.gnome.Shell.HotplugSniffer">
name: 'org.gnome.Shell.HotplugSniffer', <method name="SniffURI">
methods: [{ name: 'SniffURI', <arg type="s" direction="in" />
inSignature: 's', <arg type="as" direction="out" />
outSignature: 'as' }] </method>
}; </interface>;
const HotplugSniffer = function() { const HotplugSnifferProxy = Gio.DBusProxy.makeProxyWrapper(HotplugSnifferIface);
this._init(); function HotplugSniffer() {
}; return new HotplugSnifferProxy(Gio.DBus.session,
HotplugSniffer.prototype = {
_init: function() {
DBus.session.proxifyObject(this,
'org.gnome.Shell.HotplugSniffer', 'org.gnome.Shell.HotplugSniffer',
'/org/gnome/Shell/HotplugSniffer'); '/org/gnome/Shell/HotplugSniffer');
}, }
};
DBus.proxifyPrototype(HotplugSniffer.prototype, HotplugSnifferIface);
function ContentTypeDiscoverer(callback) { function ContentTypeDiscoverer(callback) {
this._init(callback); this._init(callback);
@ -114,9 +107,8 @@ ContentTypeDiscoverer.prototype = {
let root = mount.get_root(); let root = mount.get_root();
let hotplugSniffer = new HotplugSniffer(); let hotplugSniffer = new HotplugSniffer();
hotplugSniffer.SniffURIRemote hotplugSniffer.SniffURIRemote(root.get_uri(),
(root.get_uri(), DBus.CALL_FLAG_START, Lang.bind(this, function([contentTypes]) {
Lang.bind(this, function(contentTypes) {
this._emitCallback(mount, contentTypes); this._emitCallback(mount, contentTypes);
})); }));
} }

View File

@ -1,6 +1,5 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const DBus = imports.dbus;
const Clutter = imports.gi.Clutter; const Clutter = imports.gi.Clutter;
const Gio = imports.gi.Gio; const Gio = imports.gi.Gio;
const Lang = imports.lang; const Lang = imports.lang;
@ -195,30 +194,34 @@ EmptyEventSource.prototype = {
}; };
Signals.addSignalMethods(EmptyEventSource.prototype); Signals.addSignalMethods(EmptyEventSource.prototype);
const CalendarServerIface = { const CalendarServerIface = <interface name="org.gnome.Shell.CalendarServer">
name: 'org.gnome.Shell.CalendarServer', <method name="GetEvents">
methods: [{ name: 'GetEvents', <arg type="x" direction="in" />
inSignature: 'xxb', <arg type="x" direction="in" />
outSignature: 'a(sssbxxa{sv})' }], <arg type="b" direction="in" />
signals: [{ name: 'Changed', <arg type="a(sssbxxa{sv})" direction="out" />
inSignature: '' }] </method>
}; <signal name="Changed" />
</interface>;
const CalendarServer = function () { const CalendarServerInfo = Gio.DBusInterfaceInfo.new_for_xml(CalendarServerIface);
this._init();
};
CalendarServer.prototype = { function CalendarServer() {
_init: function() { var self = new Gio.DBusProxy({ g_connection: Gio.DBus.session,
DBus.session.proxifyObject(this, 'org.gnome.Shell.CalendarServer', '/org/gnome/Shell/CalendarServer'); g_interface_name: CalendarServerInfo.name,
g_interface_info: CalendarServerInfo,
g_name: 'org.gnome.Shell.CalendarServer',
g_object_path: '/org/gnome/Shell/CalendarServer',
g_flags: (Gio.DBusProxyFlags.DO_NOT_AUTO_START |
Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES) });
self.init(null);
return self;
} }
};
DBus.proxifyPrototype(CalendarServer.prototype, CalendarServerIface);
// an implementation that reads data from a session bus service // an implementation that reads data from a session bus service
function DBusEventSource(owner) { function DBusEventSource() {
this._init(owner); this._init();
} }
function _datesEqual(a, b) { function _datesEqual(a, b) {
@ -241,16 +244,18 @@ function _dateIntervalsOverlap(a0, a1, b0, b1)
DBusEventSource.prototype = { DBusEventSource.prototype = {
_init: function(owner) { _init: function() {
this._resetCache(); this._resetCache();
this._dbusProxy = new CalendarServer(owner); this._dbusProxy = new CalendarServer();
this._dbusProxy.connect('Changed', Lang.bind(this, this._onChanged)); this._dbusProxy.connectSignal('Changed', Lang.bind(this, this._onChanged));
DBus.session.watch_name('org.gnome.Shell.CalendarServer', this._dbusProxy.connect('notify::g-name-owner', Lang.bind(this, function() {
false, // do not launch a name-owner if none exists if (this._dbusProxy.g_name_owner)
Lang.bind(this, this._onNameAppeared), this._onNameAppeared();
Lang.bind(this, this._onNameVanished)); else
this._onNameVanished();
}));
}, },
_resetCache: function() { _resetCache: function() {
@ -273,7 +278,7 @@ DBusEventSource.prototype = {
this._loadEvents(false); this._loadEvents(false);
}, },
_onEventsReceived: function(appointments) { _onEventsReceived: function([appointments]) {
let newEvents = []; let newEvents = [];
if (appointments != null) { if (appointments != null) {
for (let n = 0; n < appointments.length; n++) { for (let n = 0; n < appointments.length; n++) {
@ -296,9 +301,9 @@ DBusEventSource.prototype = {
_loadEvents: function(forceReload) { _loadEvents: function(forceReload) {
if (this._curRequestBegin && this._curRequestEnd){ if (this._curRequestBegin && this._curRequestEnd){
let callFlags = 0; let callFlags = Gio.DBusCallFlags.NO_AUTO_START;
if (forceReload) if (forceReload)
callFlags |= DBus.CALL_FLAG_START; callFlags = Gio.DBusCallFlags.NONE;
this._dbusProxy.GetEventsRemote(this._curRequestBegin.getTime() / 1000, this._dbusProxy.GetEventsRemote(this._curRequestBegin.getTime() / 1000,
this._curRequestEnd.getTime() / 1000, this._curRequestEnd.getTime() / 1000,
forceReload, forceReload,

View File

@ -1,6 +1,5 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const DBus = imports.dbus;
const Gio = imports.gi.Gio; const Gio = imports.gi.Gio;
const Mainloop = imports.mainloop; const Mainloop = imports.mainloop;
const Meta = imports.gi.Meta; const Meta = imports.gi.Meta;
@ -70,24 +69,21 @@ function waitLeisure() {
}; };
} }
const PerfHelperIface = { const PerfHelperIface = <interface name="org.gnome.Shell.PerfHelper">
name: 'org.gnome.Shell.PerfHelper', <method name="CreateWindow">
methods: [{ name: 'CreateWindow', inSignature: 'iibb', outSignature: '' }, <arg type="i" direction="in" />
{ name: 'WaitWindows', inSignature: '', outSignature: '' }, <arg type="i" direction="in" />
{ name: 'DestroyWindows', inSignature: '', outSignature: ''}] <arg type="b" direction="in" />
}; <arg type="b" direction="in" />
</method>
<method name="WaitWindows" />
<method name="DestroyWindows" />
</interface>;
const PerfHelper = function () { var PerfHelperProxy = Gio.DBusProxy.makeProxyWrapper(PerfHelperIface);
this._init(); function PerfHelper() {
}; return new PerfHelperProxy(Gio.DBus.session, 'org.gnome.Shell.PerfHelper', '/org/gnome/Shell/PerfHelper');
PerfHelper.prototype = {
_init: function() {
DBus.session.proxifyObject(this, 'org.gnome.Shell.PerfHelper', '/org/gnome/Shell/PerfHelper');
} }
};
DBus.proxifyPrototype(PerfHelper.prototype, PerfHelperIface);
let _perfHelper = null; let _perfHelper = null;
function _getPerfHelper() { function _getPerfHelper() {

View File

@ -1,7 +1,6 @@
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Gio = imports.gi.Gio; const Gio = imports.gi.Gio;
const DBus = imports.dbus;
const Lang = imports.lang; const Lang = imports.lang;
const Mainloop = imports.mainloop; const Mainloop = imports.mainloop;
const Shell = imports.gi.Shell; const Shell = imports.gi.Shell;
@ -40,20 +39,18 @@ const UPDeviceState = {
PENDING_DISCHARGE: 6 PENDING_DISCHARGE: 6
}; };
const PowerManagerInterface = { const PowerManagerInterface = <interface name="org.gnome.SettingsDaemon.Power">
name: 'org.gnome.SettingsDaemon.Power', <method name="GetDevices">
methods: [ <arg type="a(susdut)" direction="out" />
{ name: 'GetDevices', inSignature: '', outSignature: 'a(susdut)' }, </method>
{ name: 'GetPrimaryDevice', inSignature: '', outSignature: '(susdut)' }, <method name="GetPrimaryDevice">
], <arg type="(susdut)" direction="out" />
signals: [ </method>
{ name: 'Changed', inSignature: '' }, <signal name="Changed" />
], <property name="Icon" type="s" access="read" />
properties: [ </interface>;
{ name: 'Icon', signature: 's', access: 'read' },
] const PowerManagerProxy = Gio.DBusProxy.makeProxyWrapper(PowerManagerInterface);
};
let PowerManagerProxy = DBus.makeProxyClass(PowerManagerInterface);
function Indicator() { function Indicator() {
this._init.apply(this, arguments); this._init.apply(this, arguments);
@ -64,7 +61,7 @@ Indicator.prototype = {
_init: function() { _init: function() {
PanelMenu.SystemStatusButton.prototype._init.call(this, 'battery-missing'); PanelMenu.SystemStatusButton.prototype._init.call(this, 'battery-missing');
this._proxy = new PowerManagerProxy(DBus.session, BUS_NAME, OBJECT_PATH); this._proxy = new PowerManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH);
this._deviceItems = [ ]; this._deviceItems = [ ];
this._hasPrimary = false; this._hasPrimary = false;
@ -81,19 +78,19 @@ Indicator.prototype = {
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
this.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop'); this.menu.addSettingsAction(_("Power Settings"), 'gnome-power-panel.desktop');
this._proxy.connect('Changed', Lang.bind(this, this._devicesChanged)); this._proxy.connectSignal('Changed', Lang.bind(this, this._devicesChanged));
this._devicesChanged(); this._devicesChanged();
}, },
_readPrimaryDevice: function() { _readPrimaryDevice: function() {
this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(device, error) { this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(result, error) {
if (error) { if (error) {
this._hasPrimary = false; this._hasPrimary = false;
this._primaryDeviceId = null; this._primaryDeviceId = null;
this._batteryItem.actor.hide(); this._batteryItem.actor.hide();
return; return;
} }
let [device_id, device_type, icon, percentage, state, seconds] = device; let [[device_id, device_type, icon, percentage, state, seconds]] = result;
if (device_type == UPDeviceType.BATTERY) { if (device_type == UPDeviceType.BATTERY) {
this._hasPrimary = true; this._hasPrimary = true;
let time = Math.round(seconds / 60); let time = Math.round(seconds / 60);
@ -130,7 +127,7 @@ Indicator.prototype = {
}, },
_readOtherDevices: function() { _readOtherDevices: function() {
this._proxy.GetDevicesRemote(Lang.bind(this, function(devices, error) { this._proxy.GetDevicesRemote(Lang.bind(this, function(result, error) {
this._deviceItems.forEach(function(i) { i.destroy(); }); this._deviceItems.forEach(function(i) { i.destroy(); });
this._deviceItems = []; this._deviceItems = [];
@ -139,6 +136,7 @@ Indicator.prototype = {
} }
let position = 0; let position = 0;
let [devices] = result;
for (let i = 0; i < devices.length; i++) { for (let i = 0; i < devices.length; i++) {
let [device_id, device_type] = devices[i]; let [device_id, device_type] = devices[i];
if (device_type == UPDeviceType.AC_POWER || device_id == this._primaryDeviceId) if (device_type == UPDeviceType.AC_POWER || device_id == this._primaryDeviceId)
@ -153,7 +151,7 @@ Indicator.prototype = {
}, },
_devicesChanged: function() { _devicesChanged: function() {
this._proxy.GetRemote('Icon', Lang.bind(this, function(icon, error) { let icon = this._proxy.Icon;
if (icon) { if (icon) {
let gicon = Gio.icon_new_for_string(icon); let gicon = Gio.icon_new_for_string(icon);
this.setGIcon(gicon); this.setGIcon(gicon);
@ -162,7 +160,6 @@ Indicator.prototype = {
this.menu.close(); this.menu.close();
this.actor.hide(); this.actor.hide();
} }
}));
this._readPrimaryDevice(); this._readPrimaryDevice();
this._readOtherDevices(); this._readOtherDevices();
} }