#include "config.h"
#include <glib.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "ev-daemon-gdbus-generated.h"
Go to the source code of this file.
|
static GType | ev_daemon_application_get_type (void) |
|
static void | ev_doc_free (EvDoc *doc) |
|
static EvDoc * | ev_daemon_application_find_doc (EvDaemonApplication *application, const gchar *uri) |
|
static gboolean | spawn_evince (const gchar *uri) |
|
static void | name_appeared_cb (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data) |
|
static void | name_vanished_cb (GDBusConnection *connection, const gchar *name, gpointer user_data) |
|
static void | process_pending_invocations (EvDaemonApplication *application, const gchar *uri, const gchar *dbus_name) |
|
static void | document_loaded_cb (GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) |
|
static gboolean | handle_register_document_cb (EvDaemon *object, GDBusMethodInvocation *invocation, const gchar *uri, EvDaemonApplication *application) |
|
static gboolean | handle_unregister_document_cb (EvDaemon *object, GDBusMethodInvocation *invocation, const gchar *uri, EvDaemonApplication *application) |
|
static gboolean | handle_find_document_cb (EvDaemon *object, GDBusMethodInvocation *invocation, const gchar *uri, gboolean spawn, EvDaemonApplication *application) |
|
static gboolean | ev_daemon_application_dbus_register (GApplication *gapplication, GDBusConnection *connection, const gchar *object_path, GError **error) |
|
static void | ev_daemon_application_dbus_unregister (GApplication *gapplication, GDBusConnection *connection, const gchar *object_path) |
|
static void | ev_daemon_application_init (EvDaemonApplication *application) |
|
static void | ev_daemon_application_finalize (GObject *object) |
|
static void | ev_daemon_application_class_init (EvDaemonApplicationClass *klass) |
|
gint | main (gint argc, gchar **argv) |
|
#define DAEMON_TIMEOUT (30) /* seconds */ |
#define EV_DBUS_DAEMON_INTERFACE_NAME "org.gnome.evince.Daemon" |
#define EV_DBUS_DAEMON_NAME "org.gnome.evince.Daemon" |
#define EV_DBUS_DAEMON_OBJECT_PATH "/org/gnome/evince/Daemon" |
#define EV_DBUS_WINDOW_INTERFACE_NAME "org.gnome.evince.Window" |
#define G_LOG_DOMAIN "EvinceDaemon" |
static void document_loaded_cb |
( |
GDBusConnection * |
connection, |
|
|
const gchar * |
sender_name, |
|
|
const gchar * |
object_path, |
|
|
const gchar * |
interface_name, |
|
|
const gchar * |
signal_name, |
|
|
GVariant * |
parameters, |
|
|
gpointer |
user_data |
|
) |
| |
|
static |
Definition at line 192 of file ev-daemon.c.
204 g_variant_get (parameters,
"(&s)", &uri);
209 if (strcmp (uri, doc->
uri) == 0) {
213 g_dbus_connection_signal_unsubscribe (connection, doc->
loaded_id);
Definition at line 442 of file ev-daemon.c.
444 GObjectClass *object_class = G_OBJECT_CLASS (klass);
445 GApplicationClass *g_application_class = G_APPLICATION_CLASS (klass);
static gboolean ev_daemon_application_dbus_register |
( |
GApplication * |
gapplication, |
|
|
GDBusConnection * |
connection, |
|
|
const gchar * |
object_path, |
|
|
GError ** |
error |
|
) |
| |
|
static |
Definition at line 368 of file ev-daemon.c.
376 if (!G_APPLICATION_CLASS (ev_daemon_application_parent_class)->dbus_register (gapplication,
382 skeleton = ev_daemon_skeleton_new ();
383 if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton),
387 g_object_unref (skeleton);
391 application->
daemon = skeleton;
392 g_signal_connect (skeleton,
"handle-register-document",
394 g_signal_connect (skeleton,
"handle-unregister-document",
396 g_signal_connect (skeleton,
"handle-find-document",
static void ev_daemon_application_dbus_unregister |
( |
GApplication * |
gapplication, |
|
|
GDBusConnection * |
connection, |
|
|
const gchar * |
object_path |
|
) |
| |
|
static |
Definition at line 402 of file ev-daemon.c.
408 if (application->
daemon) {
409 g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (application->
daemon));
410 g_object_unref (application->
daemon);
411 application->
daemon = NULL;
414 G_APPLICATION_CLASS (ev_daemon_application_parent_class)->dbus_unregister (gapplication,
static void ev_daemon_application_finalize |
( |
GObject * |
object) | |
|
|
static |
Definition at line 429 of file ev-daemon.c.
438 G_OBJECT_CLASS (ev_daemon_application_parent_class)->finalize (
object);
Definition at line 94 of file ev-daemon.c.
99 for (l = application->
docs; l != NULL; l = l->next) {
102 if (strcmp (doc->
uri, uri) == 0)
static GType ev_daemon_application_get_type |
( |
void |
) | |
|
|
static |
Definition at line 420 of file ev-daemon.c.
424 (GDestroyNotify) g_free,
static void ev_doc_free |
( |
EvDoc * |
doc) | |
|
|
static |
static gboolean handle_find_document_cb |
( |
EvDaemon * |
object, |
|
|
GDBusMethodInvocation * |
invocation, |
|
|
const gchar * |
uri, |
|
|
gboolean |
spawn, |
|
|
EvDaemonApplication * |
application |
|
) |
| |
|
static |
Definition at line 320 of file ev-daemon.c.
328 LOG (
"FindDocument URI '%s'", uri);
332 ev_daemon_complete_find_document (
object, invocation, doc->
dbus_name);
338 GList *uri_invocations;
339 gboolean ret_val =
TRUE;
343 if (uri_invocations == NULL) {
350 uri_invocations = g_list_prepend (uri_invocations, invocation);
358 LOG (
"FindDocument URI '%s' was not registered!", uri);
360 ev_daemon_complete_find_document (
object, invocation,
"");
static gboolean handle_register_document_cb |
( |
EvDaemon * |
object, |
|
|
GDBusMethodInvocation * |
invocation, |
|
|
const gchar * |
uri, |
|
|
EvDaemonApplication * |
application |
|
) |
| |
|
static |
Definition at line 218 of file ev-daemon.c.
223 GDBusConnection *connection;
229 LOG (
"RegisterDocument found owner '%s' for URI '%s'", doc->
dbus_name, uri);
230 ev_daemon_complete_register_document (
object, invocation, doc->
dbus_name);
235 sender = g_dbus_method_invocation_get_sender (invocation);
236 connection = g_dbus_method_invocation_get_connection (invocation);
238 LOG (
"RegisterDocument registered owner '%s' for URI '%s'", sender, uri);
240 doc = g_new (
EvDoc, 1);
242 doc->
uri = g_strdup (uri);
244 application->
docs = g_list_prepend (application->
docs, doc);
246 doc->
loaded_id = g_dbus_connection_signal_subscribe (connection,
255 doc->
watch_id = g_bus_watch_name_on_connection (connection,
257 G_BUS_NAME_WATCHER_FLAGS_NONE,
262 ev_daemon_complete_register_document (
object, invocation,
"");
264 g_application_hold (G_APPLICATION (application));
static gboolean handle_unregister_document_cb |
( |
EvDaemon * |
object, |
|
|
GDBusMethodInvocation * |
invocation, |
|
|
const gchar * |
uri, |
|
|
EvDaemonApplication * |
application |
|
) |
| |
|
static |
Definition at line 270 of file ev-daemon.c.
278 LOG (
"UnregisterDocument URI '%s'", uri);
282 LOG (
"UnregisterDocument URI was not registered!");
283 g_dbus_method_invocation_return_error_literal (invocation,
285 G_DBUS_ERROR_INVALID_ARGS,
286 "URI not registered");
290 sender = g_dbus_method_invocation_get_sender (invocation);
291 if (strcmp (doc->
dbus_name, sender) != 0) {
292 LOG (
"UnregisterDocument called by non-owner (owner '%s' sender '%s')",
295 g_dbus_method_invocation_return_error_literal (invocation,
297 G_DBUS_ERROR_BAD_ADDRESS,
298 "Only owner can call this method");
302 application->
docs = g_list_remove (application->
docs, doc);
305 g_dbus_connection_signal_unsubscribe (g_dbus_method_invocation_get_connection (invocation),
312 ev_daemon_complete_unregister_document (
object, invocation);
314 g_application_release (G_APPLICATION (application));
gint main |
( |
gint |
argc, |
|
|
gchar ** |
argv |
|
) |
| |
Definition at line 456 of file ev-daemon.c.
458 GApplication *application;
459 const GApplicationFlags flags = G_APPLICATION_IS_SERVICE;
460 GError *error = NULL;
463 g_set_prgname (
"evince-daemon");
469 g_application_set_inactivity_timeout (application,
DAEMON_TIMEOUT);
471 if (!g_application_register (application, NULL, &error)) {
472 g_printerr (
"Failed to register: %s\n", error->message);
473 g_error_free (error);
474 g_object_unref (application);
479 status = g_application_run (application, 0, NULL);
480 g_object_unref (application);
static void name_appeared_cb |
( |
GDBusConnection * |
connection, |
|
|
const gchar * |
name, |
|
|
const gchar * |
name_owner, |
|
|
gpointer |
user_data |
|
) |
| |
|
static |
Definition at line 133 of file ev-daemon.c.
138 LOG (
"Watch name'%s' appeared with owner '%s'",
name, name_owner);
static void name_vanished_cb |
( |
GDBusConnection * |
connection, |
|
|
const gchar * |
name, |
|
|
gpointer |
user_data |
|
) |
| |
|
static |
Definition at line 142 of file ev-daemon.c.
149 LOG (
"Watch name'%s' disappeared",
name);
151 for (l = application->
docs; l != NULL; l = l->next) {
157 LOG (
"Watch found URI '%s' for name; removing", doc->
uri);
159 application->
docs = g_list_delete_link (application->
docs, l);
162 g_application_release (G_APPLICATION (application));
static void process_pending_invocations |
( |
EvDaemonApplication * |
application, |
|
|
const gchar * |
uri, |
|
|
const gchar * |
dbus_name |
|
) |
| |
|
static |
Definition at line 169 of file ev-daemon.c.
174 GList *uri_invocations;
176 LOG (
"RegisterDocument process pending invocations for URI %s", uri);
179 for (l = uri_invocations; l != NULL; l = l->next) {
180 GDBusMethodInvocation *invocation;
182 invocation = (GDBusMethodInvocation *)l->data;
183 g_dbus_method_invocation_return_value (invocation,
184 g_variant_new (
"(s)", dbus_name));
187 g_list_free (uri_invocations);
static gboolean spawn_evince |
( |
const gchar * |
uri) | |
|
|
static |
Definition at line 110 of file ev-daemon.c.
114 GError *error = NULL;
117 argv[0] = g_build_filename (BINDIR,
"evince", NULL);
118 argv[1] = (gchar *) uri;
121 retval = g_spawn_async (NULL , argv, NULL ,
122 0, NULL, NULL, NULL, &error);
124 g_printerr (
"Error spawning evince for uri %s: %s\n", uri, error->message);
125 g_error_free (error);