Newer
Older
#include <syslog.h>
#include <stdarg.h>
struct terminal_info_t terminal_info = { .num_terminals = 0, };
struct line_t *lines = NULL; // Array of phone lines including FXS and DECT
struct connection_t *connections = NULL;
int max_num_connections = 0;
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
const struct voice_event_t event_map[] = { // List of events from the voice engine
{ .name = "DTMF0", .event = VOICE_EVT_DTMF0 },
{ .name = "DTMF1", .event = VOICE_EVT_DTMF1 },
{ .name = "DTMF2", .event = VOICE_EVT_DTMF2 },
{ .name = "DTMF3", .event = VOICE_EVT_DTMF3 },
{ .name = "DTMF4", .event = VOICE_EVT_DTMF4 },
{ .name = "DTMF5", .event = VOICE_EVT_DTMF5 },
{ .name = "DTMF6", .event = VOICE_EVT_DTMF6 },
{ .name = "DTMF7", .event = VOICE_EVT_DTMF7 },
{ .name = "DTMF8", .event = VOICE_EVT_DTMF8 },
{ .name = "DTMF9", .event = VOICE_EVT_DTMF9 },
{ .name = "DTMFS", .event = VOICE_EVT_DTMFS },
{ .name = "DTMFH", .event = VOICE_EVT_DTMFH },
{ .name = "DTMFA", .event = VOICE_EVT_DTMFA },
{ .name = "DTMFB", .event = VOICE_EVT_DTMFB },
{ .name = "DTMFC", .event = VOICE_EVT_DTMFC },
{ .name = "DTMFD", .event = VOICE_EVT_DTMFD },
{ .name = "OFFHOOK", .event = VOICE_EVT_OFFHOOK },
{ .name = "ONHOOK", .event = VOICE_EVT_ONHOOK },
{ .name = "FLASH", .event = VOICE_EVT_FLASH },
{ .name = "MEDIA", .event = VOICE_EVT_MEDIA_START },
{ .name = "", .event = VOICE_EVT_END }
};
const struct dect_event_t dect_event_map[] = {
{ .name = "SWITCH", .event = DECT_EVT_SWITCH },
{ .name = "JOIN", .event = DECT_EVT_JOIN },
{ .name = "RELEASE", .event = DECT_EVT_RELEASE },
{ .name = "", .event = DECT_EVT_END }
};
// Callback function which is invoked when an event is detected from the voice engine
void (*voice_cb_event_report)(int line, const char *event, int data) = NULL;
void voice_syslog(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vsyslog(LOG_DEBUG, fmt, ap);
va_end(ap);
}
int voice_connection_find(int line, int conId)
{
int conIdx;
for(conIdx = 0; conIdx < max_num_connections; conIdx++) {
if(connections[conIdx].line == line && connections[conIdx].connection_id == conId) {
return conIdx;
}
}
return -1;
}
// Pre-initialization of data structures
int voice_line_preinit(void) {
int i;
if(terminal_info.num_terminals <= 0) {
ENDPT_DBG("%s: terminal_info.num_terminals = %d\n", __func__, terminal_info.num_terminals);
return -1;
}
// Initialize all contents as 0 by calloc
lines = calloc(terminal_info.num_terminals, sizeof(struct line_t));
if(!lines) {
ENDPT_DBG("%s: out out memory\n", __func__);
return -1;
}
for(i = 0; i < terminal_info.num_terminals; i++) {
lines[i].type = VOICE_LINE_UNKNOWN;
lines[i].pcm_state[PCM_0] = LINE_PCM_STATE_NOT_USED;
lines[i].pcm_state[PCM_1] = LINE_PCM_STATE_NOT_USED;
}
return 0;
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Shut down and free resources
int voice_line_deinit(void) {
char *digits;
int line;
// Free all line resources we have allocated
for (line = 0; line < terminal_info.num_terminals; line++) {
if(lines[line].pending_digits) {
do {
digits = pe_list_get(lines[line].pending_digits);
free(digits);
} while(digits);
free(lines[line].pending_digits);
lines[line].pending_digits = NULL;
}
voice_line_close(line);
if (lines[line].line_conf.name) {
free(lines[line].line_conf.name);
lines[line].line_conf.name = NULL;
}
}
free(lines);
lines = NULL;
return 0;
}
// Register the callback function for event report
int voice_register_cb_event_report(void (*cb_event_report)(int line, const char *event, int data)) {
voice_cb_event_report = cb_event_report;
return 0;
}