summaryrefslogtreecommitdiff
path: root/src/libgsmd/libgsmd_event.c
blob: 6e19effea2820eddf5e95878c3653f3fca60d876 (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
47
48
49
50
51
52
53
54
55
56
57
/* libgsmd event demultiplexer handler */

#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <libgsmd/voicecall.h>
#include <libgsmd/event.h>

#include <gsmd/usock.h>
#include <gsmd/event.h>

#include "lgsm_internals.h"

static lgsm_evt_handler *evt_handlers[__NUM_GSMD_EVT];

int lgsm_evt_handler_register(struct lgsm_handle *lh, int evt_type,
			      lgsm_evt_handler *handler)
{
	if (evt_type >= __NUM_GSMD_EVT)
		return -EINVAL;

	evt_handlers[evt_type] = handler;

	return 0;
}

void lgsm_evt_handler_unregister(struct lgsm_handle *lh, int evt_type)
{
	if (evt_type < __NUM_GSMD_EVT)
		evt_handlers[evt_type] = NULL;
}


static int evt_demux_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
{
	struct gsmd_evt_auxdata *aux = gmh->data;

	if (gmh->len < sizeof(*aux))
		return -EIO;
	
	if (gmh->msg_type != GSMD_MSG_EVENT || 
	    gmh->msg_subtype >= __NUM_GSMD_EVT)
		return -EINVAL;

	return evt_handlers[gmh->msg_subtype](lh, gmh->msg_subtype, aux);
}

int lgsm_evt_init(struct lgsm_handle *lh)
{
	return lgsm_register_handler(lh, GSMD_MSG_EVENT, &evt_demux_msghandler);
}

void lgsm_evt_exit(struct lgsm_handle *lh)
{
	lgsm_unregister_handler(lh, GSMD_MSG_EVENT);
}
personal git repositories of Harald Welte. Your mileage may vary