download otdialdrv.cpp
Language: C++
Copyright: (c) 1995-99 OpenComm do Brasil Ltda.
LOC: 261
Project Info
Open Telephony Server(opentel)
Server: SourceForge
Type: cvs
...el\server\drivers\dialogic\
   dialogic.dsp
   otdialap.cpp
   otdialap.h
   otdialar.cpp
   otdialar.h
   otdialdev.h
   otdialdrv.cpp
   otdialdrv.h
   otdialdti.cpp
   otdialdti.h
   otdialdxx.cpp
   otdialdxx.h
   otdialei.cpp
   otdialei.h
   otdialev.cpp
   otdialev.h
   otdialex.cpp
   otdialex.h
   otdialgc.cpp
   otdialgc.h
   otdialmsi.cpp
   otdialmsi.h
   otdialogic.cpp
   otdialogic.h
   otdialsc.cpp
   otdialsc.h
   otdialtd.cpp
   otdialtd.h
   otdialtg.cpp
   otdialtg.h

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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
/*****************************************************************************
* OpenTel Telephony Server & Framework
* Copyright (c) 1995-99 OpenComm do Brasil Ltda.
* Todos os direitos reservados.
* Este arquivo contem material confidencial de OpenComm do Brasil, e deve
* darse tratamento como tal.
******************************************************************************/

#ident "@(#) $Header: /cvsroot/opentel/opentel/server/drivers/dialogic/otdialdrv.cpp,v 1.3 2000/04/21 20:27:30 jbernab Exp $"


#include <otconfig.h>

#ifdef _WINDOWS
#include <windows.h>
#include <io.h>
#endif


extern "C" {
#include <srllib.h>
#include <dxxxlib.h>
#include <string.h>
#include <stdio.h>
#include <malloc.h>
};


#include <otserver.includes>

#include <dialogic/otdialdrv.h>
#include <dialogic/otdialar.h>
#include <dialogic/otdialap.h>
#include <dialogic/otdialtd.h>
#include <dialogic/otdialtg.h>
#include <dialogic/otdialei.h>

#ifdef CONFIG_DIALOGIC_MSI
#include <dialogic/otdialmsi.h>
#endif

#include <dialogic/otdialev.h>

#ifdef CONFIG_DIALOGIC_GC
#include <dialogic/otdialgc.h>
#endif

#include <dialogic/otdialsc.h>

#include <otresgroup.includes>
#include <otgroupmgr.includes>
#include <otnum.includes>
#include <otpstnint.includes>


OT_IMPLEMENT_DYNCREATE(OtDialogicDriverThread, OtDriver);


OtDialogicDriverThread::OtDialogicDriverThread() :
        OtDriver("OtDialogicDriverThread"),
        _msec(100)
{
        static int inited=0;
        if(!inited) {
#ifdef _WINDOWS
				sr_libinit(DLGC_MT);
#ifdef CONFIG_DIALOGIC_DXX
				dx_libinit(DLGC_MT);
#endif
#endif
				inited=1;
                int mode=SR_POLLMODE;
                sr_setparm(SRL_DEVICE,SR_MODEID,&mode);
                }

}

