+ if (g_strcmp0 (interface_name, EV_DBUS_DAEMON_INTERFACE_NAME) != 0)
+ return;
+
+ if (g_strcmp0 (method_name, "RegisterDocument") == 0) {
+ EvDoc *doc;
+ const gchar *uri;
+
+ g_variant_get (parameters, "(&s)", &uri);
+
+ doc = ev_daemon_find_doc (uri);
+ if (doc != NULL) {
+ LOG ("RegisterDocument found owner '%s' for URI '%s'\n", doc->dbus_name, uri);
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("(s)", doc->dbus_name));
+ return;
+ }
+
+ ev_daemon_stop_killtimer ();
+
+ doc = g_new (EvDoc, 1);
+ doc->dbus_name = g_strdup (sender);
+ doc->uri = g_strdup (uri);
+
+ doc->loaded_id = g_dbus_connection_signal_subscribe (connection,
+ doc->dbus_name,
+ EV_DBUS_WINDOW_INTERFACE_NAME,
+ "DocumentLoaded",
+ NULL,
+ NULL,
+ 0,
+ (GDBusSignalCallback) document_loaded_cb,
+ doc,
+ NULL);
+ doc->watch_id = g_bus_watch_name_on_connection (connection,
+ sender,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ name_appeared_cb,
+ name_vanished_cb,
+ user_data, NULL);
+
+ LOG ("RegisterDocument registered owner '%s' for URI '%s'\n", doc->dbus_name, uri);
+ ev_daemon_docs = g_list_prepend (ev_daemon_docs, doc);
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", ""));
+ } else if (g_strcmp0 (method_name, "UnregisterDocument") == 0) {
+ EvDoc *doc;
+ const gchar *uri;
+
+ g_variant_get (parameters, "(&s)", &uri);
+
+ LOG ("UnregisterDocument URI '%s'\n", uri);
+
+ doc = ev_daemon_find_doc (uri);
+ if (doc == NULL) {
+ LOG ("UnregisterDocument URI was not registered!\n");
+ g_dbus_method_invocation_return_error_literal (invocation,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_INVALID_ARGS,
+ "URI not registered");
+ return;
+ }
+
+ if (strcmp (doc->dbus_name, sender) != 0) {
+ LOG ("UnregisterDocument called by non-owner (owner '%s' sender '%s')\n",
+ doc->dbus_name, sender);
+
+ g_dbus_method_invocation_return_error_literal (invocation,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_BAD_ADDRESS,
+ "Only owner can call this method");
+ return;
+ }
+
+ ev_daemon_docs = g_list_remove (ev_daemon_docs, doc);
+ ev_doc_free (doc);
+ ev_daemon_maybe_start_killtimer (user_data);
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+ } else if (g_strcmp0 (method_name, "FindDocument") == 0) {
+ EvDoc *doc;
+ const gchar *uri;
+ gboolean spawn;
+
+ g_variant_get (parameters, "(&sb)", &uri, &spawn);
+
+ LOG ("FindDocument URI '%s' \n", uri);
+
+ doc = ev_daemon_find_doc (uri);
+ if (doc != NULL) {
+ g_dbus_method_invocation_return_value (invocation,
+ g_variant_new ("(s)", doc->dbus_name));
+ return;
+ }
+
+ if (spawn) {
+ GList *uri_invocations;
+ gboolean ret_val = TRUE;
+
+ uri_invocations = g_hash_table_lookup (pending_invocations, uri);