Merge authors:
  Ted Gould (ted)
Related merge proposals:
  https://code.launchpad.net/~ted/upstart/dbus-arguments/+merge/172385
  proposed by: Ted Gould (ted)
  review: Approve - James Hunt (jamesodhunt)
  https://code.launchpad.net/~ted/upstart/session-jobs/+merge/172384
  proposed by: Ted Gould (ted)
------------------------------------------------------------
revno: 1513 [merge]
committer: James Hunt <[email protected]>
branch nick: upstart
timestamp: Wed 2013-07-24 10:22:25 +0100
message:
  * Merge of lp:~ted/upstart/dbus-arguments.
added:
  extra/conf-session/upstart-dbus-session-bridge.conf
  extra/conf-session/upstart-dbus-system-bridge.conf
modified:
  extra/Makefile.am
  extra/man/dbus-event.7
  extra/upstart-dbus-bridge.c


--
lp:upstart
https://code.launchpad.net/~upstart-devel/upstart/trunk

Your team Upstart Reviewers is subscribed to branch lp:upstart.
To unsubscribe from this branch go to 
https://code.launchpad.net/~upstart-devel/upstart/trunk/+edit-subscription
=== modified file 'extra/Makefile.am'
--- extra/Makefile.am	2013-07-18 14:12:13 +0000
+++ extra/Makefile.am	2013-07-24 04:41:18 +0000
@@ -20,7 +20,9 @@
 dist_sessions_DATA = \
 	conf-session/upstart-event-bridge.conf \
 	conf-session/upstart-file-bridge.conf \
-	conf-session/re-exec.conf
+	conf-session/re-exec.conf \
+	conf-session/upstart-dbus-session-bridge.conf \
+	conf-session/upstart-dbus-system-bridge.conf
 
 sbin_PROGRAMS = \
 	upstart-socket-bridge \

=== added file 'extra/conf-session/upstart-dbus-session-bridge.conf'
--- extra/conf-session/upstart-dbus-session-bridge.conf	1970-01-01 00:00:00 +0000
+++ extra/conf-session/upstart-dbus-session-bridge.conf	2013-07-24 04:41:18 +0000
@@ -0,0 +1,16 @@
+# upstart-dbus-bridge - Bridge D-Bus signal events into upstart
+#
+# This helper daemon receives D-Bus signal events and
+# emits equivalent Upstart events.
+
+description	"Bridge D-Bus session bus signal events into upstart"
+
+emits dbus
+
+start on started dbus
+stop on stopping dbus
+
+expect daemon
+respawn
+
+exec upstart-dbus-bridge --daemon --session --user --bus-name session

=== added file 'extra/conf-session/upstart-dbus-system-bridge.conf'
--- extra/conf-session/upstart-dbus-system-bridge.conf	1970-01-01 00:00:00 +0000
+++ extra/conf-session/upstart-dbus-system-bridge.conf	2013-07-24 04:41:18 +0000
@@ -0,0 +1,16 @@
+# upstart-dbus-bridge - Bridge D-Bus signal events into upstart
+#
+# This helper daemon receives D-Bus signal events and
+# emits equivalent Upstart events.
+
+description	"Bridge D-Bus system bus signal events into upstart"
+
+emits dbus
+
+start on started dbus
+stop on stopping dbus
+
+expect daemon
+respawn
+
+exec upstart-dbus-bridge --daemon --system --user --bus-name system

=== modified file 'extra/man/dbus-event.7'
--- extra/man/dbus-event.7	2013-07-24 08:52:11 +0000
+++ extra/man/dbus-event.7	2013-07-24 09:22:25 +0000
@@ -11,6 +11,8 @@
 .BI PATH\fR= PATH
 .BI SENDER\fR= SENDER
 .BI DESTINATION\fR= DESTINATION
+.BI ARG0\fR= VALUE
+.BI ARGN\fR= VALUE
 .\"
 .SH DESCRIPTION
 
@@ -26,6 +28,8 @@
 .B stop on
 stanza is modified.
 
+Arguments that are simple types (string, int, etc.) are translated into strings and placed as parameters on the event with the pattern ARG and the number representing the placement in the event prototype.  Parameters that are not a simple type are skipped, with the number being incremented the same.
+
 The
 .B BUS
 parameter is optional and only set if the
@@ -39,7 +43,7 @@
 .\"
 .SH EXAMPLES
 .\"
