Loading...
Searching...
No Matches
geis2.c
#include "geis_config.h"
#include <errno.h>
#include <geis/geis.h>
#include <stdio.h>
#include <string.h>
#include <sys/select.h>
void print_attr(GeisAttr attr)
{
GeisString attr_name = geis_attr_name(attr);
switch (geis_attr_type(attr))
{
case GEIS_ATTR_TYPE_BOOLEAN:
printf(" \"%s\": %s\n", attr_name,
geis_attr_value_to_boolean(attr) ? "true" : "false");
break;
case GEIS_ATTR_TYPE_FLOAT:
printf(" \"%s\": %g\n", attr_name, geis_attr_value_to_float(attr));
break;
case GEIS_ATTR_TYPE_INTEGER:
printf(" \"%s\": %d\n", attr_name, geis_attr_value_to_integer(attr));
break;
case GEIS_ATTR_TYPE_STRING:
printf(" \"%s\": %s\n", attr_name, geis_attr_value_to_string(attr));
break;
default:
break;
}
}
void
dump_device_event(GeisEvent event)
{
GeisDevice device;
GeisAttr attr;
GeisSize i;
attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_DEVICE);
device = geis_attr_value_to_pointer(attr);
printf("device %02d \"%s\"\n",
geis_device_id(device), geis_device_name(device));
for (i = 0; i < geis_device_attr_count(device); ++i)
{
print_attr(geis_device_attr(device, i));
}
}
void
dump_gesture_event(GeisEvent event)
{
GeisSize i;
GeisTouchSet touchset;
GeisGroupSet groupset;
GeisAttr attr;
attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_TOUCHSET);
touchset = geis_attr_value_to_pointer(attr);
attr = geis_event_attr_by_name(event, GEIS_EVENT_ATTRIBUTE_GROUPSET);
groupset = geis_attr_value_to_pointer(attr);
printf("gesture\n");
for (i= 0; i < geis_groupset_group_count(groupset); ++i)
{
GeisSize j;
GeisGroup group = geis_groupset_group(groupset, i);
printf("+group %u\n", geis_group_id(group));
for (j=0; j < geis_group_frame_count(group); ++j)
{
GeisSize k;
GeisFrame frame = geis_group_frame(group, j);
GeisSize attr_count = geis_frame_attr_count(frame);
printf("+frame %u\n", geis_frame_id(frame));
for (k = 0; k < attr_count; ++k)
{
print_attr(geis_frame_attr(frame, k));
}
for (k = 0; k < geis_frame_touchid_count(frame); ++k)
{
GeisSize touchid = geis_frame_touchid(frame, k);
GeisTouch touch = geis_touchset_touch_by_id(touchset, touchid);
GeisSize n;
printf("+touch %u\n", (unsigned)k);
for (n = 0; n < geis_touch_attr_count(touch); ++n)
{
print_attr(geis_touch_attr(touch, n));
}
}
}
}
}
void
target_subscription(Geis geis, GeisSubscription subscription)
{
GeisStatus status;
GeisFilter 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);
if (status != GEIS_STATUS_SUCCESS)
{
fprintf(stderr, "error adding filter\n");
}
}
int
main(int argc GEIS_UNUSED, char* argv[] GEIS_UNUSED)
{
GeisStatus status;
Geis geis;
GeisSubscription subscription;
int fd;
geis = geis_new(GEIS_INIT_TRACK_DEVICES,
GEIS_INIT_TRACK_GESTURE_CLASSES,
NULL);
geis_get_configuration(geis, GEIS_CONFIGURATION_FD, &fd);
subscription = geis_subscription_new(geis, "example", GEIS_SUBSCRIPTION_CONT);
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_INIT_COMPLETE:
target_subscription(geis, subscription);
status = geis_subscription_activate(subscription);
break;
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;
default:
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);
}
GeisDevice
A gesture-capable input device.
GeisEvent
A generic GEIS event.
GeisFilter
Selects a subset of possible gestures in a subscription.
GeisFrame
A collection of information describing the state of a gesture.
GeisGroup
A collection of gesture frames.
GeisGroupSet
A collection of GeisGroups.
Geis
Represents an instance of the gesture recognition engine.
GeisSubscription
A gesture recognition subscription.
GeisTouch
An instance of a touch.
GeisTouchSet
A collection of GeisTouch.
geis.h
This is the public interface for the GEIS gesture API.
GeisStatus
GeisStatus
Errors returned from calls.
Definition geis.h:73
GEIS_STATUS_SUCCESS
@ GEIS_STATUS_SUCCESS
normal successful completion
Definition geis.h:74
GEIS_STATUS_CONTINUE
@ GEIS_STATUS_CONTINUE
normal successful completion with data still remaining
Definition geis.h:75
GEIS_ATTR_TYPE_BOOLEAN
@ GEIS_ATTR_TYPE_BOOLEAN
Attr is truth-valued .
Definition geis.h:93
GEIS_ATTR_TYPE_FLOAT
@ GEIS_ATTR_TYPE_FLOAT
Attr is real-valued.
Definition geis.h:94
GEIS_ATTR_TYPE_STRING
@ GEIS_ATTR_TYPE_STRING
Attr is a null-terminated UTF-8 string.
Definition geis.h:97
GEIS_ATTR_TYPE_INTEGER
@ GEIS_ATTR_TYPE_INTEGER
Attr is a counting number.
Definition geis.h:95
geis_attr_type
GeisAttrType geis_attr_type(GeisAttr attr)
Gets the type of an attribute value.
geis_attr_name
GeisString geis_attr_name(GeisAttr attr)
An opaque type that encapsulates a GEIS attribute.
geis_dispatch_events
GeisStatus geis_dispatch_events(Geis geis)
Pumps the GEIS event loop.
geis_next_event
GeisStatus geis_next_event(Geis geis, GeisEvent *event)
Retrieves the next queued GEIS event.
geis_attr_value_to_boolean
GeisBoolean geis_attr_value_to_boolean(GeisAttr attr)
Gets the value of an attribute as a GeisBoolean.
geis_get_configuration
GeisStatus geis_get_configuration(Geis geis, GeisString configuration_item_name, void *configuration_item_value)
Gets a feature configuration value.
GEIS_CONFIGURATION_FD
#define GEIS_CONFIGURATION_FD
Gets a Unix file descriptor that will signal the availablility of GEIS events for processing.
Definition geis.h:714
geis_attr_value_to_pointer
GeisPointer geis_attr_value_to_pointer(GeisAttr attr)
Gets the value of an attribute as a GeisPointer.
geis_attr_value_to_float
GeisFloat geis_attr_value_to_float(GeisAttr attr)
Gets the value of an attribute as a GeisFloat.
geis_attr_value_to_integer
GeisInteger geis_attr_value_to_integer(GeisAttr attr)
Gets the value of an attribute as a GeisInteger.
geis_attr_value_to_string
GeisString geis_attr_value_to_string(GeisAttr attr)
Gets the value of an attribute as a GeisString.
GEIS_EVENT_ATTRIBUTE_DEVICE
#define GEIS_EVENT_ATTRIBUTE_DEVICE
The event attribute containing a pointer to a GeisDevice.
Definition geis.h:1273
GEIS_FILTER_CLASS
@ GEIS_FILTER_CLASS
Filters on gesture class and gesture attributes.
Definition geis.h:1714
GEIS_FILTER_OP_EQ
@ GEIS_FILTER_OP_EQ
Compares for equality.
Definition geis.h:1724
GEIS_INIT_TRACK_DEVICES
#define GEIS_INIT_TRACK_DEVICES
Tells GEIS to send input device events.
Definition geis.h:566
GEIS_INIT_TRACK_GESTURE_CLASSES
#define GEIS_INIT_TRACK_GESTURE_CLASSES
Tells GEIS to send gesture class events.
Definition geis.h:567
GEIS_EVENT_ATTRIBUTE_GROUPSET
#define GEIS_EVENT_ATTRIBUTE_GROUPSET
The event attribute containing a pointer to a GeisGroupSet.
Definition geis.h:2082
GEIS_EVENT_ATTRIBUTE_TOUCHSET
#define GEIS_EVENT_ATTRIBUTE_TOUCHSET
The event attribute containing a pointer to a GeisTouchSet.
Definition geis.h:2083
GEIS_SUBSCRIPTION_CONT
@ GEIS_SUBSCRIPTION_CONT
The gesture engine will return gesture continuations, in which the class of a recognized gestire may ...
Definition geis.h:1845