[shotwell/wip/phako/external-gstreamer: 4/5] wip: external helper launch helper
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/phako/external-gstreamer: 4/5] wip: external helper launch helper
- Date: Sun, 12 May 2019 10:52:44 +0000 (UTC)
commit 7c2238033804bd49e1532e48c3fe5c59ae7d8caf
Author: Jens Georg <mail jensge org>
Date: Sat May 11 17:25:29 2019 +0200
wip: external helper launch helper
src/ExternalHelper.vala | 95 +++++++++++++++++++++++++++++++++++++++++++++++++
src/meson.build | 3 +-
2 files changed, 97 insertions(+), 1 deletion(-)
---
diff --git a/src/ExternalHelper.vala b/src/ExternalHelper.vala
new file mode 100644
index 00000000..ce715953
--- /dev/null
+++ b/src/ExternalHelper.vala
@@ -0,0 +1,95 @@
+/*
+ * - Proxies interface access
+ */
+public class ExternalProxy<G> : Object, Initable {
+ private G remote;
+ private DBusServer server;
+ private Subprocess remote_process;
+ private SourceFunc saved_get_remote_callback;
+
+ public string dbus_path { get; construct set; }
+ public string remote_helper_path { get; construct set; }
+
+ public ExternalProxy(string dbus_path, string helper_path) throws Error {
+ Object(dbus_path: dbus_path, remote_helper_path : helper_path);
+ init();
+ }
+
+ public bool init(Cancellable? cancellable) throws GLib.Error {
+ var address = "unix:tmpdir=%s".printf(Environment.get_tmp_dir());
+ var observer = new DBusAuthObserver();
+ observer.authorize_authenticated_peer.connect(this.on_authorize_peer);
+
+ server = new DBusServer.sync(address, DBusServerFlags.NONE, DBus.generate_guid(), observer,
cancellable);
+ server.new_connection.connect(on_new_connection);
+ server.start();
+
+ return true;
+ }
+
+ public async G get_remote() throws Error {
+ if (remote == null) {
+ yield launch_helper();
+ } else {
+ Idle.add(() => { get_remote.callback(); return false; });
+ yield;
+ }
+
+ return remote;
+ }
+
+ private bool on_authorize_peer(DBusAuthObserver observer, IOStream stream, Credentials? credentials) {
+ debug("Observer trying to authorize for %s", credentials.to_string());
+
+ if (credentials == null) {
+ return false;
+ }
+
+ try {
+ if (!credentials.is_same_user(new Credentials())) {
+ return false;
+ }
+
+ return true;
+ } catch (Error error) {
+ return false;
+ }
+ }
+
+ private bool on_new_connection(DBusServer server, DBusConnection connection) {
+ bool retval = true;
+ try {
+ remote = connection.get_proxy_sync(null, dbus_path, DBusProxyFlags.DO_NOT_LOAD_PROPERTIES |
+ DBusProxyFlags.DO_NOT_CONNECT_SIGNALS,
+ null);
+ } catch (Error error) {
+ critical("Failed to create DBus proxy: %s", error.message);
+ retval = false;
+ }
+
+ saved_get_remote_callback();
+
+ return retval;
+ }
+
+ private async void launch_helper() throws Error {
+ saved_get_remote_callback = launch_helper.callback;
+
+ if (remote_process == null) {
+ remote_process = new Subprocess(SubprocessFlags.NONE, remote_helper_path, "--address=" +
server.get_client_address());
+ remote_process.wait_async.begin(null, on_process_exited);
+ }
+
+ yield;
+ }
+
+ private void on_process_exited(Object? source, AsyncResult res) {
+ try {
+ remote_process.wait_async.end(res);
+ remote_process = null;
+ } catch (Error error) { }
+
+ critical("Subprocess exited unexpectedly");
+ }
+}
+
diff --git a/src/meson.build b/src/meson.build
index f01a548d..0f90bebb 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -266,7 +266,8 @@ executable(
'video-support/VideoImportParams.vala',
'video-support/Video.vala',
'video-support/VideoSourceCollection.vala',
- 'video-support/VideoMetadata.vala'
+ 'video-support/VideoMetadata.vala',
+ 'ExternalHelper.vala'
] + shotwell_resources + face_sources,
include_directories : vapi_incdir,
dependencies : [
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]