summaryrefslogtreecommitdiff
path: root/src/util/event.c
blob: 0f09d470ae922fe39b3ad61e7c0650eb84d6719f (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
58
59
60
61
62
63
#include <stdio.h>
#include <string.h>

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

static int incall_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
{
	printf("EVENT: Incoming call type=%u!\n", aux->u.call.type);

	return 0;
}

static int clip_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
{
	printf("EVENT: Incoming call clip=`%s'\n", aux->u.clip.addr.number);

	return 0;
}

static int netreg_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
{
	printf("EVENT: Netreg ");

	switch (aux->u.netreg.state) {
	case 0:
		printf("not searching for network ");
		break;
	case 1:
		printf("registered (home network) ");
		break;
	case 2:
		printf("searching for network ");
		break;
	case 3:
		printf("registration denied ");
		break;
	case 5:
		printf("registered (roaming) ");
		break;
	}

	if (aux->u.netreg.lac)
		printf("LocationAreaCode=0x%04X ", aux->u.netreg.lac);
	if (aux->u.netreg.ci)
		printf("CellID=0x%04X ", aux->u.netreg.ci);
	
	printf("\n");

	return 0;
}

int event_init(struct lgsm_handle *lh)
{
	int rc;

	rc  = lgsm_evt_handler_register(lh, GSMD_EVT_IN_CALL, &incall_handler);
	rc |= lgsm_evt_handler_register(lh, GSMD_EVT_IN_CLIP, &clip_handler);
	rc |= lgsm_evt_handler_register(lh, GSMD_EVT_NETREG, &netreg_handler);

	return rc;
}

personal git repositories of Harald Welte. Your mileage may vary