/* * This file is part of the Dialogic Woomera Server project. * * * Copyright (C) 2009 Dialogic Corporation * All Rights Reserved * */ /*! * \file dialogicmanager.h * \brief * \author Antony Martin * \version 30-March-2009 Prototype */ /*-------------------------------- Dependencies ------------------------------*/ #include // memset #include #include #define lint #include #undef lint #include "logger.h" //#include "CGcIsdnDevice.h" #include "dialogicmanager.h" /*----------------------------------------------------------------------------*/ bool DialogicManager::init() { /* Init Dialogic standard runtime lib. */ if ( !initSrlMode() ) { return false; } /* Start GlobalCall using DM3 and IPM. Add others (SS7 etc) as needed. */ GC_START_STRUCT gcLibStart; memset(&gcLibStart, 0, sizeof(GC_START_STRUCT)); CCLIB_START_STRUCT ccstart[] = { { (char*)"GC_DM3CC_LIB", NULL }, { (char*)"GC_IPM_LIB", NULL } }; gcLibStart.cclib_list = ccstart; gcLibStart.num_cclibs = 2; if ( gc_Start (&gcLibStart) != GC_SUCCESS ) { LOGCRIT ("DialogicManager::Initialize() gc_Start Failed"); return false; } /* Set the flag m_gcStarted to YES */ //$$FIXME SetGcStarted (true); //$$FIXME Load config from file? // Auto detect devices if ( !getDevices() ) { return false; } /*$$AM if ( !createDevices() ) { return false; } if ( !GetNumDevices() ) { LOGCRIT ("DialogicManager::Initialize() No Dialogic devices found"); return false; } */ return true; } /* * SRL MODEL TYPE - Single Threaded Async, event handler will be called in the Main thread */ bool DialogicManager::initSrlMode() { #ifdef _WIN32 int mode = SR_STASYNC | SR_POLLMODE; #else int mode = SR_POLLMODE; #endif /* Set SRL mode */ #ifdef _WIN32 if ( sr_setparm(SRL_DEVICE, SR_MODELTYPE, &mode) == -1 ) { LOGCRIT("Unable to set to SR_STASYNC | SR_POLLMODE."); return false; } LOGDEBUG("SRL Model Set to SR_STASYNC | SR_POLLMODE"); #else if ( sr_setparm(SRL_DEVICE, SR_MODEID, &mode) == -1 ) { LOGCRIT("Unable to set mode ID to SR_POLLMODE."); return false; } LOGDEBUG("SRL Model Set to SR_STASYNC | SR_POLLMODE"); #endif return true; } void DialogicManager::shutdown() { //$$AM closeAllDevices(); LOGDEBUG("DialogicManager::shutdown() Stopping Global Call"); gc_Stop(); } /* * Auto detect devices */ bool DialogicManager::getDevices() { /* Determine number of physical boards by passing 0 * Physical Board count and NULL Auid device info. * Function will fail but number of Physical Boards will be returned */ int physicalBoards = 0; long rc = SRLGetAllPhysicalBoards(&physicalBoards, NULL); if ( rc != ESR_INSUFBUF ) { /* If error other than ESR_INSUFBUF then either no virtual boards * or other unexpected error */ LOGERROR("DialogicManager::getBoards() SRLGetAllPhysicalBoards() failed, error = 0x" << std::hex << rc); return false; } // Allocate memory for array of AUIDs AUID* auids = new AUID[physicalBoards]; // Retrieve physical board info rc = SRLGetAllPhysicalBoards(&physicalBoards, auids); if ( rc != ESR_NOERR ) { LOGERROR("DialogicManager::getBoards() SRLGetAllPhysicalBoards failed, error = 0x" << std::hex << rc); delete[] auids; return false; } /* ----------------------------------------------------------------- * For each Physical Board AUID, determine associated virtual board */ for ( int indxPhys = 0; indxPhys < physicalBoards; indxPhys++ ) { // Set the AUID pointer to the current item AUID *auid = &auids[indxPhys]; /* Determine number of virtual boards by passing 0 * Virtual Boardcount and NULL SRL device info. * Function will fail but number of virtual boards will be returned */ int nVirtualBoards = 0; SRLDEVICEINFO *srlBoards = NULL; // SRL Device Info for virtual board rc = SRLGetVirtualBoardsOnPhysicalBoard(*auid, &nVirtualBoards, srlBoards); if ( rc != ESR_INSUFBUF ) { /* If error other than ESR_INSUFBUF then either no virtual boards * or other unexpected error */ LOGERROR("SRLGetVirtualBoardsOnPhysicalBoard() failed, error = 0x" << std::hex << rc); delete[] auids; return false; } // Allocate memory for number of virtual boards found srlBoards= new SRLDEVICEINFO[nVirtualBoards]; // Now retrieve all virtual boards on physical board rc = SRLGetVirtualBoardsOnPhysicalBoard(*auid, &nVirtualBoards, srlBoards); if ( rc != ESR_NOERR ) { LOGERROR("DialogicManager::getBoards() SRLGetVirtualBoardsOnPhysicalBoard() failed, error = 0x" << std::hex << rc); delete[] srlBoards; delete[] auids; return false; } /* ------------------------------------------------------------- * For each virtual board, determine associated virtual channels */ for ( int indxBoard = 0; indxBoard < nVirtualBoards; indxBoard++ ) { // Set the Board pointer to the current item SRLDEVICEINFO *srlBoard = &srlBoards[indxBoard]; int nVirtualChans = 0; /* Determine number of virtual channels by passing 0 * Virtual Channel count and NULL SRL device info. * Function will fail but number of virtual channels will * be returned. */ rc = SRLGetSubDevicesOnVirtualBoard(srlBoard->szDevName, &nVirtualChans, NULL); if ( rc != ESR_INSUFBUF ) { /* If error other than ESR_INSUFBUF then either no virtual * channels or other unexpected error. */ LOGERROR("DialogicManager::getBoards() SRLGetSubDevicesOnVirtualBoard() failed, error = 0x" << std::hex << rc); delete[] srlBoards; delete[] auids; return false; } // Allocate memory for number of virtual channels found SRLDEVICEINFO* srlChannels = new SRLDEVICEINFO[nVirtualChans]; // Now retrieve all virtual channels on physical board rc = SRLGetSubDevicesOnVirtualBoard(srlBoard->szDevName, &nVirtualChans, srlChannels); if ( rc != ESR_NOERR ) { LOGERROR( "DialogicManager::getBoards() SRLGetSubDevicesOnVirtualBoard() failed, error = 0x" << std::hex << rc); delete[] srlChannels; delete[] srlBoards; delete[] auids; return false; } /* --------------------------------------------------------- * For each virtual channel, display associated AUID, * virtual board and device type. */ for ( int indxChan = 0; indxChan < nVirtualChans; indxChan++ ) { // Set the Channel pointer to the current item SRLDEVICEINFO *srlChannel = &srlChannels[indxChan]; std::string devType = "unknown"; switch ( srlChannel->iDevType ) { case TYPE_R4_VOX_CHANNEL: // 502 E.g., dxxxB1C1 voxBoards_.push_back (srlChannel); devType = "R4_VOX_CHANNEL"; voxChannels_++; break; case TYPE_R4_DTI_TIMESLOT: // 504 E.g., dxxxB1T1 dtiBoards_.push_back (srlChannel); devType = "R4_DTI_TIMESLOT"; dtiChannels_++; break; case TYPE_R4_IPM_CHANNEL: // 528 E.g., ipmB1C1 devType = "R4_IPM_CHANNEL"; ipmBoards_.push_back (srlChannel); ipmChannels_++; break; default: break; } /* Display AUID, virtual board, virtual channel and device type. * Device type values found in devmapr4.h */ LOGINFO("DialogicManager::getBoards() " << *auid << "\t" << srlBoard->szDevName << "\t" << srlChannel->szDevName << "\t" << srlChannel->iDevType << " (" << devType << ")"); } // end virtual channel loop delete[] srlChannels; } // end virtual board loop LOGINFO("DialogicManager::getBoards() Physical Board No:" << indxPhys << " has " << voxBoards_.size () << " Vox channels, " << dtiBoards_.size () << " DTI channels, " << ipmBoards_.size () << " IPM channels."); delete[] srlBoards; } // end physical board loop delete[] auids; return true; } /* * vim:ts=4:set nu: */