sssd_dbus_connection.c revision 8b8210c79b297b87e56d068e8839f7fe6755ab15
#include "events.h"
#include "dbus/sssd_dbus.h"
#include "dbus/sssd_dbus_private.h"
/* Types */
struct dbus_ctx_list;
struct sbus_conn_ctx {
struct event_context *ev;
int connection_type;
int disconnect;
struct sbus_method_ctx *method_ctx_list;
void *private; /* Private data for this connection */
};
struct sbus_conn_watch_ctx {
int fd;
struct sbus_conn_ctx *top;
};
struct sbus_conn_timeout_ctx {
struct timed_event *te;
struct sbus_conn_ctx *top;
};
static int _method_list_contains_path(struct sbus_method_ctx *list, struct sbus_method_ctx *method);
struct timed_event *te,
{
struct timed_event *new_event;
struct sbus_conn_ctx *dct_ctx;
int ret;
return;
}
DEBUG(0,("Connection is not open for dispatching.\n"));
/*
* Free the connection object.
* This will invoke the destructor for the connection
*/
return;
}
/* Dispatch only once each time through the mainloop to avoid
* starving other features
*/
if (ret != DBUS_DISPATCH_COMPLETE) {
}
/* If other dispatches are waiting, queue up the do_dispatch function
* for the next loop.
*/
if (ret != DBUS_DISPATCH_COMPLETE) {
DEBUG(0,("Could not add dispatch event!\n"));
/* TODO: Calling exit here is bad */
exit(1);
}
}
}
/*
* dbus_connection_read_write_handler
* Callback for D-BUS to handle messages on a file-descriptor
*/
{
struct sbus_conn_watch_ctx *conn_w_ctx;
if (flags & EVENT_FD_READ) {
}
if (flags & EVENT_FD_WRITE) {
}
}
/*
* add_connection_watch
* Set up hooks into the libevents mainloop for
* D-BUS to add file descriptor-based events
*/
{
unsigned int flags;
unsigned int event_flags;
struct sbus_conn_ctx *dt_ctx;
struct sbus_conn_watch_ctx *conn_w_ctx;
if (!dbus_watch_get_enabled(watch)) {
return TRUE;
}
event_flags = 0;
if (flags & DBUS_WATCH_READABLE)
if (flags & DBUS_WATCH_WRITABLE)
if (event_flags == 0)
return FALSE;
DEBUG(2,("%lX: %d, %d=%s\n", watch, conn_w_ctx->fd, event_flags, event_flags==EVENT_FD_READ?"READ":"WRITE"));
/* Add the file descriptor to the event loop */
/* Save the event to the watch object so it can be removed later */
return TRUE;
}
/*
* toggle_connection_watch
* an event in the mainloop
*/
{
if (dbus_watch_get_enabled(watch)) {
} else {
}
}
/*
* dbus_connection_timeout_handler
* Callback for D-BUS to handle timed events
*/
struct timed_event *te,
{
struct sbus_conn_timeout_ctx *conn_t_ctx;
}
/*
* add_connection_timeout
* Hook for D-BUS to add time-based events to the mainloop
*/
{
struct sbus_conn_ctx *dt_ctx;
struct sbus_conn_timeout_ctx *conn_t_ctx;
if (!dbus_timeout_get_enabled(timeout))
return TRUE;
/* Save the event to the watch object so it can be removed later */
return TRUE;
}
/*
* sbus_toggle_conn_timeout
* event
*/
{
if (dbus_timeout_get_enabled(timeout)) {
} else {
}
}
/* dbus_connection_wakeup_main
* D-BUS makes a callback to the wakeup_main function when
* it has data available for dispatching.
* In order to avoid blocking, this function will create a now()
* timed event to perform the dispatch during the next iteration
* through the mainloop
*/
static void sbus_conn_wakeup_main(void *data) {
struct sbus_conn_ctx *dct_ctx;
struct timed_event *te;
/* D-BUS calls this function when it is time to do a dispatch */
DEBUG(0,("Could not add dispatch event!\n"));
exit(1);
}
}
/*
* integrate_connection_with_event_loop
* Set up a D-BUS connection to use the libevents mainloop
* for handling file descriptor and timed events
*/
struct event_context *ev,
struct sbus_conn_ctx **dct_ctx,
int connection_type)
{
struct sbus_conn_ctx *dt_ctx;
dt_ctx->disconnect = 0;
/* This will be replaced on the first call to sbus_conn_add_method_ctx() */
/*
* Set the default destructor
* Connections can override this with
* sbus_conn_set_destructor
*/
/* Set up DBusWatch functions */
if (!dbret) {
DEBUG(0,("Error setting up D-BUS connection watch functions\n"));
return EIO;
}
/* Set up DBusTimeout functions */
if (!dbret) {
DEBUG(0,("Error setting up D-BUS server timeout functions\n"));
/* FIXME: free resources ? */
return EIO;
}
/* Set up dispatch handler */
/* Set up any method_contexts passed in */
/* Attempt to dispatch immediately in case of opportunistic
* services connecting before the handlers were all up.
* If there are no messages to be dispatched, this will do
* nothing.
*/
/* Return the new toplevel object */
return EOK;
}
/*int sbus_new_connection(struct sbus_method_ctx *ctx, const char *address,
DBusConnection **connection,
sbus_conn_destructor_fn destructor)*/
struct sbus_conn_ctx **dct_ctx,
{
int ret;
/* Open a shared D-BUS connection to the address */
if (!dbus_conn) {
DEBUG(0, ("Failed to open connection: name=%s, message=%s\n",
return EIO;
}
/* FIXME: release resources */
}
/* Set connection destructor */
return ret;
}
/*
* sbus_conn_set_destructor
* Configures a callback to clean up this connection when it
* is finalized.
* @param dct_ctx The sbus_conn_ctx created
* when this connection was established
* @param destructor The destructor function that should be
* called when the connection is finalized. If passed NULL,
* this will reset the connection to the default destructor.
*/
if (!dct_ctx) {
return;
}
/* TODO: Should we try to handle the talloc_destructor too? */
}
int sbus_default_connection_destructor(void *ctx) {
struct sbus_conn_ctx *dct_ctx;
/* Private connections must be closed explicitly */
/* Shared connections are destroyed when their last reference is removed */
}
else {
/* Critical Error! */
DEBUG(0,("Critical Error, connection_type is neither shared nor private!\n"));
return -1;
}
/* Remove object path */
/* TODO: Remove object paths */
return 0;
}
/*
* sbus_get_connection
* Utility function to retreive the DBusConnection object
* from a sbus_conn_ctx
*/
}
return;
}
/* Invoke the custom destructor, if it exists */
if(dct_ctx->destructor) {
}
/* Unregister object paths */
/* Disable watch functions */
/* Disable timeout functions */
/* Disable dispatch status function */
/* Disable wakeup main function */
/* Finalize the connection */
}
/* messsage_handler
* Receive messages and process them
*/
void *user_data)
{
struct sbus_method_ctx *ctx;
const char *method;
const char *path;
const char *msg_interface;
int i, ret;
/* Validate the method interface */
/* Validate the D-BUS path */
/* FIXME: check error */
break;
}
}
/* FIXME: check if we didn't find any matching method */
}
if (reply) {
}
return reply ? DBUS_HANDLER_RESULT_HANDLED :
}
/* Adds a new D-BUS path message handler to the connection
* Note: this must be a unique path.
*/
if (!method_ctx) {
return EINVAL;
}
return EINVAL;
}
/* Set up the vtable for the object path */
if (method_ctx->message_handler) {
} else {
}
dbret = dbus_connection_register_object_path(dct_ctx->conn, method_ctx->path, connection_vtable, method_ctx);
if (!dbret) {
return ENOMEM;
}
return EOK;
}
static int _method_list_contains_path(struct sbus_method_ctx *list, struct sbus_method_ctx *method) {
struct sbus_method_ctx *iter;
return 0; /* FALSE */
}
return 1; /* TRUE */
}
return 0; /* FALSE */
}
struct sbus_method_ctx *purge;
}
}
}