Beispiel #1
0
MainGameState::MainGameState(Urho3D::Context *context) : GameState(context) {

    Urho3D::ResourceCache *cache = GetSubsystem<Urho3D::ResourceCache>();
    ui_factory =
        UIManager(context_, cache->GetResource<Urho3D::Font>("Fonts/Anonymous Pro.ttf", 20),
                  Urho3D::Color(), cache->GetResource<Urho3D::XMLFile>("UI/DefaultStyle.xml"),
                  GetSubsystem<Urho3D::UI>()->GetRoot());
    create_ui();
    subscribe_to_events();
    m_systems.add<TestSystem>();
    m_systems.configure();
}
Beispiel #2
0
int soundio_pulseaudio_init(struct SoundIoPrivate *si) {
    struct SoundIo *soundio = &si->pub;
    struct SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio;

    sipa->device_scan_queued = true;

    sipa->main_loop = pa_threaded_mainloop_new();
    if (!sipa->main_loop) {
        destroy_pa(si);
        return SoundIoErrorNoMem;
    }

    pa_mainloop_api *main_loop_api = pa_threaded_mainloop_get_api(sipa->main_loop);

    sipa->props = pa_proplist_new();
    if (!sipa->props) {
        destroy_pa(si);
        return SoundIoErrorNoMem;
    }

    sipa->pulse_context = pa_context_new_with_proplist(main_loop_api, soundio->app_name, sipa->props);
    if (!sipa->pulse_context) {
        destroy_pa(si);
        return SoundIoErrorNoMem;
    }

    pa_context_set_subscribe_callback(sipa->pulse_context, subscribe_callback, si);
    pa_context_set_state_callback(sipa->pulse_context, context_state_callback, si);

    int err = pa_context_connect(sipa->pulse_context, NULL, (pa_context_flags_t)0, NULL);
    if (err) {
        destroy_pa(si);
        return SoundIoErrorInitAudioBackend;
    }

    if (pa_threaded_mainloop_start(sipa->main_loop)) {
        destroy_pa(si);
        return SoundIoErrorNoMem;
    }

    pa_threaded_mainloop_lock(sipa->main_loop);

    // block until ready
    while (!sipa->ready_flag)
        pa_threaded_mainloop_wait(sipa->main_loop);

    if (sipa->connection_err) {
        pa_threaded_mainloop_unlock(sipa->main_loop);
        destroy_pa(si);
        return sipa->connection_err;
    }

    if ((err = subscribe_to_events(si))) {
        pa_threaded_mainloop_unlock(sipa->main_loop);
        destroy_pa(si);
        return err;
    }

    pa_threaded_mainloop_unlock(sipa->main_loop);

    si->destroy = destroy_pa;
    si->flush_events = flush_events_pa;
    si->wait_events = wait_events_pa;
    si->wakeup = wakeup_pa;
    si->force_device_scan = force_device_scan_pa;

    si->outstream_open = outstream_open_pa;
    si->outstream_destroy = outstream_destroy_pa;
    si->outstream_start = outstream_start_pa;
    si->outstream_begin_write = outstream_begin_write_pa;
    si->outstream_end_write = outstream_end_write_pa;
    si->outstream_clear_buffer = outstream_clear_buffer_pa;
    si->outstream_pause = outstream_pause_pa;
    si->outstream_get_latency = outstream_get_latency_pa;

    si->instream_open = instream_open_pa;
    si->instream_destroy = instream_destroy_pa;
    si->instream_start = instream_start_pa;
    si->instream_begin_read = instream_begin_read_pa;
    si->instream_end_read = instream_end_read_pa;
    si->instream_pause = instream_pause_pa;
    si->instream_get_latency = instream_get_latency_pa;

    return 0;
}
Beispiel #3
0
int main( int argc, char *argv[] )
{
        struct sockaddr_storage myaddr,remote;
        struct server_ctx ctx;
        int cli_fd, ret;
        socklen_t addrlen;
        char peer[INET6_ADDRSTRLEN];
        void *ptr;

        if ( signal( SIGTERM, sighandler ) == SIG_ERR ) {
                fprintf(stderr, "Unable to set signal handler\n");
                return EXIT_FAILURE;
        }
        if ( signal( SIGINT, sighandler ) == SIG_ERR ) {
                fprintf(stderr, "Unable to set signal handler\n");
                return EXIT_FAILURE;
        }
        if ( signal( SIGPIPE, sighandler ) == SIG_ERR ) {
                fprintf(stderr, "Unable to set signal handler\n");
                return EXIT_FAILURE;
        }

        memset( &ctx, 0, sizeof( ctx ));
        ctx.port = DEFAULT_PORT;
        ctx.recvbuf_size = RECVBUF_SIZE;

        partial_store_init(&ctx.partial);

        ret = parse_args( argc, argv, &ctx );
        if ( ret  < 0 ) {
                WARN("Error while parsing command line\n" );
                return EXIT_FAILURE;
        } else if ( ret == 0 ) {
                return EXIT_SUCCESS;
        }
        

        memset( &myaddr, 0, sizeof( myaddr));
        myaddr.ss_family = AF_INET6;

        if ( is_flag( ctx.options, SEQ_FLAG )) {
                DBG("Using SEQPKT socket\n");
                ctx.sock = socket( PF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP );
        } else {
                DBG("Using STREAM socket\n");
                ctx.sock = socket( PF_INET6, SOCK_STREAM, IPPROTO_SCTP );
        }
        if ( ctx.sock < 0 ) {
                fprintf(stderr, "Unable to create socket: %s \n", strerror(errno));
                return EXIT_FAILURE;
        }
        if (ctx.initmsg != NULL ) {
                TRACE("Requesting for %d output streams and at max %d input streams\n",
                                ctx.initmsg->sinit_num_ostreams,
                                ctx.initmsg->sinit_max_instreams);
                if (setsockopt( ctx.sock, SOL_SCTP, SCTP_INITMSG, 
                                        ctx.initmsg, sizeof(*ctx.initmsg)) < 0) {
                        fprintf(stderr,"Warning: unable to set the association parameters: %s\n",
                                        strerror(errno));
                }
        }

        if ( bind_and_listen( &ctx ) < 0 ) {
                fprintf(stderr, "Error while initializing the server\n" );
                close(ctx.sock);
                return EXIT_FAILURE;
        }

        if ( is_flag( ctx.options, VERBOSE_FLAG ))  
                subscribe_to_events(ctx.sock); /* to err is not fatal */

        memset( &remote, 0, sizeof(remote));
        addrlen = sizeof( struct sockaddr_in6);

        TRACE("Allocating %d bytes for recv buffer \n", ctx.recvbuf_size );
        ctx.recvbuf = mem_alloc( ctx.recvbuf_size * sizeof( uint8_t ));

        printf("Listening on port %d \n", ctx.port );
        while ( !close_req ) {
                if ( is_flag( ctx.options, SEQ_FLAG ) ) {
                        ret = do_server( &ctx, ctx.sock );
                        if ( ret == SERVER_ERROR )
                                break;
                } else {
                        cli_fd = do_accept( &ctx, &remote, &addrlen );
                        if ( cli_fd < 0 ) {
                                if ( errno == EINTR ) 
                                        break;

                                close( ctx.sock );
                                mem_free( ctx.recvbuf);
                                WARN( "Error in accept!\n");
                                return EXIT_FAILURE;
                        } else if ( cli_fd == 0 ) {
                                break;
                        }
                        if ( remote.ss_family == AF_INET ) {
                                ptr = &(((struct sockaddr_in *)&remote)->sin_addr);
                        } else {
                                ptr = &(((struct sockaddr_in6 *)&remote)->sin6_addr);
                        }
                        if ( inet_ntop(remote.ss_family, ptr, peer,
                                                INET6_ADDRSTRLEN ) != NULL ) {
                                printf("Connection from %s \n", peer );
                        } else {
                                printf("Connection from unknown\n");
                        }
                        if( do_server( &ctx, cli_fd ) == SERVER_ERROR ) {
                                close( cli_fd);
                                break;
                        }
                        close( cli_fd );
                }
        }
        mem_free( ctx.recvbuf);
        if (ctx.initmsg != NULL ) {
                mem_free( ctx.initmsg);
        }
        close( ctx.sock );

        return EXIT_SUCCESS;
}