Logo Search packages:      
Sourcecode: pulseaudio version File versions

int pa_context_connect ( pa_context c,
const char *  server,
pa_context_flags_t  flags,
const pa_spawn_api api 
)

Connect the context to the specified server. If server is NULL, connect to the default server. This routine may but will not always return synchronously on error. Use pa_context_set_state_callback() to be notified when the connection is established. If flags doesn't have PA_NOAUTOSPAWN set and no specific server is specified or accessible a new daemon is spawned. If api is non-NULL, the functions specified in the structure are used when forking a new child process.

Definition at line 807 of file context.c.

References PA_CONTEXT_CONNECTING, PA_CONTEXT_NOAUTOSPAWN, PA_CONTEXT_UNCONNECTED, PA_ERR_BADSTATE, PA_ERR_INVALID, and PA_ERR_INVALIDSERVER.

                                 {

    int r = -1;

    pa_assert(c);
    pa_assert(PA_REFCNT_VALUE(c) >= 1);

    PA_CHECK_VALIDITY(c, c->state == PA_CONTEXT_UNCONNECTED, PA_ERR_BADSTATE);
    PA_CHECK_VALIDITY(c, !(flags & ~PA_CONTEXT_NOAUTOSPAWN), PA_ERR_INVALID);
    PA_CHECK_VALIDITY(c, !server || *server, PA_ERR_INVALID);

    if (!server)
        server = c->conf->default_server;

    pa_context_ref(c);

    pa_assert(!c->server_list);

    if (server) {
        if (!(c->server_list = pa_strlist_parse(server))) {
            pa_context_fail(c, PA_ERR_INVALIDSERVER);
            goto finish;
        }

    } else {
        char *d;

        /* Prepend in reverse order */

        /* Follow the X display */
        if ((d = getenv("DISPLAY"))) {
            char *e;
            d = pa_xstrdup(d);
            if ((e = strchr(d, ':')))
                *e = 0;

            if (*d)
                c->server_list = pa_strlist_prepend(c->server_list, d);

            pa_xfree(d);
        }

        /* Add TCP/IP on the localhost */
        c->server_list = pa_strlist_prepend(c->server_list, "tcp6:[::1]");
        c->server_list = pa_strlist_prepend(c->server_list, "tcp4:127.0.0.1");

        /* The system wide instance via PF_LOCAL */
        c->server_list = pa_strlist_prepend(c->server_list, PA_SYSTEM_RUNTIME_PATH PA_PATH_SEP PA_NATIVE_DEFAULT_UNIX_SOCKET);

        /* The user instance via PF_LOCAL */
        c->server_list = prepend_per_user(c->server_list);

        /* Set up autospawning */
        if (!(flags & PA_CONTEXT_NOAUTOSPAWN) && c->conf->autospawn) {

            if (getuid() == 0)
                pa_log_debug("Not doing autospawn since we are root.");
            else {
                c->do_autospawn = TRUE;

                if (api)
                    c->spawn_api = *api;
            }
        }
    }

    pa_context_set_state(c, PA_CONTEXT_CONNECTING);
    r = try_next_connection(c);

finish:
    pa_context_unref(c);

    return r;
}


Generated by  Doxygen 1.6.0   Back to index