dbusServices: Allow to inhibit auto-shutdown
While we only shut down after a method call completed or (if the interface has signals) the sender disconnects from the bus, services may need to inhibit auto-shutdown for more specific reasons themselves, for example when a method call kicks off an operation that should complete before shutting down. Add hold() and release() methods like Gio.Application for those cases. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1115
This commit is contained in:
parent
04352ae158
commit
2c91b6164c
@ -18,6 +18,7 @@ var ServiceImplementation = class {
|
|||||||
this._injectTracking('return_value_with_unix_fd_list');
|
this._injectTracking('return_value_with_unix_fd_list');
|
||||||
|
|
||||||
this._senders = new Map();
|
this._senders = new Map();
|
||||||
|
this._holdCount = 0;
|
||||||
|
|
||||||
this._hasSignals = this._dbusImpl.get_info().signals.length > 0;
|
this._hasSignals = this._dbusImpl.get_info().signals.length > 0;
|
||||||
this._shutdownTimeoutId = 0;
|
this._shutdownTimeoutId = 0;
|
||||||
@ -38,6 +39,22 @@ var ServiceImplementation = class {
|
|||||||
this._dbusImpl.unexport();
|
this._dbusImpl.unexport();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hold() {
|
||||||
|
this._holdCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
release() {
|
||||||
|
if (this._holdCount === 0) {
|
||||||
|
logError(new Error('Unmatched call to release()'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._holdCount--;
|
||||||
|
|
||||||
|
if (this._holdCount === 0)
|
||||||
|
this._queueShutdownCheck();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* _handleError:
|
* _handleError:
|
||||||
* @param {Gio.DBusMethodInvocation}
|
* @param {Gio.DBusMethodInvocation}
|
||||||
@ -69,7 +86,7 @@ var ServiceImplementation = class {
|
|||||||
if (!this._autoShutdown)
|
if (!this._autoShutdown)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (this._senders.size > 0)
|
if (this._holdCount > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.emit('shutdown');
|
this.emit('shutdown');
|
||||||
@ -93,6 +110,7 @@ var ServiceImplementation = class {
|
|||||||
if (this._senders.has(sender))
|
if (this._senders.has(sender))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
this.hold();
|
||||||
this._senders.set(sender,
|
this._senders.set(sender,
|
||||||
this._dbusImpl.get_connection().watch_name(
|
this._dbusImpl.get_connection().watch_name(
|
||||||
sender,
|
sender,
|
||||||
@ -108,7 +126,7 @@ var ServiceImplementation = class {
|
|||||||
this._dbusImpl.get_connection().unwatch_name(id);
|
this._dbusImpl.get_connection().unwatch_name(id);
|
||||||
|
|
||||||
if (this._senders.delete(sender))
|
if (this._senders.delete(sender))
|
||||||
this._queueShutdownCheck();
|
this.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
_injectTracking(methodName) {
|
_injectTracking(methodName) {
|
||||||
|
Loading…
Reference in New Issue
Block a user