예제 #1
0
guint obc_session_mkdir(struct obc_session *session, const char *folder,
				session_callback_t func, void *user_data,
				GError **err)
{
	struct pending_request *p;

	if (session->obex == NULL) {
		g_set_error(err, OBEX_IO_ERROR, OBEX_IO_DISCONNECTED,
						"Session disconnected");
		return 0;
	}

	if (session->p != NULL) {
		g_set_error(err, OBEX_IO_ERROR, OBEX_IO_BUSY, "Session busy");
		return 0;
	}


	p = pending_request_new(session, NULL, func, user_data);

	p->req_id = g_obex_mkdir(session->obex, folder, async_cb, p, err);
	if (*err != NULL) {
		pending_request_free(p);
		return 0;
	}

	session->p = p;
	return p->id;
}
예제 #2
0
guint obc_session_queue(struct obc_session *session,
				struct obc_transfer *transfer,
				session_callback_t func, void *user_data,
				GError **err)
{
	struct pending_request *p;

	if (session->obex == NULL) {
		obc_transfer_unregister(transfer);
		g_set_error(err, OBEX_IO_ERROR, -ENOTCONN,
						"Session not connected");
		return 0;
	}

	if (!obc_transfer_register(transfer, session->conn, session->owner,
									err)) {
		obc_transfer_unregister(transfer);
		return 0;
	}

	obc_transfer_set_callback(transfer, transfer_complete, session);

	p = pending_request_new(session, transfer, func, user_data);
	g_queue_push_tail(session->queue, p);

	if (session->queue_complete_id == 0)
		session->queue_complete_id = g_idle_add(
					session_queue_complete, session);

	return p->id;
}
예제 #3
0
guint obc_session_setpath(struct obc_session *session, const char *path,
				session_callback_t func, void *user_data,
				GError **err)
{
	struct setpath_data *data;
	struct pending_request *p;

	if (session->obex == NULL) {
		g_set_error(err, OBEX_IO_ERROR, OBEX_IO_DISCONNECTED,
						"Session disconnected");
		return 0;
	}

	data = g_new0(struct setpath_data, 1);
	data->func = func;
	data->user_data = user_data;
	data->remaining = g_strsplit(strlen(path) ? path : "/", "/", 0);

	if (!data->remaining || !data->remaining[0]) {
		error("obc_session_setpath: invalid path %s", path);
		g_set_error(err, OBEX_IO_ERROR, -EINVAL, "Invalid argument");
		return 0;
	}

	p = pending_request_new(session, session_process_setpath, NULL,
				setpath_op_complete, data, setpath_data_free);
	session_queue(p);
	return p->id;
}
예제 #4
0
guint obc_session_setpath(struct obc_session *session, const char *path,
				session_callback_t func, void *user_data,
				GError **err)
{
	struct setpath_data *data;
	struct pending_request *p;
	const char *first = "";

	if (session->obex == NULL) {
		g_set_error(err, OBEX_IO_ERROR, OBEX_IO_DISCONNECTED,
						"Session disconnected");
		return 0;
	}

	if (session->p != NULL) {
		g_set_error(err, OBEX_IO_ERROR, OBEX_IO_BUSY,
							"Session busy");
		return 0;
	}

	data = g_new0(struct setpath_data, 1);
	data->func = func;
	data->user_data = user_data;
	data->remaining = g_strsplit(path, "/", 3);

	p = pending_request_new(session, NULL, setpath_complete, data);

	/* Relative path */
	if (path[0] != '/') {
		first = data->remaining[data->index];
		data->index++;
	}

	p->req_id = g_obex_setpath(session->obex, first, setpath_cb, p, err);
	if (*err != NULL)
		goto fail;

	session->p = p;

	return p->id;

fail:
	g_strfreev(data->remaining);
	g_free(data);
	pending_request_free(p);
	return 0;
}
예제 #5
0
guint obc_session_delete(struct obc_session *session, const char *file,
				session_callback_t func, void *user_data,
				GError **err)
{
	struct file_data *data;
	struct pending_request *p;

	if (session->obex == NULL) {
		g_set_error(err, OBEX_IO_ERROR, OBEX_IO_DISCONNECTED,
						"Session disconnected");
		return 0;
	}

	data = g_new0(struct file_data, 1);
	data->srcname = g_strdup(file);
	data->func = func;
	data->user_data = user_data;

	p = pending_request_new(session, session_process_delete, NULL,
				file_op_complete, data, file_data_free);
	session_queue(p);
	return p->id;
}
예제 #6
0
파일: session.c 프로젝트: hmallat/obexd
void obc_session_shutdown(struct obc_session *session)
{
	struct pending_request *p;
	GError *err;

	DBG("%p", session);

	if (session->disconnecting == TRUE) {
		DBG("%p already disconnecting", session);
		return;
	}
	session->disconnecting = TRUE;

	obc_session_ref(session);

	/* Unregister any pending transfer */
	err = g_error_new(OBEX_IO_ERROR, OBEX_IO_DISCONNECTED,
						"Session closed by user");

	if (session->p != NULL && session->p->id != 0) {
		p = session->p;
		session->p = NULL;

		if (p->func)
			p->func(session, p->transfer, err, p->data);

		pending_request_free(p);
	}

	while ((p = g_queue_pop_head(session->queue))) {
		if (p->func)
			p->func(session, p->transfer, err, p->data);

		pending_request_free(p);
	}

	g_error_free(err);

	/* Unregister interfaces */
	if (session->path)
		session_unregistered(session);

	DBG("Checking the need for disconnect request");
	/* Send a disconnect request and wait for reply */
	if (session->id > 0 && session->transport != NULL
			&& session->obex != NULL) {
		DBG("Generating disconnect request. ");
		err = NULL;
		p = pending_request_new(session, NULL, NULL, NULL);
		p->req_id = g_obex_disconnect(session->obex, disconnect_cb,
						p, &err);
		if (err != NULL) {
			DBG("Generating disconnect request failed. ");
			disconnect_cb(session->obex, NULL, NULL, p);
		} else {
			/* Finalize when reply arrives */
			DBG("Generating disconnect request succeeded. ");
		}
	} else {
		DBG("Unreferring without disconnect request.");
		obc_session_unref(session);
	}
}