diff options
author | Havoc Pennington <hp@redhat.com> | 2003-09-22 03:11:12 +0000 |
---|---|---|
committer | Havoc Pennington <hp@redhat.com> | 2003-09-22 03:11:12 +0000 |
commit | c9332907b035b52103c5569119d0a7c9fbcb76ac (patch) | |
tree | 81a1da4fc3babbf73204e085026a6e9400c5556b /dbus | |
parent | 25cb861980003f81eade8707bfa1a61c9ece1779 (diff) | |
download | dbus-c9332907b035b52103c5569119d0a7c9fbcb76ac.tar.gz |
2003-09-21 Havoc Pennington <hp@pobox.com>
* glib/dbus-gproxy.c (dbus_gproxy_manager_new): start
implementing the proxy manager, didn't get very far.
* dbus/dbus-bus.c (dbus_bus_add_match): new
(dbus_bus_remove_match): new
* glib/dbus-gproxy.c (dbus_gproxy_new_for_service): add a
path_name argument; adjust the other not-yet-implemented
gproxy constructors to be what I think they should be.
Diffstat (limited to 'dbus')
-rw-r--r-- | dbus/dbus-bus.c | 122 | ||||
-rw-r--r-- | dbus/dbus-bus.h | 7 |
2 files changed, 128 insertions, 1 deletions
diff --git a/dbus/dbus-bus.c b/dbus/dbus-bus.c index 6d7cb82c..a8b9e452 100644 --- a/dbus/dbus-bus.c +++ b/dbus/dbus-bus.c @@ -681,7 +681,7 @@ dbus_bus_activate_service (DBusConnection *connection, } reply = dbus_connection_send_with_reply_and_block (connection, msg, - -1, error); + -1, error); dbus_message_unref (msg); if (reply == NULL) @@ -710,5 +710,125 @@ dbus_bus_activate_service (DBusConnection *connection, return TRUE; } +static void +send_no_return_values (DBusConnection *connection, + DBusMessage *msg, + DBusError *error) +{ + if (error) + { + /* Block to check success codepath */ + DBusMessage *reply; + + reply = dbus_connection_send_with_reply_and_block (connection, msg, + -1, error); + + if (reply == NULL) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return; + } + + if (dbus_set_error_from_message (error, reply)) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + dbus_message_unref (reply); + return; + } + + dbus_message_unref (reply); + } + else + { + /* Silently-fail nonblocking codepath */ + if (!dbus_connection_send (connection, msg, NULL)) + return; + } +} + +/** + * Adds a match rule to match messages going through the message bus. + * The "rule" argument is the string form of a match rule. + * + * If you pass #NULL for the error, this function will not + * block; the match thus won't be added until you flush the + * connection, and if there's an error adding the match + * (only possible error is lack of resources in the bus), + * you won't find out about it. + * + * If you pass non-#NULL for the error this function will + * block until it gets a reply. + * + * Normal API conventions would have the function return + * a boolean value indicating whether the error was set, + * but that would require blocking always to determine + * the return value. + * + * @param connection connection to the message bus + * @param rule textual form of match rule + * @param error location to store any errors + */ +void +dbus_bus_add_match (DBusConnection *connection, + const char *rule, + DBusError *error) +{ + DBusMessage *msg; + + msg = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS, + DBUS_PATH_ORG_FREEDESKTOP_DBUS, + DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, + "AddMatch"); + + if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, rule, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (msg); + _DBUS_SET_OOM (error); + return; + } + + send_no_return_values (connection, msg, error); + + dbus_message_unref (msg); +} + +/** + * Removes a previously-added match rule "by value" (the most + * recently-added identical rule gets removed). The "rule" argument + * is the string form of a match rule. + * + * If you pass #NULL for the error, this function will not + * block; otherwise it will. See detailed explanation in + * docs for dbus_bus_add_match(). + * + * @param connection connection to the message bus + * @param rule textual form of match rule + * @param error location to store any errors + */ +void +dbus_bus_remove_match (DBusConnection *connection, + const char *rule, + DBusError *error) +{ + DBusMessage *msg; + + msg = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS, + DBUS_PATH_ORG_FREEDESKTOP_DBUS, + DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS, + "RemoveMatch"); + + if (!dbus_message_append_args (msg, DBUS_TYPE_STRING, rule, + DBUS_TYPE_INVALID)) + { + dbus_message_unref (msg); + _DBUS_SET_OOM (error); + return; + } + + send_no_return_values (connection, msg, error); + + dbus_message_unref (msg); +} /** @} */ diff --git a/dbus/dbus-bus.h b/dbus/dbus-bus.h index a62a746b..072b0c8e 100644 --- a/dbus/dbus-bus.h +++ b/dbus/dbus-bus.h @@ -59,6 +59,13 @@ dbus_bool_t dbus_bus_activate_service (DBusConnection *connection, dbus_uint32_t *reply, DBusError *error); +void dbus_bus_add_match (DBusConnection *connection, + const char *rule, + DBusError *error); +void dbus_bus_remove_match (DBusConnection *connection, + const char *rule, + DBusError *error); + DBUS_END_DECLS; #endif /* DBUS_BUS_H */ |