Merge lp:~7-eric/inkscape/dbus-instances into lp:~inkscape.dev/inkscape/trunk

Proposed by Eric Greveson
Status: Merged
Merged at revision: 12412
Proposed branch: lp:~7-eric/inkscape/dbus-instances
Merge into: lp:~inkscape.dev/inkscape/trunk
Diff against target: 174 lines (+57/-7)
5 files modified
src/extension/dbus/dbus-init.cpp (+27/-2)
src/extension/dbus/dbus-init.h (+10/-0)
src/extension/dbus/document-interface.h (+0/-3)
src/extension/dbus/wrapper/inkscape-dbus-wrapper.h (+0/-2)
src/main.cpp (+20/-0)
To merge this branch: bzr merge lp:~7-eric/inkscape/dbus-instances
Reviewer Review Type Date Requested Status
Martin Owens full review Approve
Review via email: mp+173909@code.launchpad.net

Description of the change

Added a "--dbus-name" option to the command-line args, allowing users to specify a D-Bus bus name other than "org.inkscape" if required. This makes it possible to run and control multiple Inkscape instances (command line or GUI) in a single user session, very useful in a multi-processor server scripting environment.

To post a comment you must log in.
Revision history for this message
Martin Owens (doctormo) wrote :

The code is good and looks clean. I'd leave out the comment at dbus-init.cpp:117, but apart from that very minor item. It's ready to be merged.

The functional test went well and it worked as expected.