OtDialogicDriverThread::~OtDialogicDriverThread()
/////////////////////////////////////////////////
{
        // @j@: agregar a OtList: removeAllElements( bool deleteThem )
        #define DESTROY_RESOURCE_LIST( type, listName ) \
                OtListCursor< type > __var##type##__( listName ); \
                for (   __var##type##__.first(); \
                                __var##type##__.current(); \
                                __var##type##__.next() ) \
                        delete ( __var##type##__.current() );

        DESTROY_RESOURCE_LIST( OtAudioPlayer, m_audioPlayers );
        DESTROY_RESOURCE_LIST( OtAudioRecorder, m_audioRecorders );
        DESTROY_RESOURCE_LIST( OtToneDetector, m_toneDetectors );
        DESTROY_RESOURCE_LIST( OtToneGenerator, m_toneGenerators );
        DESTROY_RESOURCE_LIST( OtCallChannel, m_callChannels );
        DESTROY_RESOURCE_LIST( OtDialogicDxx, m_dxxs );
        DESTROY_RESOURCE_LIST( OtDialogicMsiDev, m_msis );

}


void OtDialogicDriverThread::run(void)
{
        OtDialogicEvent *e;
        OtMessageTarget *t;
        while(!isInterrupted()) {
                if((e=OtDialogicDev::waitEvent(_msec))!=NULL) {
                        if(t=OtDialogicDev::findTargetDevice(e)) {
                                OtDlgMsg m(e);
                                t->onMessage(&m);
                                delete e;
                                }
                        while((e=OtDialogicDev::waitEvent(0))!=NULL) {
                                if(t=OtDialogicDev::findTargetDevice(e)) {
                                        OtDlgMsg m(e);
                                        t->onMessage(&m);
                                        delete e;
                                        }
                                }
                        }
                yield();
                }
}

void OtDialogicDriverThread::initMsi(const OtBus &theBus, long board, long dev)
{
#ifdef CONFIG_DIALOGIC_MSI
	// Create the msi ExtInterface  & ResourceGroup
        OtDialogicMsiDev *msi   = NULL;
        OtDialogicExtInterface *ei = NULL;

        OtString tmp = "msiB"+ OtString(OtNum(board)) + "C" +
                        OtString(OtNum(dev)) ;

        m_msis.add( msi = new OtDialogicMsiDev( tmp, (OtBus*)(&theBus) ) );
        m_callChannels.add( ei = new OtDialogicExtInterface( msi ));

        // Creates the Resource group for the Extension Interface
        OtResourceGroup* rg = new OtResourceGroup;
        rg->addResource( *ei );

        // gives a reference the to the GroupMgr
        OtServer::GetInstance()->getGroupMgr().addResourceGroup( rg );
#endif
}

void OtDialogicDriverThread::initDtiGc(const OtBus &theBus, long board, long dev, const OtString &protocol)
{
#ifdef CONFIG_DIALOGIC_GC
	OtString tmp;

        OtDialogicGc* cc                = NULL;

        tmp = ":N_dtiB" + OtString(OtNum(board)) + "T" + OtString(OtNum( dev )) + ":P_" + protocol;

        m_callChannels.add( cc = new OtDialogicGc( tmp, OtPSTNInterface::Inbound, (OtBus*)(&theBus) ) );

        //
        //
        //
        OtResourceGroup* rg1 = new OtResourceGroup;
        rg1->addResource( *cc );

        // gives a reference to the GroupMgr
        OtServer::GetInstance()->getGroupMgr().addResourceGroup( rg1 );
#endif
}

void OtDialogicDriverThread::initDxx(const OtBus &theBus, long board, long dev)
{
        OtDialogicDxx* dxx              = NULL;
        OtDialogicAudioPlayer* ap       = NULL;
        OtDialogicAudioRecorder* ar = NULL;
        OtDialogicToneDetector* td      = NULL;
        OtDialogicToneGenerator* tg = NULL;
        OtString tmp;

        tmp = OtString("dxxxB")+ OtString((char *)OtNum(board)) + OtString("C") +  OtString((char *)OtNum(dev)) ;

		OtDebug(OT_DEBUG_DXX, "Dialogic: opening device %s\n", (char *)tmp);

        m_dxxs.add( dxx = new OtDialogicDxx( tmp, (OtBus*)(&theBus)) );
        m_toneGenerators.add( tg = new OtDialogicToneGenerator( dxx ) );
        m_toneDetectors.add( td = new OtDialogicToneDetector( dxx ) );

        //
        // TODO: Check if this dxx supports audio playing and recording
        //
        m_audioPlayers.add( ap = new OtDialogicAudioPlayer( dxx ) );
        m_audioRecorders.add( ar = new OtDialogicAudioRecorder( dxx ) );

        OtResourceGroup* rg = new OtResourceGroup;
        rg->addResource( *tg );
        rg->addResource( *td );
        rg->addResource( *ap );
        rg->addResource( *ar );
        // gives the ownership
        OtServer::GetInstance()->getGroupMgr().addResourceGroup( rg );
}


/* This opens all the resources and needed objects for the low level
Dialogic implementation of the resources and etc.
This class owns the resources, but gives ownership to the GroupMgr
of the resourceGroups that it creates to contain them.
*/
void OtDialogicDriverThread::initialize( OtDriverConfig &drvConfig )
////////////////////////////////////////////////////
{
	OtWarning("Dialogic Driver v.1.0.1 Starting\n");
	//	OtWarning("$Id: otdialdrv.cpp,v 1.3 2000/04/21 20:27:30 jbernab Exp $\n");
	
	const std::set< OtBoardConfig * > &boards=drvConfig.getConfiguredBoard();
	
	
	std::set<OtBoardConfig *>::iterator it=boards.begin();
	std::set<OtBoardConfig *>::iterator end=boards.end();
	
	for (; it != end; it++) {
		//"Initializing Board: %s\n", (*it)->getBoardName()
		if((*it)->getBoardModel() == "ProLine/2V") {
			static OtBusSC bus;
			try {
				initDxx(bus, 1, 1);
			} catch (OtException &e) {
				OtWarning("Catched Exception: %s\n", (const char *)e.getErr());
			}
			try {
				initDxx(bus, 1, 2);
			} catch (OtException &e) {
				OtWarning("Catched Exception: %s\n", (const char *)e.getErr());
			}
		} else if((*it)->getBoardModel() == "DTI212-E1") {
		} else if((*it)->getBoardModel() == "D300SC-E1") {
			static OtBusSC bus;
			for ( int channel = 1; channel <= 30; channel++ )
			{
				int board  = ((channel - 1 ) / 30 )+1;
				int cchannel = channel - (30 *(( channel - 1 ) / 30));
				int vBoard		= ( cchannel - 1 ) / 4 + 1 + (8*(board-1));
				int vChannel	= ( cchannel - 1 ) % 4 + 1 ;
				try {				
					initDxx(bus, vBoard, vChannel);
				} catch (OtException &e) {
					OtWarning("Catched Exception: %s\n", (const char *)e.getErr());
				}
				try {
					initDtiGc(bus, board, cchannel, "br_r2_i");
				} catch (OtException &e) {
					OtWarning("Catched Exception: %s\n", (const char *)e.getErr());
				}
			} // for
			
		} else if((*it)->getBoardModel() == "DMX") {
		} else if((*it)->getBoardModel() == "MSI80SC-R") {
		} else if((*it)->getBoardModel() == "MSI160SC-R") {
		} else if((*it)->getBoardModel() == "MSI240SC-R") {
		} else if((*it)->getBoardModel() == "MSI80SC") {
		} else if((*it)->getBoardModel() == "MSI160SC") {
		} else if((*it)->getBoardModel() == "MSI240SC") {
		} else {
			OtWarning("Board model not supported: %s\n", (*it)->getBoardModel());
		}
	}
	
#if 0
	const OtBus& bus = OtServer::GetInstance()->getBus();
	
	//
	// Create the Msi ExtInterfaces ResourceGroups
	//
	for ( int channel = 1; channel <= 8; channel++ )
	{
		int vBoard		= ( channel - 1 ) / 24 + 1;
		int vChannel	= ( channel - 1 ) % 24 + 1;
		
		initMsi(bus, vBoard, vChannel);
	} // for
	
	
	//
	// Create the dti devices with global call binding
	// and Brazilian r2 protocol driver
	
	for ( channel = 1; channel <= 120; channel++ )
	{
		int board  = ((channel - 1 ) / 30 )+1;
		int cchannel = channel - (30 *(( channel - 1 ) / 30));
		initDtiGc(bus, board, cchannel, "br_r2_i");
	}
	
#if 0
	for ( int channel = 31; channel <= 60; channel++ )
	{
		int board  = ((channel - 1 ) / 30 )+1;
		int cchannel = channel - (30 *(( channel - 1 ) / 30));
		initDtiGc(bus, board, cchannel, "br_r2_o");
	}
#endif
	
	
	//
	// Create the resources from the Dxx devices
	//
	for ( channel = 1; channel <= 120; channel++ )
	{
		int board  = ((channel - 1 ) / 30 )+1;
		int cchannel = channel - (30 *(( channel - 1 ) / 30));
		int vBoard		= ( cchannel - 1 ) / 4 + 1 + (8*(board-1));
		int vChannel	= ( cchannel - 1 ) % 4 + 1 ;
		
		initDxx(bus, vBoard, vChannel);
	} // for
#endif
}



/////////////////////////////////////////////
#if 0
OtDialogicDriverThread::InitDriver()
{
        loadConfig();
        openDevices();
}

OtDialogicDriverThread::loadConfig()
{
        if("dxxx") {
                OtGroup *g=new OtGroup();
                g->Set
}

#endif

#if 0
OtDialogicD300E1SC::OtDialogicD300E1SC(int board, LineDirect dir) :
        _board(board)
{
        for(int i=1;i<1+getNumDevs();i++) {
                char tmp[50];
                int vbnum=(i-1)/4+1+(8*(board-1));
                int vch=(i-1)%4+1;
                sprintf(tmp,":N_dtiB%dT%d:P_br_r2_%c:V_dxxxB%dC%d",_board,i,dir == OUTBOUND ? 'o' : 'i', vbnum,vch);
//              printf("%s\n",tmp);
                switch(dir) {
                        case INBOUND:
                                _devs[i-1]=new OtDialogicGc(tmp,OtCallChannel::Inbound);
                                break;
                        case OUTBOUND:
                                _devs[i-1]=new OtDialogicGc(tmp,OtCallChannel::Outbound);
                                break;
                        }
                _devs[i-1]->Open();
                }
}

OtDialogicD300E1SC::~OtDialogicD300E1SC(void)
{
        for(int i=0;i<getNumDevs();i++) {
                if(_devs[i]) {
                        delete(_devs[i]);
                        _devs[i]=NULL;
                        }
                }
}








#endif

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us