/*****************************************************************************
* 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