FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
event.h
Go to the documentation of this file.
1 /* **************************************************************
2 Copyright (C) 2010, 2011, 2012 Hewlett-Packard Development Company, L.P.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 ************************************************************** */
22 #ifndef EVENT_H_INCLUDE
23 #define EVENT_H_INCLUDE
24 
25 /* scheduler includes */
26 #include <scheduler.h>
27 
28 /* ************************************************************************** */
29 /* **** Data Types ********************************************************** */
30 /* ************************************************************************** */
31 
32 #define EVENT_LOOP_SIZE 1024
33 
35 typedef struct {
36  void(*func)(scheduler_t*, void*);
37  void* argument;
38  char* name;
39  char* source_name;
40  uint16_t source_line;
41 } event_t;
42 
44 typedef struct event_loop {
45  GAsyncQueue* queue;
46  int terminated;
47  int occupied;
48 } event_loop_t;
49 
50 
51 typedef void(*event_function)(scheduler_t*, void*);
52 
56 typedef struct
57 {
58  void* first;
59  int second;
60 } arg_int;
61 
62 /* ************************************************************************** */
63 /* **** Constructor Destructor ********************************************** */
64 /* ************************************************************************** */
65 
66 event_t* event_init(void(*func)(scheduler_t*, void*), void* arg, char* name, char* source_name, uint16_t source_line);
67 void event_destroy(event_t* e);
70 
71 void event_loop_destroy();
72 
73 /* ************************************************************************** */
74 /* **** EventLoop Functions ************************************************* */
75 /* ************************************************************************** */
76 
77 #define event_signal(func, args) event_signal_ext(func, args, #func, __FILE__, __LINE__)
78 
79 void event_signal_ext(void* func, void* args, char* name, char* s_name, uint16_t s_line);
80 int event_loop_enter(scheduler_t* scheduler, void(*)(scheduler_t*), void(*)(scheduler_t*));
82 
83 #endif /* EVENT_H_INCLUDE */
struct event_loop event_loop_t
char * name
Name of the event, used for debugging.
Definition: event.h:38
void event_loop_destroy()
Frees any memory associated with the event queue.
Definition: event.c:185
void event_destroy(event_t *e)
Free any memory associated with an event.
Definition: event.c:171
void event_signal_ext(void *func, void *args, char *name, char *s_name, uint16_t s_line)
Definition: event.c:206
int occupied
Does this loop already have a worker thread.
Definition: event.h:47
event_t * event_loop_take(event_loop_t *event_loop)
Definition: event.c:101
event_t * event_init(void(*func)(scheduler_t *, void *), void *arg, char *name, char *source_name, uint16_t source_line)
Definition: event.c:153
uint16_t s_line
Sample source line number.
Definition: testEvent.c:39
void event_loop_terminate()
Stops the event loop from executing.
Definition: event.c:281
void * argument
The arguments for the function.
Definition: event.h:37
uint16_t source_line
Line in the source file creating the event.
Definition: event.h:40
int event_loop_put(event_loop_t *event_loop, event_t *event)
Definition: event.c:86
int event_loop_enter(scheduler_t *scheduler, void(*)(scheduler_t *), void(*)(scheduler_t *))
Enters the event loop.
Definition: event.c:227
Definition: event.h:56
Definition: event.h:35
GAsyncQueue * queue
The queue that is the core of the event loop.
Definition: event.h:45
Header file for the scheduler.
char * source_name
Name of the source file creating the event.
Definition: event.h:39
char * s_name
Sample source file name.
Definition: testEvent.c:38
int terminated
Flag that signals the end of the event loop.
Definition: event.h:46