Beispiel #1
0
static void transport_func(GIOChannel *io, GError *err, gpointer user_data)
{
    struct callback_data *callback = user_data;
    struct obc_session *session = callback->session;
    struct obc_driver *driver = session->driver;
    struct obc_transport *transport = session->transport;
    GObex *obex;
    GObexTransportType type;
    int tx_mtu = -1;
    int rx_mtu = -1;

    DBG("");

    if (err != NULL) {
        error("%s", err->message);
        goto done;
    }

    g_io_channel_set_close_on_unref(io, FALSE);

    if (transport->getpacketopt &&
            transport->getpacketopt(io, &tx_mtu, &rx_mtu) == 0)
        type = G_OBEX_TRANSPORT_PACKET;
    else
        type = G_OBEX_TRANSPORT_STREAM;

    obex = g_obex_new(io, type, tx_mtu, rx_mtu);
    if (obex == NULL)
        goto done;

    g_io_channel_set_close_on_unref(io, TRUE);

    if (driver->target != NULL)
        g_obex_connect(obex, connect_cb, callback, &err,
                       G_OBEX_HDR_TARGET, driver->target, driver->target_len,
                       G_OBEX_HDR_INVALID);
    else
        g_obex_connect(obex, connect_cb, callback, &err,
                       G_OBEX_HDR_INVALID);

    if (err != NULL) {
        error("%s", err->message);
        g_obex_unref(obex);
        goto done;
    }

    session->obex = obex;
    sessions = g_slist_prepend(sessions, session);

    g_obex_set_disconnect_function(obex, session_disconnected, session);

    return;
done:
    callback->func(callback->session, NULL, err, callback->data);
    obc_session_unref(callback->session);
    g_free(callback);
}
Beispiel #2
0
static void transport_connect(GIOChannel *io, GObexTransportType transport)
{
	GIOChannel *input;
	GIOCondition events;

	g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
	g_io_channel_set_close_on_unref(io, TRUE);

	obex = g_obex_new(io, transport, option_imtu, option_omtu);
	g_obex_set_disconnect_function(obex, disconn_func, NULL);

	input = g_io_channel_unix_new(STDIN_FILENO);
	g_io_channel_set_close_on_unref(input, TRUE);
	events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
	g_io_add_watch(input, events, prompt_read, NULL);
	g_io_channel_unref(input);
	rl_callback_handler_install("client> ", parse_line);
}
Beispiel #3
0
static void transport_accept(GIOChannel *io)
{
	GObex *obex;
	GObexTransportType transport;

	g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
	g_io_channel_set_close_on_unref(io, TRUE);

	if (option_packet)
		transport = G_OBEX_TRANSPORT_PACKET;
	else
		transport = G_OBEX_TRANSPORT_STREAM;

	obex = g_obex_new(io, transport, option_imtu, option_omtu);
	g_obex_set_disconnect_function(obex, disconn_func, NULL);
	g_obex_add_request_function(obex, G_OBEX_OP_PUT, handle_put, NULL);
	g_obex_add_request_function(obex, G_OBEX_OP_GET, handle_get, NULL);
	g_obex_add_request_function(obex, G_OBEX_OP_CONNECT, handle_connect,
									NULL);
	clients = g_slist_append(clients, obex);
}
Beispiel #4
0
static void session_free(struct obc_session *session)
{
	DBG("%p", session);

	if (session->process_id != 0)
		g_source_remove(session->process_id);

	if (session->queue) {
		g_queue_foreach(session->queue, (GFunc) pending_request_free,
									NULL);
		g_queue_free(session->queue);
	}

	if (session->watch)
		g_dbus_remove_watch(session->conn, session->watch);

	if (session->obex) {
		g_obex_set_disconnect_function(session->obex, NULL, NULL);
		g_obex_unref(session->obex);
	}

	if (session->id > 0 && session->transport != NULL)
		session->transport->disconnect(session->id);

	if (session->path)
		session_unregistered(session);

	if (session->conn)
		dbus_connection_unref(session->conn);

	if (session->p)
		pending_request_free(session->p);

	g_free(session->path);
	g_free(session->owner);
	g_free(session->source);
	g_free(session->destination);
	g_free(session->folder);
	g_free(session);
}
Beispiel #5
0
static void transport_func(GIOChannel *io, GError *err, gpointer user_data)
{
	struct callback_data *callback = user_data;
	struct obc_session *session = callback->session;
	struct obc_driver *driver = session->driver;
	struct obc_transport *transport = session->transport;
	GObex *obex;
	GObexApparam *apparam;
	GObexTransportType type;
	int tx_mtu = -1;
	int rx_mtu = -1;

	DBG("");

	if (err != NULL) {
		error("%s", err->message);
		goto done;
	}

	g_io_channel_set_close_on_unref(io, FALSE);

	if (transport->getpacketopt &&
			transport->getpacketopt(io, &tx_mtu, &rx_mtu) == 0)
		type = G_OBEX_TRANSPORT_PACKET;
	else
		type = G_OBEX_TRANSPORT_STREAM;

	obex = g_obex_new(io, type, tx_mtu, rx_mtu);
	if (obex == NULL)
		goto done;

	g_io_channel_set_close_on_unref(io, TRUE);

	apparam = NULL;

	if (driver->supported_features)
		apparam = driver->supported_features(session);

	if (apparam) {
		uint8_t buf[1024];
		ssize_t len;

		len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
		if (driver->target)
			g_obex_connect(obex, connect_cb, callback, &err,
					G_OBEX_HDR_TARGET,
					driver->target, driver->target_len,
					G_OBEX_HDR_APPARAM,
					buf, len,
					G_OBEX_HDR_INVALID);
		else
			g_obex_connect(obex, connect_cb, callback, &err,
					G_OBEX_HDR_APPARAM, buf, len,
					G_OBEX_HDR_INVALID);
		g_obex_apparam_free(apparam);
	} else if (driver->target)
		g_obex_connect(obex, connect_cb, callback, &err,
			G_OBEX_HDR_TARGET, driver->target, driver->target_len,
			G_OBEX_HDR_INVALID);
	else
		g_obex_connect(obex, connect_cb, callback, &err,
							G_OBEX_HDR_INVALID);

	if (err != NULL) {
		error("%s", err->message);
		g_obex_unref(obex);
		goto done;
	}

	session->obex = obex;
	sessions = g_slist_prepend(sessions, session);

	g_obex_set_disconnect_function(obex, session_disconnected, session);

	return;
done:
	callback_destroy(callback, err);
}