diff options
| author | Lennart Poettering <lennart@poettering.net> | 2009-04-22 03:56:18 +0200 | 
|---|---|---|
| committer | Lennart Poettering <lennart@poettering.net> | 2009-05-20 02:09:30 +0200 | 
| commit | 08e49d9b53b675ee2292ac35173dfb4ab97e8d13 (patch) | |
| tree | e2847e9bfd5319a2a3b9194192fb9173868bbb7c | |
| parent | a0cc21f8bb6752ffe0ee5f4f5b575dc50d6d46ae (diff) | |
unix-fd: introduce dbus_connection_can_send_type()
This is just a wrapper around _dbus_transport_can_pass_unix_fd() however
it is more generic.
The reason for keeping this generic is to ease later addition of more
types without having to add a new API for that.
| -rw-r--r-- | dbus/dbus-connection.c | 50 | ||||
| -rw-r--r-- | dbus/dbus-connection.h | 2 | 
2 files changed, 50 insertions, 2 deletions
diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index afa0ca6a..fc872bc2 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -33,6 +33,7 @@  #include "dbus-list.h"  #include "dbus-hash.h"  #include "dbus-message-internal.h" +#include "dbus-message-private.h"  #include "dbus-threads.h"  #include "dbus-protocol.h"  #include "dbus-dataslot.h" @@ -41,6 +42,7 @@  #include "dbus-object-tree.h"  #include "dbus-threads-internal.h"  #include "dbus-bus.h" +#include "dbus-marshal-basic.h"  #ifdef DBUS_DISABLE_CHECKS  #define TOOK_LOCK_CHECK(connection) @@ -2932,15 +2934,59 @@ dbus_connection_get_server_id (DBusConnection *connection)    char *id;    _dbus_return_val_if_fail (connection != NULL, NULL); -   +    CONNECTION_LOCK (connection);    id = _dbus_strdup (_dbus_transport_get_server_id (connection->transport));    CONNECTION_UNLOCK (connection); -   +    return id;  }  /** + * Tests whether a certain type can be send via the connection. This + * will always return TRUE for all types, with the exception of + * DBUS_TYPE_UNIX_FD. The function will return TRUE for + * DBUS_TYPE_UNIX_FD only on systems that know Unix file descriptors + * and can send them via the chosen transport and when the remote side + * supports this. + * + * This function can be used to do runtime checking for types that + * might be unknown to the specific D-Bus client implementation + * version, i.e. it will return FALSE for all types this + * implementation does not know. + * + * @param connection the connection + * @param type the type to check + * @returns TRUE if the type may be send via the connection + */ +dbus_bool_t +dbus_connection_can_send_type(DBusConnection *connection, +                                  int type) +{ +  _dbus_return_val_if_fail (connection != NULL, FALSE); + +  if (!_dbus_type_is_valid(type)) +    return FALSE; + +  if (type != DBUS_TYPE_UNIX_FD) +    return TRUE; + +#ifdef HAVE_UNIX_FD_PASSING +  { +    dbus_bool_t b; + +    CONNECTION_LOCK(connection); +    b = _dbus_transport_can_pass_unix_fd(connection->transport); +    CONNECTION_UNLOCK(connection); + +    return b; +  } +#endif + +  return FALSE; +} + +/**   * Set whether _exit() should be called when the connection receives a   * disconnect signal. The call to _exit() comes after any handlers for   * the disconnect signal run; handlers can cancel the exit by calling diff --git a/dbus/dbus-connection.h b/dbus/dbus-connection.h index b8fd35fb..c9b9aa34 100644 --- a/dbus/dbus-connection.h +++ b/dbus/dbus-connection.h @@ -180,6 +180,8 @@ dbus_bool_t        dbus_connection_get_is_connected             (DBusConnection  dbus_bool_t        dbus_connection_get_is_authenticated         (DBusConnection             *connection);  dbus_bool_t        dbus_connection_get_is_anonymous             (DBusConnection             *connection);  char*              dbus_connection_get_server_id                (DBusConnection             *connection); +dbus_bool_t        dbus_connection_can_send_type                (DBusConnection             *connection, +                                                                 int                         type);  void               dbus_connection_set_exit_on_disconnect       (DBusConnection             *connection,                                                                   dbus_bool_t                 exit_on_disconnect);  void               dbus_connection_flush                        (DBusConnection             *connection);  | 
