static gboolean setup_bus(DBusConnection *conn, const char *name,
						DBusError *error)
{
	gboolean result;
	DBusDispatchStatus status;

	if (name != NULL) {
		result = g_dbus_request_name(conn, name, error);

		if (error != NULL) {
			if (dbus_error_is_set(error) == TRUE)
				return FALSE;
		}

		if (result == FALSE)
			return FALSE;
	}

	setup_dbus_with_main_loop(conn);

	status = dbus_connection_get_dispatch_status(conn);
	queue_dispatch(conn, status);

	return TRUE;
}
static void dispatch_status(DBusConnection *conn,
					DBusDispatchStatus status, void *data)
{
	if (!dbus_connection_get_is_connected(conn))
		return;

	queue_dispatch(conn, status);
}
static gboolean watch_func(GIOChannel *chan, GIOCondition cond, gpointer data)
{
	struct watch_info *info = data;
	unsigned int flags = 0;
	DBusDispatchStatus status;

	if (cond & G_IO_IN)  flags |= DBUS_WATCH_READABLE;
	if (cond & G_IO_OUT) flags |= DBUS_WATCH_WRITABLE;
	if (cond & G_IO_HUP) flags |= DBUS_WATCH_HANGUP;
	if (cond & G_IO_ERR) flags |= DBUS_WATCH_ERROR;

	dbus_watch_handle(info->watch, flags);

	status = dbus_connection_get_dispatch_status(info->conn);
	queue_dispatch(info->conn, status);

	return TRUE;
}
Beispiel #4
0
Bool asdbus_init ()
{																/* return connection unix fd */
	char *tmp;
#ifdef ASDBUS_DISPATCH
	if (!ASDBus.dispatches)
		ASDBus.dispatches = create_asbidirlist(asdbus_dispatch_destroy);
#endif
	if (!ASDBus.session_conn) {
		ASDBus.session_conn = _asdbus_get_session_connection();
		if (!dbus_connection_set_watch_functions(ASDBus.session_conn, add_watch, remove_watch,  toggle_watch, ASDBus.session_conn, NULL)) {
		 	show_error("dbus_connection_set_watch_functions() failed");
		}
		_asdbus_add_match (ASDBus.session_conn,  SESSIONMANAGER_INTERFACE, NULL);
		//_asdbus_add_match (ASDBus.session_conn,  IFACE_SESSION_PRIVATE, "QueryEndSession");
		//_asdbus_add_match (ASDBus.session_conn,  IFACE_SESSION_PRIVATE, "EndSession");
		//_asdbus_add_match (ASDBus.session_conn,  IFACE_SESSION_PRIVATE, "Stop");
		dbus_connection_set_timeout_functions(ASDBus.session_conn, add_timeout, remove_timeout, toggle_timeout, NULL, NULL);
#ifdef ASDBUS_DISPATCH
		dbus_connection_set_dispatch_status_function(ASDBus.session_conn, queue_dispatch, NULL, NULL);
		queue_dispatch(ASDBus.session_conn, dbus_connection_get_dispatch_status(ASDBus.session_conn), NULL);
#endif
	}

	if (!ASDBus.system_conn){
		ASDBus.system_conn = _asdbus_get_system_connection();
		/*if (!dbus_connection_set_watch_functions(ASDBus.system_conn, add_watch, remove_watch,  toggle_watch, ASDBus.system_conn, NULL)) {
		 	show_error("dbus_connection_set_watch_functions() failed");
		}*/
	}

	/*if (ASDBus.session_conn && ASDBus.watchFds == NULL){
		//dbus_connection_get_unix_fd (ASDBus.session_conn, &(ASDBus.watch_fd));
		//dbus_whatch_get_unix_fd (ASDBus.session_conn, &(ASDBus.watch_fd));
	}*/

	if ((tmp = getenv ("KDE_SESSION_VERSION")) != NULL)
		ASDBus.kdeSessionVersion = atoi(tmp);

	return (ASDBus.session_conn != NULL);
}