apps/streamer/event.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Nathan Lutchansky <lutchann@litech.org>
00003  *
00004  *  This program is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation, either version 3 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #include <sys/types.h>
00019 #include <sys/time.h>
00020 
00021 #ifndef _EVENT_H
00022 #define _EVENT_H
00023 
00024 #define EVENT_TIME              1
00025 #define EVENT_FD                2
00026 #define EVENT_ALWAYS            3
00027 
00028 #define EVENT_F_ENABLED         1
00029 #define EVENT_F_REMOVE          2
00030 #define EVENT_F_ONESHOT         4
00031 #define EVENT_F_RUNNING         8
00032 
00033 struct event;
00034 
00035 typedef struct timeval  time_ref;
00036 typedef void (*callback)( struct event *e, void *d );
00037 
00038 struct time_event {
00039         time_ref fire;
00040         int ival;
00041 };
00042 
00043 struct fd_event {
00044         int fd;
00045         int write; // 0 = read, 1 = write
00046 };
00047 
00048 struct event {
00049         struct event *prev;
00050         struct event *next;
00051         callback func;
00052         void *data;
00053         int type;
00054         int flags;
00055         union {
00056                 struct time_event time;
00057                 struct fd_event fd;
00058         } ev;
00059 };
00060 
00061 int time_diff( time_ref *tr_start, time_ref *tr_end );
00062 int time_ago( time_ref *tr );
00063 
00064 void time_now( time_ref *tr );
00065 void time_add( time_ref *tr, int msec );
00066 void time_future( time_ref *tr, int msec );
00067 
00068 struct event *add_timer_event( int msec, unsigned int flags, callback f, void *d );
00069 struct event *add_alarm_event( time_ref *t, unsigned int flags, callback f, void *d );
00070 void resched_event( struct event *e, time_ref *t );
00071 struct event *add_fd_event( int fd, int write, unsigned int flags, callback f, void *d );
00072 struct event *add_always_event( unsigned int flags, callback f, void *d );
00073 void remove_event( struct event *e );
00074 void set_event_interval( struct event *e, int msec );
00075 void set_event_enabled( struct event *e, int enabled );
00076 int get_event_enabled( struct event *e );
00077 void exit_event_loop(void);
00078 void event_loop( int single );
00079 
00080 #endif /* EVENT_H */

Generated on Fri Nov 28 00:06:22 2008 for elphel by  doxygen 1.5.1