示例#1
0
static int main_loop() {
    fd_set rfds, efds;
    int maxfd, mfd, lofd;

    mfd  = monome_get_fd(state.monome);
    lofd = lo_server_get_socket_fd(state.server);
    maxfd = ((lofd > mfd) ? lofd : mfd) + 1;

    do {
        FD_ZERO(&rfds);
        FD_SET(mfd, &rfds);
        FD_SET(lofd, &rfds);

        FD_ZERO(&efds);
        FD_SET(mfd, &efds);

        /* block until either the monome or liblo have data */
        select(maxfd, &rfds, NULL, &efds, NULL);

        /* is the monome still connected? */
        if( FD_ISSET(mfd, &efds) )
            return 1;

        /* is there data available for reading from the monome? */
        if( FD_ISSET(mfd, &rfds) )
            monome_event_handle_next(state.monome);

        /* how about from OSC? */
        if( FD_ISSET(lofd, &rfds) )
            lo_server_recv_noblock(state.server, 0);
    } while( 1 );
}
示例#2
0
static int main_loop() {
    struct pollfd fds[2];

    fds[0].fd = monome_get_fd(state.monome);
    fds[1].fd = lo_server_get_socket_fd(state.server);

    fds[0].events = fds[1].events =
                        POLLIN;

    do {
        /* block until either the monome or liblo have data */
        poll(fds, 2, -1);

        /* is the monome still connected? */
        if( fds[0].revents & (POLLHUP | POLLERR) )
            return 1;

        /* is there data available for reading from the monome? */
        if( fds[0].revents & POLLIN )
            monome_event_handle_next(state.monome);

        /* how about from OSC? */
        if( fds[1].revents & POLLIN )
            lo_server_recv_noblock(state.server, 0);
    } while( 1 );
}
示例#3
0
int sosc_event_loop(const sosc_state_t *state) {
	OVERLAPPED ov = {0, 0, {{0, 0}}};
	HANDLE hres, lo_thd_res;
	DWORD evt_mask;

	hres = (HANDLE) _get_osfhandle(monome_get_fd(state->monome));
	lo_thd_res = CreateThread(NULL, 0, lo_thread, (void *) state, 0, NULL);

	if( !(ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL)) ) {
		fprintf(stderr, "serialosc: event_loop: can't allocate event (%ld)\n",
		        GetLastError());
		return 1;
	}

	do {
		SetCommMask(hres, EV_RXCHAR);

		if( !WaitCommEvent(hres, &evt_mask, &ov) )
			switch( GetLastError() ) {
			case ERROR_IO_PENDING:
				break;

			case ERROR_ACCESS_DENIED:
				/* evidently we get this when the monome is unplugged? */
				return 1;

			default:
				fprintf(stderr, "event_loop() error: %d\n", GetLastError());
				return 1;
			}

		switch( WaitForSingleObject(ov.hEvent, INFINITE) ) {
		case WAIT_OBJECT_0:
			while( monome_event_handle_next(state->monome) );
			break;

		case WAIT_TIMEOUT:
			break;

		case WAIT_ABANDONED_0:
		case WAIT_FAILED:
			fprintf(stderr, "event_loop(): wait failed: %ld\n",
			        GetLastError());
			return 1;
		}
	} while ( 1 );

	((void) lo_thd_res); /* shut GCC up about this being an unused variable */
	return 0;
}
示例#4
0
文件: poll.c 项目: artfwo/serialosc
int
sosc_event_loop(struct sosc_state *state)
{
	struct pollfd fds[3];
	int nfds;

	fds[0].fd = monome_get_fd(state->monome);
	fds[0].events = POLLIN;

	fds[1].fd = lo_server_get_socket_fd(state->server);
	fds[1].events = POLLIN;

	fds[2].fd = state->ipc_in_fd;
	fds[2].events = POLLIN;
	fds[2].revents = 0;

	nfds = (state->ipc_in_fd > -1) ? 3 : 2;

	for (state->running = 1; state->running;) {
		/* block until either the monome or liblo have data */
		if (poll(fds, nfds, -1) < 0)
			switch (errno) {
			case EINVAL:
				perror("error in poll()");
				return 1;

			case EINTR:
			case EAGAIN:
				continue;
			}

		/* is the monome still connected? */
		if (fds[0].revents & (POLLHUP | POLLERR))
			break;

		/* is there data available for reading from the monome? */
		if (fds[0].revents & POLLIN)
			monome_event_handle_next(state->monome);

		/* how about from OSC? */
		if (fds[1].revents & POLLIN)
			lo_server_recv_noblock(state->server, 0);

		/* how about from the supervisor? */
		if (fds[2].revents & POLLIN)
			recv_msg(state, state->ipc_in_fd);
	}

	return 0;
}
示例#5
0
int monome_platform_wait_for_input(monome_t *monome, uint_t msec) {
	struct timeval timeout[1];
	fd_set rfds[1];
	int fd;

	fd = monome_get_fd(monome);

	timeout->tv_sec  = msec / 1000;
	timeout->tv_usec = (msec - (timeout->tv_sec * 1000)) * 1000;

	FD_ZERO(rfds);
	FD_SET(fd, rfds);

	if( !select(fd + 1, rfds, NULL, NULL, timeout) )
		return 1;

	return 0;
}
示例#6
0
int sosc_event_loop(const sosc_state_t *state) {
    fd_set rfds, efds;
    int maxfd, mfd, lofd;

    mfd  = monome_get_fd(state->monome);
    lofd = lo_server_get_socket_fd(state->server);
    maxfd = ((lofd > mfd) ? lofd : mfd) + 1;

    do {
        FD_ZERO(&rfds);
        FD_SET(mfd, &rfds);
        FD_SET(lofd, &rfds);

        FD_ZERO(&efds);
        FD_SET(mfd, &efds);

        /* block until either the monome or liblo have data */
        if( select(maxfd, &rfds, NULL, &efds, NULL) < 0 )
            switch( errno ) {
            case EBADF:
            case EINVAL:
                perror("error in select()");
                return 1;

            case EINTR:
                continue;
            }

        /* is the monome still connected? */
        if( FD_ISSET(mfd, &efds) )
            return 1;

        /* is there data available for reading from the monome? */
        if( FD_ISSET(mfd, &rfds) )
            monome_event_handle_next(state->monome);

        /* how about from OSC? */
        if( FD_ISSET(lofd, &rfds) )
            lo_server_recv_noblock(state->server, 0);
    } while( 1 );
}
示例#7
0
int
sosc_event_loop(struct sosc_state *state)
{
	OVERLAPPED ov = {0, 0, {{0, 0}}};
	HANDLE hres, wait_handles[3];
	struct poll_thread_ctx ctx;
	DWORD evt_mask;
	ssize_t nbytes;

	wait_handles[0] = ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	wait_handles[1] = WSACreateEvent();
	WSAEventSelect(lo_server_get_socket_fd(state->server),
			wait_handles[1], FD_READ);

	wait_handles[2] = CreateEvent(NULL, TRUE, FALSE, NULL);

	state->running = 1;

	if (state->ipc_in_fd > -1 || 1) {
		ctx.state = state;
		ctx.wakeup_handle = wait_handles[2];

		CreateThread(NULL, 0, stdin_poll_thread, &ctx, 0, NULL);
	}

	hres = (HANDLE) _get_osfhandle(monome_get_fd(state->monome));

	while (state->running) {
		SetCommMask(hres, EV_RXCHAR);

		if (!WaitCommEvent(hres, &evt_mask, &ov))
			switch (GetLastError()) {
			case ERROR_IO_PENDING:
				break;

			case ERROR_ACCESS_DENIED:
				/* evidently we get this when the monome is unplugged? */
				return 1;

			default:
				fprintf(stderr, "event_loop() error: %"PRIdword"\n",
						GetLastError());
				return 1;
			}

		switch (WaitForMultipleObjects(3, wait_handles, FALSE, INFINITE)) {
		case WAIT_OBJECT_0:
			do {
				nbytes = monome_event_handle_next(state->monome);

				if (nbytes < 0)
					return 1;
			} while (nbytes > 0);

			break;

		case WAIT_OBJECT_0 + 1:
			lo_server_recv_noblock(state->server, 0);
			WSAResetEvent(wait_handles[1]);
			break;

		case WAIT_OBJECT_0 + 2:
			ResetEvent(wait_handles[2]);
			break;

		case WAIT_TIMEOUT:
			break;

		case WAIT_ABANDONED_0:
		case WAIT_FAILED:
			fprintf(stderr, "event_loop(): wait failed: %"PRIdword"\n",
			        GetLastError());
			return 1;
		}
	}

	return 0;
}