Пример #1
0
void
ResultScreen::on_pause_press()
{
  if (result.success())
    close_screen();
  else
    retry_level();
}
Пример #2
0
bool setup_screen()
{
	//ncurses screen setup:
	//initscr();
	fd = fopen("/dev/tty", "r+");
	if (fd == NULL)
	{
		std::cerr << "Cannot open screen." << std::endl;
		return false;
	}
	scr = newterm(NULL, fd, fd);
	if (scr == NULL)
	{
		std::cerr << "Cannot open screen." << std::endl;
		close_screen();
		return false;
	}

	newfd = open("/dev/null", O_WRONLY);
	if (newfd == -1)
	{
		std::cerr << "Cannot open screen." << std::endl;
		close_screen();
		return false;
	}

	fflush(stdout);
	fflush(stderr);

	saved_stdout = dup(fileno(stdout));
	saved_stderr = dup(fileno(stderr));

	dup2(newfd, fileno(stdout));
	dup2(newfd, fileno(stderr));
	setvbuf(stdout, NULL, _IONBF, 0);

	clear();
	noecho();
	cbreak();
	keypad(stdscr, TRUE);
	timeout(10); //ms

	return true;
}
Пример #3
0
int main(int argc, char **argv)
{
    struct context ctx = {0};
    struct event *signal_int;
    struct evhttp_bound_socket *handle;
    char listen_addr[256];

    if (argc != 2)
    {
        printf("usage: statsrv STATS\n");
        return -1;
    }

    if (stats_cl_create(&ctx.cl) != S_OK)
    {
        printf("Failed to allocate stats counter list\n");
        return ERROR_FAIL;
    }

    if (stats_sample_create(&ctx.sample) != S_OK)
    {
        printf("Failed to allocate stats sample\n");
        return ERROR_FAIL;
    }

    if (stats_sample_create(&ctx.prev_sample) != S_OK)
    {
        printf("Failed to allocate stats sample\n");
        return ERROR_FAIL;
    }

    ctx.stats = open_stats(argv[1]);
    if (!ctx.stats)
    {
        printf("Failed to open stats %s\n", argv[1]);
        return ERROR_FAIL;
    }

    ctx.base = event_base_new();
    if (!ctx.base)
    {
        printf("Could not allocate event base\n");
        return 1;
    }

    /* add a handler for SIGINT */
    signal_int = evsignal_new(ctx.base, SIGINT, sigint_cb, event_self_cbarg());
    evsignal_add(signal_int,0);

    /* Create a new evhttp object to handle requests. */
    ctx.http = evhttp_new(ctx.base);
    if (!ctx.http)
    {
        printf("could not create evhttp.\n");
        return ERROR_FAIL;
    }

    evhttp_set_gencb(ctx.http, http_request_cb, &ctx);

    /* Now we tell the evhttp what port to listen on */
    handle = evhttp_bind_socket_with_handle(ctx.http, "0.0.0.0", 8080);
    if (!handle)
    {
        printf("couldn't bind to http port %d.\n", (int)8080);
        return ERROR_FAIL;
    }

    if (http_get_address(handle, listen_addr, sizeof(listen_addr)) == S_OK)
        printf("http: listening at %s\n", listen_addr);

    event_base_dispatch(ctx.base);

    event_free(signal_int);

#if 0
    start_time = current_time();

    while (!signal_received)
    {
        err = stats_get_sample(stats,cl,sample);
        if (err != S_OK)
        {
            printf("Error %08x (%s) getting sample\n",err,error_message(err));
        }

        clear();

        sample_time = TIME_DELTA_TO_NANOS(start_time, sample->sample_time);

        mvprintw(0,0,"SAMPLE @ %6lld.%03llds  SEQ:%d\n", sample_time / 1000000000ll, (sample->sample_time % 1000000000ll) / 1000000ll, sample->sample_seq_no);

        n = 1;
        maxy = getmaxy(stdscr);
        col = 0;
        for (j = 0; j < cl->cl_count; j++)
        {
            counter_get_key(cl->cl_ctr[j],counter_name,MAX_COUNTER_KEY_LENGTH+1);
            mvprintw(n,col+0,"%s", counter_name);
            mvprintw(n,col+29,"%15lld", stats_sample_get_value(sample,j));
            mvprintw(n,col+46,"%15lld", stats_sample_get_delta(sample,prev_sample,j));
            if (++n == maxy)
            {
                col += 66;
                n = 1;
            }
        }
        refresh();

        tmp = prev_sample;
        prev_sample = sample;
        sample = tmp;

        FD_ZERO(&fds);
        FD_SET(0,&fds);

        now = current_time();

        tv.tv_sec = 0;
        tv.tv_usec = 1000000 - (now % 1000000000) / 1000;

        ret = select(1, &fds, NULL, NULL, &tv);
        if (ret == 1)
        {
            ch = getch();
            if (ch == 'c' || ch == 'C')
            {
                stats_reset_counters(stats);
            }
        }
    }

    close_screen();
#endif

    if (ctx.base)
        event_base_free(ctx.base);

    if (ctx.http)
        evhttp_free(ctx.http);

    if (ctx.stats)
    {
        stats_close(ctx.stats);
        stats_free(ctx.stats);
    }

    if (ctx.cl)
        stats_cl_free(ctx.cl);

    if (ctx.sample)
        stats_sample_free(ctx.sample);

    if (ctx.prev_sample)
        stats_sample_free(ctx.prev_sample);

    return 0;
}
Пример #4
0
// Escape was pressed
void
EditorScreen::on_escape_press()
{
  close_screen();
}
Пример #5
0
void
ResultScreen::on_escape_press()
{
  close_screen();
}
Пример #6
0
void end_game() {
    close_screen(screen);
    delete_snake(snake);
    delete_move_list(move_list);
}
Пример #7
0
int main(int argc, char *argv[])
{
	if (!SetCommandLineOptions(argc, argv))
	{
		return -1;
	}

	cmdline_opt = GetCommandLineOptions();

	if (cmdline_opt.daemon)
	{
		std::cout << "raspivoice daemon started." << std::endl;
		daemon_startup();
	}

	pthread_mutex_init(&rvopt_mutex, NULL);
	rvopt = cmdline_opt;

	//Setup keyboard:
	KeyboardInput keyboardInput;
	keyboardInput.Verbose = cmdline_opt.verbose;

	bool use_ncurses = true;
	if (cmdline_opt.verbose || cmdline_opt.daemon)
	{
		use_ncurses = false;
	}

	if (cmdline_opt.use_rotary_encoder)
	{
		keyboardInput.SetInputType(KeyboardInput::InputType::RotaryEncoder);
	}
	else if (cmdline_opt.grab_keyboard != "")
	{
		if (!keyboardInput.SetInputType(KeyboardInput::InputType::Keyboard, cmdline_opt.grab_keyboard))
		{
			std::cerr << "Cannot grab keyboard device: " << cmdline_opt.grab_keyboard << "." << std::endl;
			return -1;
		}
	}
	else if (use_ncurses)
	{
		keyboardInput.SetInputType(KeyboardInput::InputType::NCurses);
	}
	else if (!cmdline_opt.daemon)
	{
		keyboardInput.SetInputType(KeyboardInput::InputType::Terminal);
	}


	//Start Program in worker thread:
	//Warning: Do not read or write rvopt or quit_flag without locking after this.
	pthread_t thr;
	AudioData::Init();
	if (pthread_create(&thr, NULL, run_worker_thread, NULL))
	{
		std::cerr << "Error setting up thread." << std::endl;
		return -1;
	}

	//Setup UI:
	if (use_ncurses)
	{
		//Show interactive screen:
		if (setup_screen())
		{
			printw("%s", keyboardInput.GetInteractiveCommandList().c_str());
			refresh();

			main_loop(keyboardInput);

			close_screen();
		}
	}
	else if ((cmdline_opt.verbose) && (!cmdline_opt.daemon))
	{
		std::cout << "Verbose mode on, curses UI disabled." << std::endl;
		std::cout << keyboardInput.GetInteractiveCommandList();
		main_loop(keyboardInput);
	}
	else
	{
		main_loop(keyboardInput);
	}

	if (cmdline_opt.grab_keyboard != "")
	{
		keyboardInput.ReleaseKeyboard();
	}

	//Wait for worker thread:
	pthread_join(thr, nullptr);

	//Check for exception from worker thread:
	if (exc_ptr != nullptr)
	{
		try
		{
			std::rethrow_exception(exc_ptr);
		}
		catch (const std::exception& e)
		{
			std::cerr << "Error: " << e.what() << std::endl;
			return(-1);
		}
	}

	return(0);
}