Ejemplo n.º 1
0
Archivo: mtsd.c Proyecto: ianonavy/mtsd
bool run(int *fd, Geis *geis, GeisStatus *status)
{
	fd_set read_fds;
	FD_ZERO(&read_fds);
	FD_SET(0, &read_fds);
	FD_SET(*fd, &read_fds);
	int sstat = select(*fd+1, &read_fds, NULL, NULL, NULL);
	if (sstat < 0) {
		fatal("error %d in select(): %s\n", errno, strerror(errno));
	}
 	if (FD_ISSET(*fd, &read_fds)) {
		GeisEvent event;
		*status = geis_dispatch_events(*geis);
		*status = geis_next_event(*geis, &event);
		while (*status == GEIS_STATUS_CONTINUE ||
			*status == GEIS_STATUS_SUCCESS) {
			switch (geis_event_type(event)) {
			case GEIS_EVENT_DEVICE_AVAILABLE:
			case GEIS_EVENT_DEVICE_UNAVAILABLE:
				break;
			case GEIS_EVENT_GESTURE_BEGIN:
				start(event);
				break;
			case GEIS_EVENT_GESTURE_UPDATE:
				update(event);
				break;
			case GEIS_EVENT_GESTURE_END:
				end(event);
				break;
			default:
				break;
			}
			geis_event_delete(event);
			*status = geis_next_event(*geis, &event);
		}
	}
	return !(FD_ISSET(0, &read_fds));
}
Ejemplo n.º 2
0
int
main(int argc, char* argv[])
{
  GeisStatus status;
  Geis geis;
  GeisSubscription subscription;
  GeisFilter filter;
  int        fd;

  geis = geis_new(GEIS_INIT_TRACK_DEVICES,
                  NULL);
  subscription = geis_subscription_new(geis, "example", GEIS_SUBSCRIPTION_CONT);
  filter = geis_filter_new(geis, "filter");

  geis_filter_add_term(filter,
                       GEIS_FILTER_CLASS,
                       GEIS_GESTURE_ATTRIBUTE_TOUCHES, GEIS_FILTER_OP_EQ, 2,
                       NULL);

  status = geis_subscription_add_filter(subscription, filter);
  status = geis_subscription_activate(subscription);

  geis_get_configuration(geis, GEIS_CONFIGURATION_FD, &fd);

  while(1)
  {
    fd_set read_fds;
    FD_ZERO(&read_fds);
    FD_SET(0, &read_fds);
    FD_SET(fd, &read_fds);
    int sstat = select(fd+1, &read_fds, NULL, NULL, NULL);
    if (sstat < 0)
    {
      fprintf(stderr, "error %d in select(): %s\n", errno, strerror(errno));
      break;
    }

    if (FD_ISSET(fd, &read_fds))
    {
      GeisEvent event;
      status = geis_dispatch_events(geis);
      status = geis_next_event(geis, &event);
      while (status == GEIS_STATUS_CONTINUE || status == GEIS_STATUS_SUCCESS)
      {
        switch (geis_event_type(event))
        {
          case GEIS_EVENT_DEVICE_AVAILABLE:
          case GEIS_EVENT_DEVICE_UNAVAILABLE:
            dump_device_event(event);
            break;

          case GEIS_EVENT_GESTURE_BEGIN:
          case GEIS_EVENT_GESTURE_UPDATE:
          case GEIS_EVENT_GESTURE_END:
            dump_gesture_event(event);
            break;
        }
        geis_event_delete(event);
        status = geis_next_event(geis, &event);
      }
    }

    if (FD_ISSET(0, &read_fds))
    {
      break;
    }
  }

  geis_subscription_delete(subscription);
  geis_delete(geis);
}