Commit 8d38a2e2 authored by Havoc Pennington's avatar Havoc Pennington

2003-08-28 Havoc Pennington <hp@pobox.com>

	purge DBusObjectID

	* dbus/dbus-connection.c: port to no ObjectID, create a
	DBusObjectTree, rename ObjectTree to ObjectPath in public API

	* dbus/dbus-connection.h (struct DBusObjectTreeVTable): delete
	everything except UnregisterFunction and MessageFunction

	* dbus/dbus-marshal.c: port away from DBusObjectID,
	add DBUS_TYPE_OBJECT_PATH

	* dbus/dbus-object-registry.[hc], dbus/dbus-object.[hc],
	dbus/dbus-objectid.[hc]: remove these, we are moving to
	path-based object IDs
parent 24f411a6
2003-08-28 Havoc Pennington <hp@pobox.com>
purge DBusObjectID
* dbus/dbus-connection.c: port to no ObjectID, create a
DBusObjectTree, rename ObjectTree to ObjectPath in public API
* dbus/dbus-connection.h (struct DBusObjectTreeVTable): delete
everything except UnregisterFunction and MessageFunction
* dbus/dbus-marshal.c: port away from DBusObjectID,
add DBUS_TYPE_OBJECT_PATH
* dbus/dbus-object-registry.[hc], dbus/dbus-object.[hc],
dbus/dbus-objectid.[hc]: remove these, we are moving to
path-based object IDs
2003-08-25 Havoc Pennington <hp@pobox.com>
Just noticed that dbus_message_test is hosed, I wonder when I
......
......@@ -17,8 +17,6 @@ dbusinclude_HEADERS= \
dbus-memory.h \
dbus-message.h \
dbus-message-handler.h \
dbus-object.h \
dbus-objectid.h \
dbus-pending-call.h \
dbus-protocol.h \
dbus-server.h \
......@@ -45,10 +43,6 @@ DBUS_LIB_SOURCES= \
dbus-message.c \
dbus-message-handler.c \
dbus-message-internal.h \
dbus-object.c \
dbus-objectid.c \
dbus-object-registry.c \
dbus-object-registry.h \
dbus-object-tree.c \
dbus-object-tree.h \
dbus-pending-call.c \
......
......@@ -25,6 +25,7 @@
#include "dbus-bus.h"
#include "dbus-protocol.h"
#include "dbus-internals.h"
#include "dbus-message.h"
#include <string.h>
/**
......
......@@ -86,8 +86,7 @@ void _dbus_message_handler_remove_connection (DBusMessageHandl
DBusHandlerResult _dbus_message_handler_handle_message (DBusMessageHandler *handler,
DBusConnection *connection,
DBusMessage *message);
void _dbus_connection_init_id (DBusConnection *connection,
DBusObjectID *id);
DBusPendingCall* _dbus_pending_call_new (DBusConnection *connection,
int timeout_milliseconds,
DBusTimeoutHandler timeout_handler);
......
......@@ -35,9 +35,9 @@
#include "dbus-threads.h"
#include "dbus-protocol.h"
#include "dbus-dataslot.h"
#include "dbus-object-registry.h"
#include "dbus-string.h"
#include "dbus-pending-call.h"
#include "dbus-object-tree.h"
#if 0
#define CONNECTION_LOCK(connection) do { \
......@@ -179,7 +179,7 @@ struct DBusConnection
DBusList *link_cache; /**< A cache of linked list links to prevent contention
* for the global linked list mempool lock
*/
DBusObjectRegistry *objects; /**< Objects registered with this connection */
DBusObjectTree *objects; /**< Object path handlers registered with this connection */
};
static void _dbus_connection_remove_timeout_locked (DBusConnection *connection,
......@@ -775,7 +775,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
DBusList *disconnect_link;
DBusMessage *disconnect_message;
DBusCounter *outgoing_counter;
DBusObjectRegistry *objects;
DBusObjectTree *objects;
watch_list = NULL;
connection = NULL;
......@@ -839,7 +839,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
if (outgoing_counter == NULL)
goto error;
objects = _dbus_object_registry_new (connection);
objects = _dbus_object_tree_new (connection);
if (objects == NULL)
goto error;
......@@ -908,7 +908,7 @@ _dbus_connection_new_for_transport (DBusTransport *transport)
_dbus_counter_unref (outgoing_counter);
if (objects)
_dbus_object_registry_unref (objects);
_dbus_object_tree_unref (objects);
return NULL;
}
......@@ -1048,25 +1048,6 @@ _dbus_connection_handle_watch (DBusWatch *watch,
return retval;
}
/**
* Get the server ID to be used in the object ID for an object
* registered with this connection.
*
* @todo implement this function
*
* @param connection the connection.
* @returns the portion of the object ID
*/
void
_dbus_connection_init_id (DBusConnection *connection,
DBusObjectID *object_id)
{
/* FIXME */
dbus_object_id_set_server_bits (object_id, 15);
dbus_object_id_set_client_bits (object_id, 31);
dbus_object_id_set_is_server_bit (object_id, FALSE);
}
/** @} */
/**
......@@ -1178,7 +1159,7 @@ _dbus_connection_last_unref (DBusConnection *connection)
_dbus_assert (!_dbus_transport_get_is_connected (connection->transport));
/* ---- We're going to call various application callbacks here, hope it doesn't break anything... */
_dbus_object_registry_free_all_unlocked (connection->objects);
_dbus_object_tree_free_all_unlocked (connection->objects);
dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
dbus_connection_set_wakeup_main_function (connection, NULL, NULL, NULL);
......@@ -1204,7 +1185,7 @@ _dbus_connection_last_unref (DBusConnection *connection)
link = next;
}
_dbus_object_registry_unref (connection->objects);
_dbus_object_tree_unref (connection->objects);
_dbus_hash_table_unref (connection->pending_replies);
connection->pending_replies = NULL;
......@@ -2547,8 +2528,8 @@ dbus_connection_dispatch (DBusConnection *connection)
dbus_message_get_interface (message) :
"no interface");
result = _dbus_object_registry_handle_and_unlock (connection->objects,
message);
result = _dbus_object_tree_dispatch_and_unlock (connection->objects,
message);
CONNECTION_LOCK (connection);
......@@ -3026,67 +3007,58 @@ dbus_connection_remove_filter (DBusConnection *connection,
}
/**
* Registers an object with the connection. This object is assigned an
* object ID, and will be visible under this ID and with the provided
* interfaces to the peer application on the other end of the
* connection. The object instance should be passed in as object_impl;
* the instance can be any datatype, as long as it fits in a void*.
* Registers a handler for a given subsection of the object hierarchy.
* The given vtable handles messages at or below the given path.
*
* As a side effect of calling this function, the "registered"
* callback in the #DBusObjectVTable will be invoked.
*
* If the object is deleted, be sure to unregister it with
* dbus_connection_unregister_object() or it will continue to get
* messages.
*
* @param connection the connection to register the instance with
* @param interfaces #NULL-terminated array of interface names the instance supports
* @param vtable virtual table of functions for manipulating the instance
* @param object_impl object instance
* @param object_id if non-#NULL, object ID to initialize with the new object's ID
* @returns #FALSE if not enough memory to register the object instance
* @param connection the connection
* @param path #NULL-terminated array of path elements
* @param vtable the virtual table
* @param user_data data to pass to functions in the vtable
* @returns #FALSE if not enough memory
*/
dbus_bool_t
dbus_connection_register_object (DBusConnection *connection,
const char **interfaces,
const DBusObjectVTable *vtable,
void *object_impl,
DBusObjectID *object_id)
dbus_connection_register_object_path (DBusConnection *connection,
const char **path,
const DBusObjectPathVTable *vtable,
void *user_data)
{
dbus_bool_t retval;
_dbus_return_val_if_fail (connection != NULL, FALSE);
_dbus_return_val_if_fail (path != NULL, FALSE);
_dbus_return_val_if_fail (path[0] != NULL, FALSE);
_dbus_return_val_if_fail (vtable != NULL, FALSE);
_dbus_return_val_if_fail (vtable->dbus_internal_pad1 == NULL, FALSE);
_dbus_return_val_if_fail (vtable->dbus_internal_pad2 == NULL, FALSE);
_dbus_return_val_if_fail (vtable->dbus_internal_pad3 == NULL, FALSE);
CONNECTION_LOCK (connection);
return _dbus_object_registry_add_and_unlock (connection->objects,
interfaces,
vtable,
object_impl,
object_id);
retval = _dbus_object_tree_register (connection->objects, path, vtable,
user_data);
CONNECTION_UNLOCK (connection);
return retval;
}
/**
* Reverses the effects of dbus_connection_register_object(),
* and invokes the "unregistered" callback in the #DBusObjectVTable
* for the given object. The passed-in object ID must be a valid,
* registered object ID or the results are undefined.
* Unregisters the handler registered with exactly the given path.
* It's a bug to call this function for a path that isn't registered.
*
* @param connection the connection to unregister the object ID from
* @param object_id the object ID to unregister
* @param connection the connection
* @param path the #NULL-terminated array of path elements
*/
void
dbus_connection_unregister_object (DBusConnection *connection,
const DBusObjectID *object_id)
dbus_connection_unregister_object_path (DBusConnection *connection,
const char **path)
{
_dbus_return_if_fail (connection != NULL);
_dbus_return_if_fail (connection != NULL);
_dbus_return_if_fail (path != NULL);
_dbus_return_if_fail (path[0] != NULL);
CONNECTION_LOCK (connection);
return _dbus_object_registry_remove_and_unlock (connection->objects,
object_id);
return _dbus_object_tree_unregister_and_unlock (connection->objects,
path);
}
static DBusDataSlotAllocator slot_allocator;
......
/* -*- mode: C; c-file-style: "gnu" -*- */
/* dbus-connection.h DBusConnection object
*
* Copyright (C) 2002 Red Hat Inc.
* Copyright (C) 2002, 2003 Red Hat Inc.
*
* Licensed under the Academic Free License version 1.2
*
......@@ -29,7 +29,7 @@
#include <dbus/dbus-errors.h>
#include <dbus/dbus-memory.h>
#include <dbus/dbus-object.h>
#include <dbus/dbus-message.h>
DBUS_BEGIN_DECLS;
......@@ -38,6 +38,8 @@ typedef struct DBusTimeout DBusTimeout;
typedef struct DBusMessageHandler DBusMessageHandler;
typedef struct DBusPreallocatedSend DBusPreallocatedSend;
typedef struct DBusPendingCall DBusPendingCall;
typedef struct DBusConnection DBusConnection;
typedef struct DBusObjectPathVTable DBusObjectPathVTable;
typedef enum
{
......@@ -57,6 +59,13 @@ typedef enum
DBUS_DISPATCH_NEED_MEMORY /**< More memory is needed to continue. */
} DBusDispatchStatus;
typedef enum
{
DBUS_HANDLER_RESULT_HANDLED, /**< Message has had its effect */
DBUS_HANDLER_RESULT_NOT_YET_HANDLED, /**< Message has not had any effect */
DBUS_HANDLER_RESULT_NEED_MEMORY /**< Need more memory to return another result */
} DBusHandlerResult;
typedef dbus_bool_t (* DBusAddWatchFunction) (DBusWatch *watch,
void *data);
typedef void (* DBusWatchToggledFunction) (DBusWatch *watch,
......@@ -159,16 +168,6 @@ dbus_bool_t dbus_connection_add_filter (DBusConnection *connection,
void dbus_connection_remove_filter (DBusConnection *connection,
DBusMessageHandler *handler);
/* Objects */
dbus_bool_t dbus_connection_register_object (DBusConnection *connection,
const char **interfaces,
const DBusObjectVTable *vtable,
void *object_impl,
DBusObjectID *object_id);
void dbus_connection_unregister_object (DBusConnection *connection,
const DBusObjectID *object_id);
/* Other */
dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t *slot_p);
void dbus_connection_free_data_slot (dbus_int32_t *slot_p);
......@@ -200,37 +199,17 @@ void dbus_connection_send_preallocated (DBusConnection
/* Object tree functionality */
typedef struct DBusObjectTreeVTable DBusObjectTreeVTable;
typedef void (* DBusObjectTreeUnregisterFunction) (DBusConnection *connection,
typedef void (* DBusObjectPathUnregisterFunction) (DBusConnection *connection,
const char **path,
void *user_data);
typedef DBusHandlerResult (* DBusObjectTreeMessageFunction) (DBusConnection *connection,
typedef DBusHandlerResult (* DBusObjectPathMessageFunction) (DBusConnection *connection,
DBusMessage *message,
void *user_data);
typedef dbus_bool_t (* DBusObjectTreeSubdirsFunction) (DBusConnection *connection,
const char **path,
char ***subdirs,
int *n_subdirs,
void *user_data);
typedef dbus_bool_t (* DBusObjectTreeObjectsFunction) (DBusConnection *connection,
const char **path,
DBusObjectID **object_ids,
int *n_object_ids,
void *user_data);
typedef dbus_bool_t (* DBusObjectTreeMethodsFunction) (DBusConnection *connection,
const char **path,
DBusObjectID **object_ids,
int *n_object_ids,
void *user_data);
struct DBusObjectTreeVTable
struct DBusObjectPathVTable
{
DBusObjectTreeUnregisterFunction unregister_function;
DBusObjectTreeMessageFunction message_function;
DBusObjectTreeSubdirsFunction subdirs_function;
DBusObjectTreeObjectsFunction objects_function;
DBusObjectTreeMethodsFunction methods_function;
DBusObjectPathUnregisterFunction unregister_function;
DBusObjectPathMessageFunction message_function;
void (* dbus_internal_pad1) (void *);
void (* dbus_internal_pad2) (void *);
......@@ -238,11 +217,11 @@ struct DBusObjectTreeVTable
void (* dbus_internal_pad4) (void *);
};
dbus_bool_t dbus_connection_register_object_tree (DBusConnection *connection,
dbus_bool_t dbus_connection_register_object_path (DBusConnection *connection,
const char **path,
const DBusObjectTreeVTable *vtable,
const DBusObjectPathVTable *vtable,
void *user_data);
void dbus_connection_unregister_object_tree (DBusConnection *connection,
void dbus_connection_unregister_object_path (DBusConnection *connection,
const char **path);
......
......@@ -234,7 +234,6 @@ _DBUS_DECLARE_GLOBAL_LOCK (server_slots);
_DBUS_DECLARE_GLOBAL_LOCK (message_slots);
_DBUS_DECLARE_GLOBAL_LOCK (atomic);
_DBUS_DECLARE_GLOBAL_LOCK (message_handler);
_DBUS_DECLARE_GLOBAL_LOCK (callback_object);
_DBUS_DECLARE_GLOBAL_LOCK (bus);
_DBUS_DECLARE_GLOBAL_LOCK (shutdown_funcs);
_DBUS_DECLARE_GLOBAL_LOCK (system_users);
......
......@@ -80,7 +80,6 @@ typedef union
dbus_uint64_t u;
#endif
double d;
DBusObjectID object_id;
} DBusOctets8;
static DBusOctets8
......@@ -426,26 +425,27 @@ _dbus_marshal_set_string (DBusString *str,
}
/**
* Sets the existing marshaled object ID at the given offset to a new
* value. The given offset must point to an existing object ID or this
* Sets the existing marshaled object path at the given offset to a new
* value. The given offset must point to an existing object path or this
* function doesn't make sense.
*
* @param str the string to write the marshalled string to
* @param offset the byte offset where string should be written
* @todo implement this function
*
* @param str the string to write the marshalled path to
* @param offset the byte offset where path should be written
* @param byte_order the byte order to use
* @param value the new value
* @param path the new path
* @param path_len number of elements in the path
*/
void
_dbus_marshal_set_object_id (DBusString *str,
int byte_order,
int offset,
const DBusObjectID *value)
_dbus_marshal_set_object_path (DBusString *str,
int byte_order,
int offset,
const char **path,
int path_len)
{
DBusOctets8 r;
r.object_id = *value;
set_8_octets (str, byte_order, offset, r);
/* FIXME */
}
static dbus_bool_t
......@@ -870,23 +870,23 @@ _dbus_marshal_string_array (DBusString *str,
}
/**
* Marshals an object ID value.
* Marshals an object path value.
*
* @todo implement this function
*
* @param str the string to append the marshalled value to
* @param byte_order the byte order to use
* @param value the value
* @param path the path
* @param path_len length of the path
* @returns #TRUE on success
*/
dbus_bool_t
_dbus_marshal_object_id (DBusString *str,
int byte_order,
const DBusObjectID *value)
_dbus_marshal_object_path (DBusString *str,
int byte_order,
const char **path,
int path_len)
{
DBusOctets8 r;
r.object_id = *value;
return marshal_8_octets (str, byte_order, r);
return TRUE;
}
static dbus_uint32_t
......@@ -1439,26 +1439,26 @@ _dbus_demarshal_string_array (const DBusString *str,
}
/**
* Demarshals an object ID.
* Demarshals an object path.
*
* @todo implement this function
*
* @param str the string containing the data
* @param byte_order the byte order
* @param pos the position in the string
* @param new_pos the new position of the string
* @param value address to store new object ID
* @param path address to store new object path
* @param path_len length of stored path
*/
void
_dbus_demarshal_object_id (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
DBusObjectID *value)
dbus_bool_t
_dbus_demarshal_object_path (const DBusString *str,
int byte_order,
int pos,
int *new_pos,
char ***path,
int *path_len)
{
DBusOctets8 r;
r = demarshal_8_octets (str, byte_order, pos, new_pos);
*value = r.object_id;
}
/**
......@@ -1509,7 +1509,6 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str,
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_OBJECT_ID:
case DBUS_TYPE_DOUBLE:
*end_pos = _DBUS_ALIGN_VALUE (pos, 8) + 8;
......@@ -1541,7 +1540,8 @@ _dbus_marshal_get_arg_end_pos (const DBusString *str,
*end_pos = pos + len;
}
break;
case DBUS_TYPE_OBJECT_PATH:
case DBUS_TYPE_ARRAY:
{
int len;
......@@ -1718,6 +1718,7 @@ validate_array_data (const DBusString *str,
case DBUS_TYPE_NIL:
break;
case DBUS_TYPE_OBJECT_PATH:
case DBUS_TYPE_STRING:
case DBUS_TYPE_NAMED:
case DBUS_TYPE_ARRAY:
......@@ -1771,7 +1772,6 @@ validate_array_data (const DBusString *str,
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:
case DBUS_TYPE_OBJECT_ID:
/* Call validate arg one time to check alignment padding
* at start of array
*/
......@@ -1802,7 +1802,9 @@ validate_array_data (const DBusString *str,
*
* @todo For array types that can't be invalid, we should not
* walk the whole array validating it. e.g. just skip all the
* int values in an int array.
* int values in an int array. (maybe this is already done now -hp)
*
* @todo support DBUS_TYPE_OBJECT_PATH
*
* @param str a string
* @param byte_order the byte order to use
......@@ -1899,7 +1901,6 @@ _dbus_marshal_validate_arg (const DBusString *str,
case DBUS_TYPE_INT64:
case DBUS_TYPE_UINT64:
case DBUS_TYPE_DOUBLE:
case DBUS_TYPE_OBJECT_ID:
{
int align_8 = _DBUS_ALIGN_VALUE (pos, 8);
......@@ -2219,7 +2220,6 @@ _dbus_marshal_test (void)
#endif
char *s;
DBusString t;
DBusObjectID obj_id, obj_id2;
if (!_dbus_string_init (&str))
_dbus_assert_not_reached ("failed to init string");
......@@ -2280,23 +2280,6 @@ _dbus_marshal_test (void)
if (!(_dbus_demarshal_uint64 (&str, DBUS_LITTLE_ENDIAN, pos, &pos) == DBUS_UINT64_CONSTANT (0x123456789abc7)))
_dbus_assert_not_reached ("demarshal failed");
#endif /* DBUS_HAVE_INT64 */
/* Marshal object IDs */
dbus_object_id_set_server_bits (&obj_id, 0xfffe);
dbus_object_id_set_client_bits (&obj_id, 0xaacc);
dbus_object_id_set_instance_bits (&obj_id, 0x70f00f0f);
if (!_dbus_marshal_object_id (&str, DBUS_BIG_ENDIAN, &obj_id))
_dbus_assert_not_reached ("could not marshal object ID value");
_dbus_demarshal_object_id (&str, DBUS_BIG_ENDIAN, pos, &pos, &obj_id2);
if (!dbus_object_id_equal (&obj_id, &obj_id2))
_dbus_assert_not_reached ("demarshal failed");
if (!_dbus_marshal_object_id (&str, DBUS_LITTLE_ENDIAN, &obj_id))
_dbus_assert_not_reached ("could not marshal object ID value");
_dbus_demarshal_object_id (&str, DBUS_LITTLE_ENDIAN, pos, &pos, &obj_id2);
if (!dbus_object_id_equal (&obj_id, &obj_id2))
_dbus_assert_not_reached ("demarshal failed");
/* Marshal strings */
tmp1 = "This is the dbus test string";
......
......@@ -29,7 +29,6 @@
#include <dbus/dbus-types.h>
#include <dbus/dbus-arch-deps.h>
#include <dbus/dbus-string.h>
#include <dbus/dbus-objectid.h>
#ifndef PACKAGE
#error "config.h not included here"
......@@ -154,15 +153,16 @@ void _dbus_marshal_set_uint64 (DBusString *str,
dbus_uint64_t value);
#endif /* DBUS_HAVE_INT64 */
dbus_bool_t _dbus_marshal_set_string (DBusString *str,
int byte_order,
int offset,
const DBusString *value,
int len);
void _dbus_marshal_set_object_id (DBusString *str,
int byte_order,
int offset,
const DBusObjectID *value);
dbus_bool_t _dbus_marshal_set_string (DBusString *str,
int byte_order,
int offset,
const DBusString *value,
int len);
void _dbus_marshal_set_object_path (DBusString *str,
int byte_order,
int offset,
const char **path,
int path_len);
dbus_bool_t _dbus_marshal_int32 (DBusString *str,
int byte_order,
......@@ -214,9 +214,10 @@ dbus_bool_t _dbus_marshal_string_array (DBusString *str,
int byte_order,
const char **value,
int len);
dbus_bool_t _dbus_marshal_object_id (DBusString *str,
dbus_bool_t _dbus_marshal_object_path (DBusString *str,
int byte_order,
const DBusObjectID *value);
const char **path,
int path_len);