review: Approve (full review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/extension/dbus/dbus-init.cpp'
2--- src/extension/dbus/dbus-init.cpp 2013-07-04 22:51:56 +0000
3+++ src/extension/dbus/dbus-init.cpp 2013-07-10 11:00:40 +0000
4@@ -36,7 +36,14 @@
5 #include <sstream>
6
7
8-
9+namespace
10+{
11+ // This stores the bus name to use for this app instance. By default, it
12+ // will be set to org.inkscape. However, users may provide other names by
13+ // setting command-line parameters when starting Inkscape, so that more
14+ // than one instance of Inkscape may be used by external scripts.
15+ gchar *instance_bus_name = NULL;
16+}
17
18 namespace Inkscape {
19 namespace Extension {
20@@ -120,6 +127,11 @@
21 void
22 init (void)
23 {
24+ if (instance_bus_name == NULL) {
25+ // Set the bus name to the default
26+ instance_bus_name = strdup("org.inkscape");
27+ }
28+
29 guint result;
30 GError *error = NULL;
31 DBusGConnection *connection;
32@@ -127,7 +139,7 @@
33 connection = dbus_get_connection();
34 proxy = dbus_get_proxy(connection);
35 org_freedesktop_DBus_request_name (proxy,
36- "org.inkscape",
37+ instance_bus_name,
38 DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error);
39 //create interface for application
40 dbus_register_object (connection,
41@@ -198,6 +210,19 @@
42 return strdup(name.c_str());
43 }
44
45+void
46+dbus_set_bus_name(gchar * bus_name)
47+{
48+ g_assert(bus_name != NULL);
49+ g_assert(instance_bus_name == NULL);
50+ instance_bus_name = strdup(bus_name);
51+}
52
53+gchar *
54+dbus_get_bus_name()
55+{
56+ g_assert(instance_bus_name != NULL);
57+ return instance_bus_name;
58+}
59
60 } } } /* namespace Inkscape::Extension::Dbus */
61
62=== modified file 'src/extension/dbus/dbus-init.h'
63--- src/extension/dbus/dbus-init.h 2013-07-03 19:06:11 +0000
64+++ src/extension/dbus/dbus-init.h 2013-07-10 11:00:40 +0000
65@@ -28,6 +28,16 @@
66
67 gchar * dbus_init_desktop_interface (SPDesktop * dt);
68
69+/** Set the bus name to use. Default is "org.inkscape".
70+ This function should only be called once, before init(), if a non-default
71+ bus name is required. */
72+void dbus_set_bus_name(gchar * bus_name);
73+
74+/** Get the bus name for this instance. Default is "org.inkscape".
75+ This function should only be called after init().
76+ The returned gchar * is owned by this module and should not be freed. */
77+gchar * dbus_get_bus_name();
78+
79 } } } /* namespace Dbus, Extension, Inkscape */
80
81 #endif /* INKSCAPE_EXTENSION_DBUS_INIT_H__ */
82
83=== modified file 'src/extension/dbus/document-interface.h'
84--- src/extension/dbus/document-interface.h 2013-07-04 22:51:56 +0000
85+++ src/extension/dbus/document-interface.h 2013-07-10 11:00:40 +0000
86@@ -34,9 +34,6 @@
87
88 class SPDesktop;
89 class SPItem;
90-
91-// TODO: this define doesn't seem to be used... although the path itself is also hardcoded in dbus-init.cpp
92-#define DBUS_DOCUMENT_INTERFACE_PATH "/org/inkscape/document"
93
94 #define TYPE_DOCUMENT_INTERFACE (document_interface_get_type ())
95 #define DOCUMENT_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_DOCUMENT_INTERFACE, DocumentInterface))
96
97=== modified file 'src/extension/dbus/wrapper/inkscape-dbus-wrapper.h'
98--- src/extension/dbus/wrapper/inkscape-dbus-wrapper.h 2013-07-03 22:00:06 +0000
99+++ src/extension/dbus/wrapper/inkscape-dbus-wrapper.h 2013-07-10 11:00:40 +0000
100@@ -8,8 +8,6 @@
101
102 //#include <dbus/dbus-glib-bindings.h>
103 //#include <dbus/dbus-glib-lowlevel.h>
104-
105-#define DBUS_DOCUMENT_INTERFACE_PATH "/org/inkscape/document"
106
107 #define TYPE_DOCUMENT_INTERFACE (document_interface_get_type ())
108 #define DOCUMENT_INTERFACE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_DOCUMENT_INTERFACE, DocumentInterface))
109
110=== modified file 'src/main.cpp'
111--- src/main.cpp 2013-07-04 22:57:15 +0000
112+++ src/main.cpp 2013-07-10 11:00:40 +0000
113@@ -103,6 +103,11 @@
114 #endif // WIN32
115
116 #include "extension/init.h"
117+// Not ideal, but there doesn't appear to be a nicer system in place for
118+// passing command-line parameters to extensions before initialization...
119+#ifdef WITH_DBUS
120+#include "extension/dbus/dbus-init.h"
121+#endif // WITH_DBUS
122
123 #include <glibmm/i18n.h>
124 #include <glibmm/main.h>
125@@ -171,6 +176,7 @@
126 SP_ARG_VACUUM_DEFS,
127 #ifdef WITH_DBUS
128 SP_ARG_DBUS_LISTEN,
129+ SP_ARG_DBUS_NAME,
130 #endif // WITH_DBUS
131 SP_ARG_VERB_LIST,
132 SP_ARG_VERB,
133@@ -227,6 +233,7 @@
134 static gboolean sp_vacuum_defs = FALSE;
135 #ifdef WITH_DBUS
136 static gboolean sp_dbus_listen = FALSE;
137+static gchar *sp_dbus_name = NULL;
138 #endif // WITH_DBUS
139 static gchar *sp_export_png_utf8 = NULL;
140 static gchar *sp_export_svg_utf8 = NULL;
141@@ -274,6 +281,7 @@
142 sp_vacuum_defs = FALSE;
143 #ifdef WITH_DBUS
144 sp_dbus_listen = FALSE;
145+ sp_dbus_name = NULL;
146 #endif // WITH_DBUS
147
148 sp_export_png_utf8 = NULL;
149@@ -487,6 +495,11 @@
150 POPT_ARG_NONE, &sp_dbus_listen, SP_ARG_DBUS_LISTEN,
151 N_("Enter a listening loop for D-Bus messages in console mode"),
152 NULL},
153+
154+ {"dbus-name", 0,
155+ POPT_ARG_STRING, &sp_dbus_name, SP_ARG_DBUS_NAME,
156+ N_("Specify the D-Bus bus name to listen for messages on (default is org.inkscape)"),
157+ N_("BUS-NAME")},
158 #endif // WITH_DBUS
159
160 {"verb-list", 0,
161@@ -885,6 +898,13 @@
162 if ( sp_global_printer )
163 sp_global_printer_utf8 = g_strdup( sp_global_printer );
164 }
165+
166+#ifdef WITH_DBUS
167+ // Before initializing extensions, we must set the DBus bus name if required
168+ if (sp_dbus_name != NULL) {
169+ Inkscape::Extension::Dbus::dbus_set_bus_name(sp_dbus_name);
170+ }
171+#endif
172
173 // Return the list if wanted, else free it up.
174 if ( flDest ) {