Logo Search packages:      
Sourcecode: obexd version File versions  Download package

GwObex* gw_obex_setup_fd ( int  fd,
const gchar *  uuid,
gint  uuid_len,
GMainContext *  context,
gint *  error 
)

Setup OBEX connection using an opened file descriptor This function should be called before calling any other functions. The pointer returned by this function should be passed to the other functions.

Parameters:
fd Opened file descriptor to use for the connection
uuid UUID of service to connect to. NULL for the default service (INBOX).
uuid_len Length (in bytes) of UUID
context GMainContext to attach to (or NULL for the default one)
error Place to store error code on failure (NULL if not interested)
Returns:
A pointer, NULL on failure This pointer should be passed to the other obex_* functions.

Definition at line 324 of file gw-obex.c.

References GW_OBEX_ERROR_CONNECT_FAILED, and GW_OBEX_ERROR_NO_SERVICE.

                                                             {
    obex_t *handle;
    GwObex *ctx;

    if (!gw_obex_transport_setup(fd, &handle)) {
        debug("gw_obex_open() failed\n");
        if (error)
            *error = GW_OBEX_ERROR_CONNECT_FAILED;
        return NULL;
    }

    debug("Transport connection opened.\n");

    ctx = make_context(handle);

#ifdef GW_OBEX_THREADS_ENABLED
    if (!g_thread_supported())
        g_thread_init(NULL);
    ctx->mutex = g_mutex_new();
#endif

    OBEX_SetCustomData(handle, ctx);

    debug("Connecting to OBEX service\n");
    if (!gw_obex_connect(ctx, uuid, uuid_len)) {
        debug("Unable to connect to OBEX service\n");
#ifdef GW_OBEX_THREADS_ENABLED
        g_mutex_free(ctx->mutex);
        ctx->mutex = NULL;
#endif
        g_free(ctx);
        OBEX_Cleanup(handle);
        if (error)
            *error = GW_OBEX_ERROR_NO_SERVICE;
        return NULL;
    }

    debug("Connected (Connection ID: %#x)\n", ctx->conid);

    ctx->gio = g_io_channel_unix_new(ctx->conn_fd);
    ctx->gio_source = g_io_create_watch (ctx->gio,
                                         G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL);
    g_source_set_callback(ctx->gio_source, (GSourceFunc)gw_obex_cb, ctx, NULL);
    (void) g_source_attach(ctx->gio_source, context);
    g_source_unref(ctx->gio_source);

    ctx->main_ctx = context;

    return ctx;
}


Generated by  Doxygen 1.6.0   Back to index