summaryrefslogtreecommitdiff
path: root/libvxi11client/perlbits/perlglue.c
blob: 62d97481ab4c8f8c79b741d572cb04d6b1d68efe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdbool.h>
#include <glib.h>
#include "libvxi11client.h"

#define INTERRUPTHANDLE "libvxi11client"

GAsyncQueue* interruptqueue;

typedef struct {
	GTimeVal when;
} Event;

static void interruptcallback(void) {
	Event* event = g_malloc(sizeof(Event));
	g_get_current_time(&event->when);
	g_async_queue_push(interruptqueue, event);
}

int glue_enable_srq(bool enable) {
	if (enable) {
		interruptqueue = g_async_queue_new();
		return vxi11_enable_srq(enable, INTERRUPTHANDLE, interruptcallback);
	}
	else {
		int ret = vxi11_enable_srq(enable, NULL, NULL);
		g_free(interruptqueue);
		return ret;
	}
}

int glue_wait_for_interrupt() {
	GTimeVal timeout;
	g_get_current_time(&timeout);
	g_time_val_add(&timeout, 2500);
	gpointer event = g_async_queue_timed_pop(interruptqueue, &timeout);
	if (event != NULL) {
		g_free(event);
		return 1;
	}
	else
		return 0;
}