コード例 #1
0
ファイル: main.c プロジェクト: walterdejong/mpflow
int main(int argc, char *argv[]) {
	printf("mpflow - Copyright (C) 2009 Walter de Jong <*****@*****.**>\n");
	get_options(argc, argv);

	if (lock_program() == -1) {
		printf("another instance of mpflow is already running\n");
		return 1;
	}
	init_mpd();

/* init app */
	SDK_init();

	create_window();
	set_app_icon();

	init_gl();
	draw_startup();			/* only a border */

/* note that the order of init_() functions here is important (!) */
	init_textures();
	init_text();
	init_covers();
	init_events();

	init_widget_covers();
	init_widget_about();
	init_widget_aboutbutton();
	init_widget_titlebar();

	main_widget = &w_titlebar;
	prepare_widgets();
	draw();

	for(;;) {
		SDK_handle_events();
		move_covers();

		if (!moving)
			SDL_WaitEvent(NULL);
		else
			SDK_sleep(FRAME_DELAY);
	}
	exit_program(0);
	return 0;
}
コード例 #2
0
ファイル: browser.c プロジェクト: ysei/podzilla2
void pz_execv(const char *path, char *const argv[])
{
#ifdef IPOD
	static const char *const vcs[] = {"/dev/vc/%d", "/dev/tty%d", 0};
	int i, tty0_fd, ttyfd, curvt, fd, status, oldvt = 0;
	struct vt_stat vtstate;
	pid_t pid;

	ttyfd = -1;
	/* open our VT */
	if ((tty0_fd = open("/dev/tty0", O_WRONLY, 0)) < 0)
		if ((tty0_fd = open("/dev/vc/0", O_WRONLY, 0)) < 0)
			tty0_fd = dup(0); /* STDIN is a VT? */

	/* find available VT */
	ioctl(tty0_fd, VT_OPENQRY, &curvt);
	if (curvt <= 0) {
		pz_error("No available VTs.");
		goto err;
	}

	for (i = 0; vcs[i] && (ttyfd < 0); ++i) {
		char vtpath[12];

		sprintf(vtpath, vcs[i], curvt);
		ttyfd = open(vtpath, O_RDWR);
	}
	if (ttyfd < 0) {
		pz_error("No available TTYs.");
		goto err;
	}

	/* switch to the correct vt */
	if (ioctl(ttyfd, VT_GETSTATE, &vtstate) == 0)
		oldvt = vtstate.v_active;
	/* trick SDL and the kernel both at the same time! */
	if (ioctl(tty0_fd, KDSETMODE, KD_TEXT) < 0) {
		pz_error("Can't set graphics.");
		goto err;
	}
	if (ioctl(ttyfd, VT_ACTIVATE, curvt)) {
		pz_perror("child VT_ACTIVATE");
		goto err;
	}
	if (ioctl(ttyfd, VT_WAITACTIVE, curvt)) {
		pz_perror("child VT_WAITACTIVE");
		goto err;
	}
        
        /* Kill MPD music player */
        if (mpd_available())
              kill_mpd();

	switch(pid = vfork()) {
	case -1: /* error */
		perror("vfork");
		goto err;
	case 0: /* child */
		close(tty0_fd);
		close(ttyfd);
		if(setsid() < 0) {
			perror("setsid");
			_exit(1);
		}
		close(0);
		if((fd = open("/dev/console", O_RDWR)) == -1) {
			perror("/dev/console");
			_exit(1);
		}
		if(dup(fd) == -1) {
			perror("stdin dup");
			_exit(1);
		}
		close(1);
		if(dup(fd) == -1) {
			perror("stdout dup");
			_exit(1);
		}
		close(2);
		if(dup(fd) == -1) {
			perror("stderr dup");
			_exit(1);
		}

		execv(path, argv);
		fprintf(stderr, _("Exec failed! (Check Permissions)\n"));
		_exit(1);
		break;
	default: /* parent */
		waitpid(pid, &status, 0);
		sleep(5);
		
		if (oldvt > 0) {
        		if (ioctl(ttyfd, VT_ACTIVATE, oldvt)) {
				perror("parent VT_ACTIVATE");
				goto err;
			}
        		if(ioctl(ttyfd, VT_WAITACTIVE, oldvt)) {
				perror("parent VT_WAITACTIVE");
				goto err;
			}
		}

		close(ttyfd);
		ttyfd = -1;

		if (ioctl(tty0_fd, KDSETMODE, KD_GRAPHICS) < 0)
			pz_error("Can't reset graphics.");

		if (ioctl(tty0_fd, VT_DISALLOCATE, curvt)) {
			perror("VT_DISALLOCATE"); // happens sometimes, no biggy
			goto err;
		}
		break;
	}

        /* init MPD music player */
        if (mpd_available())
              init_mpd();

err:
	close(tty0_fd);
	if (ttyfd >= 0)
		close(ttyfd);
#else
	pz_message(argv[0]);
#endif /* IPOD */
}
コード例 #3
0
ファイル: main.c プロジェクト: bear24rw/beat_finder
int main( int argc, char **argv )
{
    if ( use_gui )
    {
        printf("init_sdl()\n");
        if ( init_sdl() ) return 1;

        printf("init_gl()\n");
        init_gl();
    }

    printf("init_fft()\n");
    init_fft();

#ifdef USE_FIFO
    printf("init_mpd()\n");
    if ( init_mpd() ) return 1;
#endif
#ifdef USE_ALSA
    printf("init_alsa()\n");
    if ( init_alsa() ) return 1;
#endif

    if ( use_serial )
    {
        printf("init_serial()\n");
        if ( init_serial() ) use_serial = FALSE;
    }

    init_lights();
    init_table();

    pthread_t sample_thread;

    pthread_create(&sample_thread, NULL, &get_samples, NULL);

    while ( !done )
    {

        // check to see if we have a new sample
        if (new_sample == 1)
        {
            // we are going to process this sample, it is no longer new
            pthread_mutex_lock(&sample_mutex);
            new_sample = 0;
            pthread_mutex_unlock(&sample_mutex);

            do_fft();

            detect_beats();

            assign_lights();

            //assign_cells();

            if ( use_gui )
            {
                if (handle_sdl_events()) return 1;
                draw_all();
            }

            if ( use_serial ) send_serial_fpga();
        }

        usleep(5000);
    }

    return 0;
}