Hi there,
the attached patch adds IDirectFBWindow->WaitForEventWithTimeout to the
API. It's a cut and paste job from
IDirectFBInputBuffer->WaitForEventWithTimeout which was added a few days
ago. Is that ok for you guys?
Cheers,
Till
--
mailto: [EMAIL PROTECTED]
http://www.adam-lilienthal.de/till
? patch
? interfaces/.deps
? interfaces/.libs
Index: include/directfb.h
===================================================================
RCS file: /cvs/directfb/DirectFB/include/directfb.h,v
retrieving revision 1.28
diff -u -r1.28 directfb.h
--- include/directfb.h 2001/06/13 15:26:05 1.28
+++ include/directfb.h 2001/06/15 21:57:14
@@ -1860,6 +1860,18 @@
IDirectFBWindow *thiz
);
+ /*
+ * Block until next event to occurs or timeout is reached.
+ * Thread is idle in the meantime.
+ */
+ DFBResult (*WaitForEventWithTimeout) (
+ IDirectFBWindow *thiz,
+ long int seconds,
+ long int nano_seconds
+ );
+
+
+
/*
* Get the next event and remove from the FIFO.
*/
Index: src/windows/idirectfbwindow.c
===================================================================
RCS file: /cvs/directfb/DirectFB/src/windows/idirectfbwindow.c,v
retrieving revision 1.8
diff -u -r1.8 idirectfbwindow.c
--- src/windows/idirectfbwindow.c 2001/06/11 15:43:45 1.8
+++ src/windows/idirectfbwindow.c 2001/06/15 21:57:17
@@ -27,6 +27,8 @@
#include <string.h>
#include <malloc.h>
+#include <sys/time.h>
+#include <errno.h>
#include <directfb.h>
@@ -390,6 +392,42 @@
return DFB_OK;
}
+static DFBResult IDirectFBWindow_WaitForEventWithTimeout(
+ IDirectFBWindow *thiz,
+ long int seconds,
+ long int nano_seconds )
+{
+ DFBResult ret = DFB_OK;
+ IDirectFBWindow_data *data = (IDirectFBWindow_data*)thiz->priv;
+
+ if (!data)
+ return DFB_DEAD;
+
+ pthread_mutex_lock( &data->events_mutex );
+
+ if (!data->events) {
+ struct timeval now;
+ struct timespec timeout;
+
+ gettimeofday( &now, NULL );
+
+ timeout.tv_sec = now.tv_sec + seconds;
+ timeout.tv_nsec = (now.tv_usec * 1000) + nano_seconds;
+
+ timeout.tv_sec += timeout.tv_nsec / 1000000000;
+ timeout.tv_nsec %= 1000000000;
+
+ if (pthread_cond_timedwait( &data->wait_condition,
+ &data->events_mutex,
+ &timeout ) == ETIMEDOUT)
+ ret = DFB_TIMEOUT;
+ }
+
+ pthread_mutex_unlock( &data->events_mutex );
+
+ return ret;
+}
+
static DFBResult IDirectFBWindow_GetEvent( IDirectFBWindow *thiz,
DFBWindowEvent *event )
{
@@ -405,7 +443,6 @@
pthread_mutex_unlock( &data->events_mutex );
return DFB_BUFFEREMPTY;
}
-
e = data->events;
*event = e->evt;
@@ -482,6 +519,7 @@
thiz->RaiseToTop = IDirectFBWindow_RaiseToTop;
thiz->LowerToBottom = IDirectFBWindow_LowerToBottom;
thiz->WaitForEvent = IDirectFBWindow_WaitForEvent;
+ thiz->WaitForEventWithTimeout = IDirectFBWindow_WaitForEventWithTimeout;
thiz->GetEvent = IDirectFBWindow_GetEvent;
thiz->PeekEvent = IDirectFBWindow_PeekEvent;