-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapiapp.cpp
More file actions
338 lines (271 loc) · 8.37 KB
/
capiapp.cpp
File metadata and controls
338 lines (271 loc) · 8.37 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#include<pthread.h>
#include<string>
#include<malloc.h>
#include<capi20.h>
#include<iostream>
#include"capiapp.h"
#include"tools.h"
// Hilfsfunktion fuer CAPIApp::start
void * runCAPIApp(void *a)
{
((CAPIApp*)a)->Run();
pthread_exit(NULL);
}
// Laesst CAPIApp::Run() als Thread laufen...
pthread_t CAPIApp::start()
{
pthread_t Handle;
pthread_create(&Handle, NULL,(&runCAPIApp), (void *)this);
return Handle;
}
// Default-Konstruktor
CAPIApp::CAPIApp()
{
if(dbg_init)
cdebug << "init : CAPIApp() aufgerufen..." << endl;
Appl_Id=0;
CMSG=&CMSG_Instanz;
if( CAPI20_ISINSTALLED() != CapiNoError )
{
cout << "CAPI ist nicht installiert: " << CAPI20_ISINSTALLED() << endl << "CAPI installieren und neu starten :-)" << endl;
delete this;
::exit(-1);
}
CAPI20_GET_PROFILE(0,(unsigned char *)&cprofile);
if(dbg_systeminfo)
cdebug << "sinfo : Anzahl Controller: " << cprofile.ncontroller << endl;
int bchans=0;
for(int ii=1;ii<=cprofile.ncontroller;ii++)
{
if(dbg_systeminfo)
cdebug << endl << "sinfo : Controller Nr." << ii << endl;
capi_profile dummy;
CAPI20_GET_PROFILE(ii,(unsigned char*)&dummy);
bchans+=dummy.nbchannel;
if(dbg_systeminfo)
{
cdebug << "sinfo : Anzahl B-Kanäle : " << dummy.nbchannel << endl;
char dummy1[64];
CAPI20_GET_MANUFACTURER(ii,(unsigned char*)&dummy1);
cdebug << "sinfo : Manufacturer : " << dummy1 << endl;
capi20_get_serial_number(ii,(unsigned char*)&dummy1);
cdebug << "sinfo : Serial# : " << dummy1 << endl;
capi_version dummy2;
CAPI20_GET_VERSION(ii,(unsigned char *)&dummy2);
cdebug << "sinfo : Version : " << dummy2.majorversion << "." << dummy2.minorversion << endl;
cdebug << "sinfo : Firmwarever. : " << dummy2.majormanuversion << "." << dummy2.minormanuversion << endl << endl;
}
}
if(dbg_systeminfo)
cdebug << "sinfo : B-Kanäle gesamt: " << bchans << endl << endl;
CAPI_REGISTER_ERROR err;
err=CAPI20_REGISTER(bchans,7,2048,&Appl_Id);
if(err)
{
cout << "CAPI registration error:" << err << endl;
cout << " Vorschlag: Stimmen die Versionen von isdn4k-utils und isdn (Kerneltreiber)" << endl << "ueberein ? Am besten beide Versionen per CVS ziehen..." << err << endl;
delete this;
}
if(dbg_fileop)
{
cdebug << "fileop : CAPI FileNr: " << capi20_fileno(Appl_Id) << endl;
cdebug << "fileop : ApplicationID=" << Appl_Id << endl << endl;
}
map<string,string> *c;
MESSAGE_EXCHANGE_ERROR error;
for (unsigned Controller=1; Controller<=cprofile.ncontroller; Controller++)
{
c=cConf->getconf(string(""),string("controller")+(char)(Controller+48));
if(c->find("dontuse")!=c->end() && (*c)["dontuse"]=="true")
{
if(dbg_any)
cdebug << "Controller " << Controller << " not in use !!!" << endl;
}
else
{
if(dbg_capireq)
cdebug << "capireq : LISTEN_REQ fuer Controller " << Controller << endl;
LISTEN_REQ(CMSG,Appl_Id,0,Controller,0xff,0x1FFF03FF,0,NULL,NULL);
}
}
exit=false;
if(dbg_init)
cdebug << "init : CAPIApp() beendet..." << endl;
}
// Destruktor -> CAPI abmelden usw.
CAPIApp::~CAPIApp()
{
if(dbg_init)
cdebug << "init : ~CAPIApp() aufgerufen..." << endl;
MESSAGE_EXCHANGE_ERROR ErrorCode;
ErrorCode = CAPI20_RELEASE(Appl_Id);
if (ErrorCode != 0)
cout << "Fehler: ReleaseCAPI error: 0x" << ErrorCode << endl;
if(dbg_init)
cdebug << "init : ~CAPIApp() beendet..." << endl;
}
bool CAPIApp::Run()
{
while(!exit)
{
pthread_testcancel(); // Thread beenden wenn gewuenscht
struct timeval tv;
unsigned int Info;
tv.tv_sec = 600;
tv.tv_usec = 0;
CAPI20_WaitforMessage(Appl_Id, &tv);
switch(Info = capi_get_cmsg(CMSG, Appl_Id))
{
case 0x0000:
switch (CMSG->Subcommand)
{
case CAPI_CONF:
if(dbg_capiconf)
cdebug << "capiconf : Received CAPI_CONF!" << endl;
HandleConf();
break;
case CAPI_IND:
if(dbg_capiind)
cdebug << "capiind : Received CAPI_IND!" << endl;
HandleInd();
break;
default:
cdebug << "error : unknown subcommand " << CMSG->Subcommand << endl;
break;
}
break;
case 0x1104:
if(dbg_capireq || dbg_capiresp || dbg_capiconf || dbg_capiind || dbg_systeminfo)
{
time_t t;
time(&t);
cdebug << "info : nothing received @" << ctime(&t) << endl;
if(dbg_systeminfo)
malloc_stats();
}
break;
default:
cdebug << "error : ignoring CAPI_GET_CMSG Info == " << Info << endl;
break;
}
} // while !exit
exit=false;
return 0;
}
CAPIConn * CAPIApp::byPLCI(unsigned long int plci)
{
CAPIConn *x=C[plci];
if(x==NULL)
throw 1;
return C[plci];
}
CAPIConn * CAPIApp::byNCCI(unsigned long int ncci)
{
return byPLCI(ncci & 0x0000ffff);
}
void CAPIApp::HandleConf()
{
switch(CMSG->Command)
{
case CAPI_FACILITY:
if(dbg_capiconf)
cdebug << "capiconf : FAC_CONF " << FACILITY_CONF_INFO(CMSG) << " x " << endl;
// for(int i=1;i<=(unsigned char)(FACILITY_CONF_FACILITYCONFIRMATIONPARAMETER(CMSG)[0]);i++)
// cdebug << (unsigned short int )FACILITY_CONF_FACILITYCONFIRMATIONPARAMETER(CMSG)[i] << " ";
// cdebug << endl;
// Conns[((FACILITY_CONF_NCCI(CMSG))&0x0000ffff)]->FacilityConf(CMSG);
break;
case CAPI_LISTEN:
if(dbg_capiconf)
cdebug << "capiconf : LISTEN_CONF" << endl;
break;
case CAPI_ALERT:
if(dbg_capiconf)
cdebug << "capiconf : ALERT_CONF" << endl;
// Conns[ALERT_CONF_PLCI(CMSG)]->AlertConf(CMSG);
break;
case CAPI_DATA_B3:
if(dbg_capiconf)
cdebug << "capiconf : DATA_B3_CONF Conf_Info:" << DATA_B3_CONF_INFO(CMSG) << " Handle:" << DATA_B3_CONF_DATAHANDLE(CMSG) << endl;
((CAPIConn*)byNCCI(DATA_B3_CONF_NCCI(CMSG)))->DataConf(CMSG);
break;
case CAPI_INFO:
if(dbg_capiconf)
cdebug << "capiconf : INFO_CONF Info:" << INFO_CONF_INFO(CMSG) << endl;
break;
default:
if(dbg_capiconf)
cdebug << "capiconf : Warning! CAPI_CONF Cmd=" << (unsigned int)CMSG->Command << endl;
break;
}
}
void CAPIApp::HandleInd()
{
pthread_t dummyh;
if(dbg_capiind)
cdebug << "IND MsgNumber:" << CMSG->Messagenumber << endl;
switch(CMSG->Command)
{
case CAPI_CONNECT:
if(dbg_capiind)
cdebug << "IND CONNECT PLCI=" << CONNECT_IND_PLCI(CMSG) << endl;
if(playaudio)
pthread_create(&dummyh,NULL,&PlayNameThread,new string(getCallingNumber(CMSG)));
// Konfiguration lesen
C[CONNECT_IND_PLCI(CMSG)]=cConf->getCAPIConn(CMSG,Appl_Id,&C);
if( ((CAPIConn*)byPLCI(CONNECT_IND_PLCI(CMSG))) !=NULL )
((CAPIConn*)byPLCI(CONNECT_IND_PLCI(CMSG)))->Connect(CMSG);
else
cdebug << "Unbekannte PLCI..." << endl;
break;
case CAPI_CONNECT_ACTIVE:
if(dbg_capiind)
cdebug << "IND CONNECT_ACTIVE" << endl;
((CAPIConn*)byPLCI(CONNECT_ACTIVE_IND_PLCI(CMSG)))->ConnectActive(CMSG);
break;
case CAPI_CONNECT_B3:
if(dbg_capiind)
cdebug << "IND CONNECT_B3 " << endl;
((CAPIConn*)byNCCI(CONNECT_B3_IND_NCCI(CMSG)))->ConnectB3(CMSG);
break;
case CAPI_CONNECT_B3_ACTIVE:
if(dbg_capiind)
cdebug << "IND CONNECT_B3_ACTIVE " << endl;
((CAPIConn*)byNCCI(CONNECT_B3_ACTIVE_IND_NCCI(CMSG)))->ConnectB3Active(CMSG);
break;
case CAPI_DATA_B3:
if(dbg_capiind)
cdebug << "IND DATA_B3 " << endl;
((CAPIConn*)byNCCI(DATA_B3_IND_NCCI(CMSG)))->B3Data(CMSG);
break;
case CAPI_FACILITY:
if(dbg_capiind)
cdebug << "IND FACILITY " << endl;
((CAPIConn*)byPLCI(FACILITY_IND_PLCI(CMSG)))->Facility(CMSG);
break;
case CAPI_INFO:
if(dbg_capiind)
cdebug << "IND INFO" << endl;
try{
((CAPIConn*)byPLCI(INFO_IND_PLCI(CMSG)))->InfoInd(CMSG);
}
catch(int i) {
if(i==1)
cdebug << "Info_Ind unbekannte PLCI=" << INFO_IND_PLCI(CMSG) << endl;
}
break;
case CAPI_DISCONNECT:
if(dbg_capiind)
cdebug << "IND DISCONNECT reason=" << DISCONNECT_IND_REASON(CMSG) << endl;
byPLCI(DISCONNECT_IND_PLCI(CMSG))->Disconnect(CMSG);
delete byPLCI(DISCONNECT_IND_PLCI(CMSG));
break;
case CAPI_DISCONNECT_B3:
if(dbg_capiind)
cdebug << "IND DISCONNECT_B3 reason=" << DISCONNECT_B3_IND_REASON_B3(CMSG) << endl;
((CAPIConn*)byNCCI(DISCONNECT_B3_IND_NCCI(CMSG)))->DisconnectB3(CMSG);
break;
default:
cdebug << "Unhandled Ind. Cmd=" << (unsigned int) CMSG->Command << endl;
}
}