summaryrefslogtreecommitdiff
path: root/toxmsi/toxmsi_event.h
blob: 032e4df55f71102f6e22ca8f334a85e57f91da16 (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
43
44
45
46
#ifndef _MSI__EVENT_H_
#define _MSI__EVENT_H_

#include <stddef.h>
#include <inttypes.h>
#include <pthread.h>

typedef void* event_arg_t;

typedef void ( *event_t ) ( event_arg_t );
typedef void ( *timed_event_t ) ( event_arg_t );

typedef struct event_container_s {
    event_t            _event;
    event_arg_t        _event_args;
    uint32_t           _timeout;
    long long          _id;

} event_container_t;

typedef struct event_handler_s {
    event_container_t* _events;
    size_t             _events_count;

    event_container_t* _timed_events;
    size_t             _timed_events_count;

    uint32_t           _frequms;
    int                _running;

    pthread_mutex_t    _mutex;
    pthread_t          _thread_id;

} event_handler_t;

event_handler_t*    init_event_poll         ( uint32_t _frequms );
int                 terminate_event_poll    ( event_handler_t* _event_handler );

void                throw_event             ( void* _event_handler_p, event_t _func, event_arg_t _arg );

/* Not yet ready for use */
int                 throw_timer_event       ( void* _event_handler_p, event_t _func, event_arg_t _arg, uint32_t _timeout);
int                 cancel_timer_event      ( void* _event_handler_p, int _id );


#endif /* _MSI__EVENT_H_ */