From f24f34bd713c7a26fbb6e13c2a44111223950738 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sun, 12 Jul 2009 16:02:09 +0000 Subject: Core Dbus files. Init creates interfaces on Inkscape startup. Application and document interface provide API functions over Dbus. service.in file makes sure Inkscape starts automatically when someone connects to it over Dbus. (bzr r8254.1.3) --- src/extension/dbus/dbus-init.cpp | 153 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 src/extension/dbus/dbus-init.cpp (limited to 'src/extension/dbus/dbus-init.cpp') diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp new file mode 100644 index 000000000..a30bb8fda --- /dev/null +++ b/src/extension/dbus/dbus-init.cpp @@ -0,0 +1,153 @@ + +#include +#include "dbus-init.h" + +#include "application-interface.h" +#include "application-server-glue.h" + +#include "document-interface.h" +#include "document-server-glue.h" + +#include "inkscape.h" +#include "document.h" +#include "desktop.h" +#include "file.h" +#include "verbs.h" +#include "helper/action.h" + +#include +#include +#include + + + + +namespace Inkscape { +namespace Extension { +namespace Dbus { + +/* PRIVATE get a connection to the session bus */ +DBusGConnection * +dbus_get_connection() { + GError *error = NULL; + DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); + if (error) { + fprintf(stderr, "Failed to get connection"); + return NULL; + } + else + return connection; +} + +/* PRIVATE create a proxy object for a bus.*/ +DBusGProxy * +dbus_get_proxy(DBusGConnection *connection) { + return dbus_g_proxy_new_for_name (connection, + DBUS_SERVICE_DBUS, + DBUS_PATH_DBUS, + DBUS_INTERFACE_DBUS); +} + +/* PRIVATE register an object on a bus */ +static gpointer +dbus_register_object (DBusGConnection *connection, + DBusGProxy *proxy, + GType object_type, + const DBusGObjectInfo *info, + const gchar *path) +{ + GObject *object = (GObject*)g_object_new (object_type, NULL); + dbus_g_object_type_install_info (object_type, info); + dbus_g_connection_register_g_object (connection, path, object); + return object; +} + +/* Initialize a Dbus service */ +void +init (void) +{ + guint result; + GError *error = NULL; + DBusGConnection *connection; + DBusGProxy *proxy; + DocumentInterface *obj; + connection = dbus_get_connection(); + proxy = dbus_get_proxy(connection); + org_freedesktop_DBus_request_name (proxy, + "org.inkscape", + DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); + //create interface for application + dbus_register_object (connection, + proxy, + TYPE_APPLICATION_INTERFACE, + &dbus_glib_application_interface_object_info, + DBUS_APPLICATION_INTERFACE_PATH); +} //init + +gchar * +init_document (void) { + guint result; + GError *error = NULL; + DBusGConnection *connection; + DBusGProxy *proxy; + SPDocument *doc; + + doc = sp_document_new(NULL, 1, TRUE); + + std::string name("/org/inkscape/"); + name.append(doc->name); + std::replace(name.begin(), name.end(), ' ', '_'); + + connection = dbus_get_connection(); + proxy = dbus_get_proxy(connection); + + dbus_register_object (connection, + proxy, + TYPE_DOCUMENT_INTERFACE, + &dbus_glib_document_interface_object_info, + name.c_str()); + return strdup(name.c_str()); +} //init_document + +gchar * +dbus_init_desktop_interface (SPDesktop * dt) +{ + DBusGConnection *connection; + DBusGProxy *proxy; + DocumentInterface *obj; + + std::string name("/org/inkscape/desktop_"); + std::stringstream out; + out << dt->dkey; + name.append(out.str()); + + //printf("DKEY: %d\n, NUMBER %d\n NAME: %s\n", dt->dkey, dt->number, name.c_str()); + + connection = dbus_get_connection(); + proxy = dbus_get_proxy(connection); + + obj = (DocumentInterface*) dbus_register_object (connection, + proxy, TYPE_DOCUMENT_INTERFACE, + &dbus_glib_document_interface_object_info, name.c_str()); + obj->desk = dt; + obj->updates = TRUE; + + return strdup(name.c_str()); +} + +gchar * +init_desktop (void) { + //this function will create a new desktop and call + //dbus_init_desktop_interface. + SPDesktop * dt = sp_file_new_default(); + + std::string name("/org/inkscape/desktop_"); + std::stringstream out; + out << dt->dkey; + name.append(out.str()); + return strdup(name.c_str()); +} //init_desktop + + + +} } } /* namespace Inkscape::Extension::Dbus */ -- cgit v1.2.3 From 4caca0b9edefb8470c058fdfed95ff50e0324499 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Wed, 22 Jul 2009 06:22:59 +0000 Subject: Fixed GErrors. Added many GErrors, especially for unfound objects. transfered many functions to using verbs instead of the function the verb calls to make error reporting easier. (bzr r8254.1.19) --- src/extension/dbus/dbus-init.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/extension/dbus/dbus-init.cpp') diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index a30bb8fda..dfd69d9fa 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -115,6 +115,9 @@ dbus_init_desktop_interface (SPDesktop * dt) DBusGConnection *connection; DBusGProxy *proxy; DocumentInterface *obj; + dbus_g_error_domain_register (INKSCAPE_ERROR, + NULL, + INKSCAPE_TYPE_ERROR); std::string name("/org/inkscape/desktop_"); std::stringstream out; -- cgit v1.2.3 From f8c188ba29f18db8bf7af03ed8f80841f613bbc0 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 17 Aug 2009 18:52:11 +0000 Subject: More documentation. (bzr r8254.1.32) --- src/extension/dbus/dbus-init.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/extension/dbus/dbus-init.cpp') diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index dfd69d9fa..253d6b938 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -1,4 +1,18 @@ - +/* + * This is where Inkscape connects to the DBus when it starts and + * registers the main interface. + * + * Also where new interfaces are registered when a new document is created. + * (Not called directly by application-interface but called indirectly.) + * + * Authors: + * Soren Berg + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + #include #include "dbus-init.h" -- cgit v1.2.3