summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2007-05-07 10:52:10 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2007-05-07 10:52:10 +0000
commit55466e2f43cf52b563954a9c2d1a722f6c646f7c (patch)
tree28d0addef2787b7b467e4fe4606cf4217ca55775
parent9306a904c561b8d6552c0de2584ee875d2034751 (diff)
Implement generic signal sending function which also checks for signal interface, name and paramter type conformance
-rw-r--r--common/dbus-helper.c90
-rw-r--r--common/dbus-helper.h11
2 files changed, 101 insertions, 0 deletions
diff --git a/common/dbus-helper.c b/common/dbus-helper.c
index 40cd3eac..fb7bce98 100644
--- a/common/dbus-helper.c
+++ b/common/dbus-helper.c
@@ -449,3 +449,93 @@ void dbus_message_iter_append_dict_entry(DBusMessageIter *dict,
dbus_message_iter_close_container(dict, &entry);
}
+
+dbus_bool_t dbus_connection_emit_signal_valist(DBusConnection *conn,
+ const char *path,
+ const char *interface,
+ const char *name,
+ int first,
+ va_list var_args)
+{
+ struct generic_data *data;
+ struct interface_data *iface;
+ DBusMessageIter iter;
+ DBusSignalVTable *sig_data;
+ DBusMessage *signal;
+ int type;
+ const char *args = NULL;
+
+ if (dbus_connection_get_object_path_data(conn, path,
+ (void *) &data) == FALSE) {
+ error("dbus_connection_emit_signal: path %s isn't registered", path);
+ return FALSE;
+ }
+
+ iface = find_interface(data->interfaces, interface);
+
+ if (!iface) {
+ error("dbus_connection_emit_signal: %s does not implement %s",
+ path, interface);
+ return FALSE;
+ }
+
+ for (sig_data = iface->signals; sig_data && sig_data->name; sig_data++) {
+ if (!strcmp(sig_data->name, name)) {
+ args = sig_data->signature;
+ break;
+ }
+ }
+
+ if (!args) {
+ error("No signal named %s on interface %s", name, interface);
+ return FALSE;
+ }
+
+ signal = dbus_message_new_signal(path, interface, name);
+ if (!signal) {
+ error("Unable to allocate new %s.%s signal", interface, name);
+ return FALSE;
+ }
+
+ dbus_message_iter_init_append(signal, &iter);
+
+ for (type = first; type != DBUS_TYPE_INVALID;
+ type = va_arg(var_args, int), args++) {
+ void *value;
+
+ if (type != *args) {
+ error("Expected arg type '%c' but got '%c'", *args, type);
+ dbus_message_unref(signal);
+ return FALSE;
+ }
+
+ value = va_arg(var_args, void *);
+
+ if (!dbus_message_iter_append_basic(&iter, type, value)) {
+ error("Append property argument error (type %d)", type);
+ dbus_message_unref(signal);
+ return FALSE;
+ }
+ }
+
+ dbus_connection_send(conn, signal, NULL);
+ dbus_message_unref(signal);
+
+ return TRUE;
+}
+
+dbus_bool_t dbus_connection_emit_signal(DBusConnection *conn, const char *path,
+ const char *interface, const char *name,
+ int first, ...)
+{
+ dbus_bool_t ret;
+ va_list var_args;
+
+ va_start(var_args, first);
+ ret = dbus_connection_emit_signal_valist(conn, path, interface, name,
+ first, var_args);
+ va_end(var_args);
+
+ return ret;
+}
+
diff --git a/common/dbus-helper.h b/common/dbus-helper.h
index 49db1c58..4dd9d155 100644
--- a/common/dbus-helper.h
+++ b/common/dbus-helper.h
@@ -20,6 +20,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
+#include <stdarg.h>
#define DBUS_TYPE_STRING_ARRAY_AS_STRING (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING)
#define DBUS_TYPE_BYTE_ARRAY_AS_STRING (DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING)
@@ -71,3 +72,13 @@ dbus_bool_t dbus_connection_unregister_interface(DBusConnection *connection,
void dbus_message_iter_append_dict_entry(DBusMessageIter *dict,
const char *key, int type, void *val);
+dbus_bool_t dbus_connection_emit_signal(DBusConnection *conn, const char *path,
+ const char *interface, const char *name,
+ int first, ...);
+
+dbus_bool_t dbus_connection_emit_signal_valist(DBusConnection *conn,
+ const char *path,
+ const char *interface,
+ const char *name,
+ int first,
+ va_list var_args);