fastevent.h 2.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/* Icecast
 *
 * This program is distributed under the GNU General Public License, version 2.
 * A copy of this license is included with this source.
 *
 * Copyright 2018,      Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
 */

#ifndef __FASTEVENT_H__
#define __FASTEVENT_H__

12 13 14 15 16 17
/* Add all conditions when to enable fast events here. */
#if 1
#define FASTEVENT_ENABLED
#endif

#include <stdarg.h>
18
#include "refobject.h"
19 20 21

typedef enum {
    FASTEVENT_TYPE_SLOWEVENT = 0,
22 23 24 25 26 27 28 29 30 31
    FASTEVENT_TYPE_CONNECTION_CREATE,
    FASTEVENT_TYPE_CONNECTION_DESTROY,
    FASTEVENT_TYPE_CONNECTION_READ,
    FASTEVENT_TYPE_CONNECTION_PUTBACK,
    FASTEVENT_TYPE_CONNECTION_WRITE,
    FASTEVENT_TYPE_CLIENT_CREATE,
    FASTEVENT_TYPE_CLIENT_DESTROY,
    FASTEVENT_TYPE_CLIENT_READ,
    FASTEVENT_TYPE_CLIENT_WRITE,
    FASTEVENT_TYPE_CLIENT_READ_BODY,
32 33 34
    FASTEVENT_TYPE_CLIENT_READY_FOR_AUTH,
    FASTEVENT_TYPE_CLIENT_AUTHED,
    FASTEVENT_TYPE_CLIENT_SEND_RESPONSE,
35 36 37 38 39 40 41
    FASTEVENT_TYPE__END /* must be last element */
} fastevent_type_t;

typedef enum {
    FASTEVENT_DATATYPE_NONE = 0,
    FASTEVENT_DATATYPE_EVENT,
    FASTEVENT_DATATYPE_CLIENT,
42 43 44
    FASTEVENT_DATATYPE_CONNECTION,
    FASTEVENT_DATATYPE_OBR,             /* Object, const void *Buffer, size_t Request_length */
    FASTEVENT_DATATYPE_OBRD             /* Object, const void *Buffer, size_t Request_length, ssize_t Done_length */
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
} fastevent_datatype_t;

typedef int fastevent_flag_t;
#define FASTEVENT_FLAG_NONE                     ((fastevent_flag_t)0x0000)
#define FASTEVENT_FLAG_MODIFICATION_ALLOWED     ((fastevent_flag_t)0x0001)

typedef void (*fastevent_cb_t)(const void *userdata, fastevent_type_t type, fastevent_flag_t flags, fastevent_datatype_t datatype, va_list ap);
typedef void (*fastevent_freecb_t)(void **userdata);

#ifdef FASTEVENT_ENABLED
int fastevent_initialize(void);
int fastevent_shutdown(void);
refobject_t fastevent_register(fastevent_type_t type, fastevent_cb_t cb, fastevent_freecb_t freecb, void *userdata);
void fastevent_emit(fastevent_type_t type, fastevent_flag_t flags, fastevent_datatype_t datatype, ...);
#else
#define fastevent_initialize() 0
#define fastevent_shutdown() 0
#define fastevent_register(type,cb,freecb,userdata) REFOBJECT_NULL
#define fastevent_emit(type,flags,datatype,...)
#endif

66
#endif