From 07e941c1bbdc752142bbd3b838c540bc7ecd0ed7 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Tue, 18 Feb 2014 14:32:54 +0100 Subject: sbus: Refactor how we export DBus interfaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most importantly, stop using per connection private data. This doesn't scale when you have more than one thing exporting or exported on a connection. Remove struct sbus_interface and expand sbus_conn_add_interface() function. Remove various struct sbus_interface args to connection initialization functions and make callers use sbus_conn_add_interface() directly. The old method was optimized for exporting one interface on a connection. We'll have connections that export zero, one or more interfaces. To export an interface on a DBus server, call sbus_conn_add_interface() from within the sbus_server_conn_init_fn. To export an interface on a DBus client, call sbus_conn_add_interface() after sbus_new_connection() returns. As before struct sbus_interface represents an object exported via DBus. However it is now talloc allocated. One can set instance data on the struct sbus_interface. This instance data is passed to the various handlers and used in their implementation. However, we now have type safe interface exporting in the various high level sss_process_init() sss_monitor_init() and so on. Introspection support was not in use, and is now gone until we implement it using the metadata (future patch). Reviewed-by: Jakub Hrozek Reviewed-by: Pavel Březina Reviewed-by: Lukáš Slebodník --- src/sbus/sssd_dbus.h | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/sbus/sssd_dbus.h') diff --git a/src/sbus/sssd_dbus.h b/src/sbus/sssd_dbus.h index dcb669079..ef728bd30 100644 --- a/src/sbus/sssd_dbus.h +++ b/src/sbus/sssd_dbus.h @@ -23,12 +23,13 @@ #define _SSSD_DBUS_H_ struct sbus_connection; - +struct sbus_interface; struct sbus_request; #include -typedef int (*sbus_msg_handler_fn)(struct sbus_request *dbus_req); +typedef int (*sbus_msg_handler_fn)(struct sbus_request *dbus_req, + void *instance_data); /* * sbus_conn_destructor_fn @@ -79,14 +80,28 @@ struct sbus_vtable { struct sbus_interface { const char *path; struct sbus_vtable *vtable; - sbus_msg_handler_fn introspect_fn; + void *instance_data; }; +/* + * Creates a new struct sbus_interface instance to be exported by a DBus + * service. + * + * Pass the result to sbus_conn_add_interface(). The interface + * will be exported at @object_path. The method handlers are represented by + * @iface_vtable. @instance_data contains additional caller specific data + * which is made available to handlers. + */ +struct sbus_interface * +sbus_new_interface(TALLOC_CTX *mem_ctx, + const char *object_path, + struct sbus_vtable *iface_vtable, + void *instance_data); + /* Server Functions */ int sbus_new_server(TALLOC_CTX *mem_ctx, struct tevent_context *ev, const char *address, - struct sbus_interface *intf, bool use_symlink, struct sbus_connection **server, sbus_server_conn_init_fn init_fn, void *init_pvt_data); @@ -103,7 +118,6 @@ int sbus_new_server(TALLOC_CTX *mem_ctx, int sbus_new_connection(TALLOC_CTX *ctx, struct tevent_context *ev, const char *address, - struct sbus_interface *intf, struct sbus_connection **conn); /* sbus_add_connection @@ -121,19 +135,11 @@ int sbus_new_connection(TALLOC_CTX *ctx, int sbus_init_connection(TALLOC_CTX *ctx, struct tevent_context *ev, DBusConnection *dbus_conn, - struct sbus_interface *intf, int connection_type, struct sbus_connection **_conn); -void sbus_conn_set_destructor(struct sbus_connection *conn, - sbus_conn_destructor_fn destructor); - -int sbus_default_connection_destructor(void *ctx); - DBusConnection *sbus_get_connection(struct sbus_connection *conn); void sbus_disconnect(struct sbus_connection *conn); -void sbus_conn_set_private_data(struct sbus_connection *conn, void *pvt_data); -void *sbus_conn_get_private_data(struct sbus_connection *conn); int sbus_conn_add_interface(struct sbus_connection *conn, struct sbus_interface *intf); bool sbus_conn_disconnecting(struct sbus_connection *conn); -- cgit