-.IP "start on dbus SIGNAL=NameAcquired INTERFACE=org.freedesktop.DBus PATH=/org/freedesktop/DBus SENDER=org.freedesktop.DBus"
+.IP "start on dbus SIGNAL=NameAcquired INTERFACE=org.freedesktop.DBus PATH=/org/freedesktop/DBus SENDER=org.freedesktop.DBus ARG0=com.mycorp.foo"
 Start job when a particular
 .I NameAcquired
 D-Bus signal is received.

=== modified file 'extra/upstart-dbus-bridge.c'
--- extra/upstart-dbus-bridge.c	2013-07-24 08:52:11 +0000
+++ extra/upstart-dbus-bridge.c	2013-07-24 09:22:25 +0000
@@ -443,6 +443,7 @@
 	int                 emit = FALSE;
 	DBusPendingCall    *pending_call;
 	DBusError           error;
+	DBusMessageIter     message_iter;
 	nih_local char    **env = NULL;
 	const char         *sender;
 	const char         *destination;
@@ -527,6 +528,97 @@
 		NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, var));
 	}
 
+	if (dbus_message_iter_init (message, &message_iter)) {
+		int current_type = DBUS_TYPE_INVALID;
+		int arg_num = 0;
+
+		while ((current_type = dbus_message_iter_get_arg_type(&message_iter)) != DBUS_TYPE_INVALID) {
+			nih_local char *var = NULL;
+
+			switch (current_type) {
+				case DBUS_TYPE_BOOLEAN: {
+					dbus_bool_t arg = 0;
+					dbus_message_iter_get_basic(&message_iter, &arg);
+
+					var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%s", arg_num, arg ? "TRUE" : "FALSE"));
+					break;
+				}
+				case DBUS_TYPE_INT16: {
+					dbus_int16_t arg = 0;
+					dbus_message_iter_get_basic(&message_iter, &arg);
+
+					var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%u", arg_num, arg));
+					break;
+				}
+				case DBUS_TYPE_UINT16: {
+					dbus_uint16_t arg = 0;
+					dbus_message_iter_get_basic(&message_iter, &arg);
+
+					var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%d", arg_num, arg));
+					break;
+				}
+				case DBUS_TYPE_INT32: {
+					dbus_int32_t arg = 0;
+					dbus_message_iter_get_basic(&message_iter, &arg);
+
+					var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%d", arg_num, arg));
+					break;
+				}
+				case DBUS_TYPE_UINT32: {
+					dbus_uint32_t arg = 0;
+					dbus_message_iter_get_basic(&message_iter, &arg);
+
+					var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%u", arg_num, arg));
+					break;
+				}
+				case DBUS_TYPE_INT64: {
+					dbus_int64_t arg = 0;
+					dbus_message_iter_get_basic(&message_iter, &arg);
+
+					var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%ld", arg_num, arg));
+					break;
+				}
+				case DBUS_TYPE_UINT64: {
+					dbus_uint64_t arg = 0;
+					dbus_message_iter_get_basic(&message_iter, &arg);
+
+					var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%lu", arg_num, arg));
+					break;
+				}
+				case DBUS_TYPE_DOUBLE: {
+					double arg = 0;
+					dbus_message_iter_get_basic(&message_iter, &arg);
+
+					var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%f", arg_num, arg));
+					break;
+				}
+				case DBUS_TYPE_STRING: {
+					const char * arg = NULL;
+					dbus_message_iter_get_basic(&message_iter, &arg);
+
+					var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%s", arg_num, arg));
+					break;
+				}
+				case DBUS_TYPE_OBJECT_PATH: {
+					const char * arg = NULL;
+					dbus_message_iter_get_basic(&message_iter, &arg);
+
+					var = NIH_MUST (nih_sprintf (NULL, "ARG%d=%s", arg_num, arg));
+					break;
+				}
+				/* NOTE: Only supporting strings for now, we can consider other
+				   types in the future by extending this switch */
+			}
+
+			if (var != NULL) {
+				NIH_MUST (nih_str_array_addp (&env, NULL, &env_len, var));
+			}
+
+			dbus_message_iter_next(&message_iter);
+			arg_num++;
+		}
+	}
+
 	nih_debug ("Received D-Bus signal: %s "
 		   "(sender=%s, destination=%s, interface=%s, path=%s)",
 		   signal ? signal : "",

-- 
upstart-devel mailing list
[email protected]
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/upstart-devel

Reply via email to