Browse Source

preparation for edge triggerd events

1.0.0
Georg Hopp 11 years ago
parent
commit
f6254dfb48
  1. 2
      include/tr/event_dispatcher.h
  2. 9
      src/event_dispatcher.c
  3. 24
      src/event_dispatcher_start.c

2
include/tr/event_dispatcher.h

@ -51,6 +51,8 @@ TR_CLASS(TR_EventDispatcher) {
TR_Hash handler;
TR_EventHandler default_handler;
int running;
int pollinterval; // milliseconds
int nextpoll; // milliseconds
int heartbeat; // milliseconds
int nextbeat; // milliseconds
TR_EventDispatcherMode mode;

9
src/event_dispatcher.c

@ -23,6 +23,7 @@
#include <stdint.h>
#include <signal.h>
#include <stdio.h>
#include <time.h>
#include "trbase.h"
#include "trdata.h"
@ -63,6 +64,8 @@ static
int
eventDispatcherCtor(void * _this, va_list * params) {
TR_EventDispatcher this = _this;
struct timespec tp;
int now; // milliseconds
this->events = TR_new(TR_Queue);
this->handler = TR_new(TR_Hash);
@ -71,6 +74,12 @@ eventDispatcherCtor(void * _this, va_list * params) {
this->running = 0;
this->heartbeat = 0;
this->nextbeat = 0;
this->pollinterval = va_arg(*params, int);
clock_gettime(CLOCK_REALTIME, &tp);
now = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
this->nextpoll = now + this->pollinterval;
if (! _TR_controlDispatcher) {
_TR_controlDispatcher = this;

24
src/event_dispatcher_start.c

@ -30,6 +30,8 @@
#include "tr/event_subject.h"
#include "tr/event_dispatcher.h"
int ZERO = 0;
void
TR_eventDispatcherStart(TR_EventDispatcher this)
{
@ -55,18 +57,14 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
NULL));
}
if (TR_queueEmpty(this->events)) {
if (TR_EVD_CLIENT == this->mode) {
event = TR_eventSubjectEmit(
(TR_EventSubject)this,
TR_DISPATCHER_EVENT_USER_WAIT,
NULL);
} else {
event = TR_eventSubjectEmit(
(TR_EventSubject)this,
TR_DISPATCHER_EVENT_DATA_WAIT,
NULL);
}
if (TR_queueEmpty(this->events) || this->nextpoll <= now) {
int evtid = TR_EVD_CLIENT == this->mode
? TR_DISPATCHER_EVENT_USER_WAIT
: TR_DISPATCHER_EVENT_DATA_WAIT;
int * toutptr = TR_queueEmpty(this->events) ? NULL : &ZERO;
this->nextpoll += this->pollinterval;
event = TR_eventSubjectEmit((TR_EventSubject)this, evtid, toutptr);
} else {
event = TR_queueGet(this->events);
}
@ -83,7 +81,7 @@ TR_eventDispatcherStart(TR_EventDispatcher this)
if (handler_queue && ! TR_queueEmpty(handler_queue)) {
TR_Queue queue_node = handler_queue->first;
TR_EventDone done;
TR_EventDone done = TR_EVENT_PENDING;
while (queue_node) {
TR_EventHandler handler = queue_node->msg;

Loading…
Cancel
Save