driver: make signal header writing generic
Allow it to deal with both unicast and broadcast headers.
@@ -235,13 +235,18 @@ static void driver_write_reply_header(CDVar *var, Peer *peer, uint32_t serial, c
c_dvar_write(var, ">)])");
}
-static void driver_write_unicast_signal_header(CDVar *var, Peer *peer, const char *member, const char *signature) {
- c_dvar_write(var, "(yyyyuu[(y<s>)(y<",
+static void driver_write_signal_header(CDVar *var, Peer *peer, const char *member, const char *signature) {
+ c_dvar_write(var, "(yyyyuu[(y<s>)",
c_dvar_is_big_endian(var) ? 'B' : 'l', DBUS_MESSAGE_TYPE_SIGNAL, DBUS_HEADER_FLAG_NO_REPLY_EXPECTED, 1, 0, (uint32_t)-1,
- DBUS_MESSAGE_FIELD_SENDER, c_dvar_type_s, "org.freedesktop.DBus",
- DBUS_MESSAGE_FIELD_DESTINATION, c_dvar_type_s);
+ DBUS_MESSAGE_FIELD_SENDER, c_dvar_type_s, "org.freedesktop.DBus");
+
+ if (peer) {
+ c_dvar_write(var, "(y<", DBUS_MESSAGE_FIELD_DESTINATION, c_dvar_type_s);
driver_dvar_write_unique_name(var, peer);
- c_dvar_write(var, ">)(y<o>)(y<s>)(y<s>)(y<g>)])",
+ c_dvar_write(var, ">)");
+ }
+
+ c_dvar_write(var, "(y<o>)(y<s>)(y<s>)(y<g>)])",
DBUS_MESSAGE_FIELD_PATH, c_dvar_type_o, "/org/freedesktop/DBus",
DBUS_MESSAGE_FIELD_INTERFACE, c_dvar_type_s, "org.freedesktop.DBus",
DBUS_MESSAGE_FIELD_MEMBER, c_dvar_type_s, member,
@@ -270,7 +275,7 @@ static int driver_notify_name_acquired(Peer *peer, const char *name) {
c_dvar_begin_write(var, type);
c_dvar_write(var, "(");
- driver_write_unicast_signal_header(var, peer, "NameAcquired", "s");
+ driver_write_signal_header(var, peer, "NameAcquired", "s");
c_dvar_write(var, "(s)", name);
c_dvar_write(var, ")");
r = c_dvar_end_write(var, &data, &n_data);
@@ -310,7 +315,7 @@ static int driver_notify_name_lost(Peer *peer, const char *name) {
c_dvar_begin_write(var, type);
c_dvar_write(var, "(");
- driver_write_unicast_signal_header(var, peer, "NameLost", "s");
+ driver_write_signal_header(var, peer, "NameLost", "s");
c_dvar_write(var, "(s)", name);
c_dvar_write(var, ")");
r = c_dvar_end_write(var, &data, &n_data);
