[server] / trunk / server / src / dialogicmanager.cxx Repository:
ViewVC logotype

View of /trunk/server/src/dialogicmanager.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (download) (annotate)
Fri Apr 3 16:56:49 2009 UTC (4 years, 2 months ago) by jtarlton
File size: 9221 byte(s)
    1 /*
    2  * This file is part of the Dialogic Woomera Server project.
    3  *
    4  *
    5  * Copyright (C) 2009 Dialogic Corporation
    6  * All Rights Reserved
    7  *
    8  */
    9 
   10 /*!
   11  * \file        dialogicmanager.cxx
   12  * \brief
   13  * \author      Antony Martin <antony.martin@dialogic.com>
   14  * \version     30-March-2009 Prototype
   15  */
   16 
   17 /*-------------------------------- Dependencies ------------------------------*/
   18 
   19 #include <string.h>        // memset
   20 #include <gclib.h>
   21 #include <srllib.h>
   22 
   23 #define lint
   24 #include <devmapr4.h>
   25 #undef  lint
   26 
   27 #include "logger.h"
   28 
   29 #include "dialogicmanager.h"
   30 #include "dialogicdevice.h"
   31 #include "gcdevice.h"
   32 #include "gcisdndevice.h"
   33 #include "voxdevice.h"
   34 #include "ipmdevice.h"
   35 
   36 
   37 /*----------------------------------------------------------------------------*/
   38 
   39 /*
   40  *
   41  */
   42 bool DialogicManager::init()
   43 {
   44   /* Init Dialogic standard runtime lib.
   45    */
   46   if ( !initSrlMode() )
   47   {
   48     return false;
   49   }
   50 
   51   /* Start GlobalCall using DM3 and IPM. Add others (SS7 etc) as needed.
   52    */
   53   GC_START_STRUCT gcLibStart;
   54   memset(&gcLibStart, 0, sizeof(GC_START_STRUCT));
   55 
   56   CCLIB_START_STRUCT ccstart[] = {
   57     { (char*)"GC_DM3CC_LIB", NULL },
   58     { (char*)"GC_IPM_LIB",   NULL }
   59   };
   60 
   61   gcLibStart.cclib_list = ccstart;
   62   gcLibStart.num_cclibs = 2;
   63 
   64   if ( gc_Start (&gcLibStart) != GC_SUCCESS )
   65   {
   66     LOGCRIT ("DialogicManager::Initialize() gc_Start Failed");
   67     return false;
   68   }
   69 
   70   /* Set the flag m_gcStarted to YES */
   71   //$$FIXME   SetGcStarted (true);
   72 
   73   //$$FIXME Load config from file?
   74 
   75   // Auto detect devices
   76   if ( !getDevices() )
   77   {
   78     return false;
   79   }
   80 
   81 /*$$AM
   82   if ( !createDevices() )
   83   {
   84     return false;
   85   }
   86 
   87   if ( !GetNumDevices() )
   88   {
   89     LOGCRIT ("DialogicManager::Initialize() No Dialogic devices found");
   90     return false;
   91   }
   92   */
   93   return true;
   94 }
   95 
   96 /*
   97  *  SRL MODEL TYPE - Single Threaded Async, event handler will be called in the Main thread
   98  */
   99 bool DialogicManager::initSrlMode()
  100 {
  101 #ifdef _WIN32
  102   int mode = SR_STASYNC | SR_POLLMODE;
  103 #else
  104   int mode = SR_POLLMODE;
  105 #endif
  106 
  107 /* Set SRL mode */
  108 #ifdef _WIN32
  109   if ( sr_setparm(SRL_DEVICE, SR_MODELTYPE, &mode) == -1 )
  110   {
  111     LOGCRIT("Unable to set to SR_STASYNC | SR_POLLMODE.");
  112     return false;
  113   }
  114   LOGDEBUG("SRL Model Set to SR_STASYNC | SR_POLLMODE");
  115 #else
  116   if ( sr_setparm(SRL_DEVICE, SR_MODEID, &mode) == -1 )
  117   {
  118     LOGCRIT("Unable to set mode ID to SR_POLLMODE.");
  119     return false;
  120   }
  121   LOGDEBUG("SRL Model Set to SR_STASYNC | SR_POLLMODE");
  122 #endif
  123 
  124   return true;
  125 }
  126 
  127 
  128 /*
  129  *
  130  */
  131 void DialogicManager::shutdown()
  132 {
  133 //$$AM  closeAllDevices();
  134 
  135   LOGDEBUG("DialogicManager::shutdown() Stopping Global Call");
  136   gc_Stop();
  137 }
  138 
  139 
  140 /*
  141  * Auto detect devices
  142  */
  143 bool DialogicManager::getDevices()
  144 {
  145   /* Determine number of physical boards by passing 0
  146    * Physical Board count and NULL Auid device info.
  147    * Function will fail but number of Physical Boards will be returned
  148    */
  149   int physicalBoards = 0;
  150   long rc = SRLGetAllPhysicalBoards(&physicalBoards, NULL);
  151   if ( rc != ESR_INSUFBUF )
  152   {
  153     /* If error other than ESR_INSUFBUF then either no virtual boards
  154      * or other unexpected error
  155      */
  156     LOGERROR("DialogicManager::getBoards() SRLGetAllPhysicalBoards() -1- failed, error = 0x" << std::hex << rc);
  157     return false;
  158   }
  159 
  160   AUID* auids = new AUID[physicalBoards];
  161 
  162   rc = SRLGetAllPhysicalBoards(&physicalBoards, auids);
  163   if ( rc != ESR_NOERR )
  164   {
  165     LOGERROR("DialogicManager::getBoards() SRLGetAllPhysicalBoards() -2- failed, error = 0x" << std::hex << rc);
  166     delete[] auids;
  167     return false;
  168   }
  169 
  170   /* -----------------------------------------------------------------
  171    * For each Physical Board AUID, determine associated virtual board
  172    */
  173   for ( int indxPhys = 0; indxPhys < physicalBoards; indxPhys++ )
  174   {
  175     AUID *auid = &auids[indxPhys];
  176 
  177     /* Determine number of virtual boards by passing 0
  178      * Virtual Boardcount and NULL SRL device info.
  179      * Function will fail but number of virtual boards will be returned
  180      */
  181     int nVirtualBoards = 0;
  182     SRLDEVICEINFO *srlBoards = NULL; // SRL Device Info for virtual board
  183     rc = SRLGetVirtualBoardsOnPhysicalBoard(*auid, &nVirtualBoards, srlBoards);
  184     if ( rc != ESR_INSUFBUF )
  185     {
  186       /* If error other than ESR_INSUFBUF then either no virtual boards
  187        * or other unexpected error
  188        */
  189       LOGERROR("DialogicManager::getBoards() SRLGetVirtualBoardsOnPhysicalBoard() -1- failed, error = 0x" << std::hex << rc);
  190       delete[] auids;
  191       return false;
  192     }
  193     LOGINFO("DialogicManager::getBoards() VirtualBoards = " << nVirtualBoards);
  194 
  195     srlBoards= new SRLDEVICEINFO[nVirtualBoards];
  196 
  197     rc = SRLGetVirtualBoardsOnPhysicalBoard(*auid, &nVirtualBoards, srlBoards);
  198     if ( rc != ESR_NOERR )
  199     {
  200       LOGERROR("DialogicManager::getBoards() SRLGetVirtualBoardsOnPhysicalBoard() -2- failed, error = 0x" << std::hex << rc);
  201       delete[] srlBoards;
  202       delete[] auids;
  203       return false;
  204     }
  205 
  206     /* For each virtual board, determine associated virtual channels
  207      */
  208     for ( int indxBoard = 0; indxBoard < nVirtualBoards; indxBoard++ )
  209     {
  210       SRLDEVICEINFO *srlBoard = &srlBoards[indxBoard];
  211 
  212       int nVirtualChans = 0;
  213       /* Determine number of virtual channels by passing 0
  214        * Virtual Channel count and NULL SRL device info.
  215        * Function will fail but number of virtual channels will
  216        * be returned.
  217        */
  218       rc = SRLGetSubDevicesOnVirtualBoard(srlBoard->szDevName, &nVirtualChans, NULL);
  219       if ( rc != ESR_INSUFBUF && rc != ESR_NOERR )
  220       {
  221         /* If error other than ESR_INSUFBUF then either no virtual
  222          * channels or other unexpected error.
  223          */
  224         LOGERROR("DialogicManager::getBoards() SRLGetSubDevicesOnVirtualBoard() -1- failed, error = 0x" << std::hex << rc);
  225         delete[] srlBoards;
  226         delete[] auids;
  227         return false;
  228       }
  229 
  230       SRLDEVICEINFO* srlChannels = new SRLDEVICEINFO[nVirtualChans];
  231 
  232       rc = SRLGetSubDevicesOnVirtualBoard(srlBoard->szDevName, &nVirtualChans, srlChannels);
  233       if ( rc != ESR_NOERR )
  234       {
  235         LOGERROR( "DialogicManager::getBoards() SRLGetSubDevicesOnVirtualBoard() -2- failed, error = 0x" << std::hex << rc);
  236         delete[] srlChannels;
  237         delete[] srlBoards;
  238         delete[] auids;
  239         return false;
  240       }
  241 
  242       /* For each virtual channel, display associated AUID,
  243        * virtual board and device type.
  244        */
  245       for ( int indxChan = 0; indxChan < nVirtualChans; indxChan++ )
  246       {
  247         SRLDEVICEINFO *srlChannel = &srlChannels[indxChan];
  248 
  249         std::string devType = "unknown";
  250         switch ( srlChannel->iDevType )
  251         {
  252           case TYPE_R4_VOX_CHANNEL:      // 502 E.g., dxxxB1C1
  253             voxBoards_.push_back (srlChannel);
  254             devType = "R4_VOX_CHANNEL";
  255             voxChannels_++;
  256             break;
  257 
  258           case TYPE_R4_DTI_TIMESLOT:     // 504 E.g., dxxxB1T1
  259             dtiBoards_.push_back (srlChannel);
  260             devType = "R4_DTI_TIMESLOT";
  261             dtiChannels_++;
  262             break;
  263 
  264           case TYPE_R4_IPM_CHANNEL:      // 528 E.g., ipmB1C1
  265             devType = "R4_IPM_CHANNEL";
  266             ipmBoards_.push_back (srlChannel);
  267             ipmChannels_++;
  268             break;
  269 
  270           default:
  271             break;
  272         }
  273 
  274         /* Display AUID, virtual board, virtual channel and device type.
  275          * Device type values found in devmapr4.h
  276          */
  277         LOGINFO("DialogicManager::getBoards() " << *auid
  278           << "\t" << srlBoard->szDevName
  279           << "\t" << srlChannel->szDevName
  280           << "\t" << srlChannel->iDevType
  281           << " (" << devType << ")");
  282       }
  283 
  284       delete[] srlChannels;
  285     }
  286 
  287     LOGINFO("DialogicManager::getBoards() Physical Board No:" << indxPhys << " has "
  288       << voxBoards_.size () << " Vox channels, "
  289       << dtiBoards_.size () << " DTI channels, "
  290       << ipmBoards_.size () << " IPM channels.");
  291     delete[] srlBoards;
  292   }
  293 
  294   delete[] auids;
  295   return true;
  296 }
  297 
  298 bool DialogicManager::createDevices()
  299 {
  300   // create the devices.
  301   std::string deviceName;
  302 
  303   GcIsdnDevice *gc;
  304   int dtiChannels = dtiBoards_.size();
  305 
  306   for ( int i = 0; i < dtiChannels; i++ )
  307   {
  308     deviceName.assign(dtiBoards_[i]->szDevName);
  309     gc = new GcIsdnDevice(deviceName);
  310 
  311     if (gc)
  312     {
  313       gc->Open();
  314       deviceMap_.insert(device_map_t::value_type (deviceName, gc));
  315       m_GcDeviceStack.push(gc);
  316     }
  317     else
  318     {
  319       delete gc;
  320     }
  321     gc = NULL;
  322   }
  323 
  324   VoxDevice *vd;
  325   int voxChannels = voxBoards_.size();
  326   for (int i = 0; i < voxChannels; i++)
  327   {
  328     deviceName = voxBoards_[i]->szDevName;
  329     vd = new VoxDevice (deviceName);
  330     if (vd && vd->Open())
  331     {
  332       deviceMap_.insert(device_map_t::value_type (deviceName, vd));
  333       m_VoxDeviceStack.push(vd);
  334     }
  335     else
  336     {
  337       delete vd;
  338     }
  339     vd = NULL;
  340   }
  341 
  342   IpmDevice *id;
  343   int ipmChannels = ipmBoards_.size();
  344 
  345   for (int i = 0; i < ipmChannels; i++) {
  346     deviceName = ipmBoards_[i]->szDevName;
  347     id = new IpmDevice (deviceName);
  348     if (id && id->Open())
  349     {
  350       deviceMap_.insert(device_map_t::value_type (deviceName, id));
  351       m_IpmDeviceStack.push(id);
  352     }
  353     else
  354     {
  355       delete id;
  356     }
  357     id = NULL;
  358   }
  359 
  360 //$$AM  SetNumDevices (deviceMap_.size());
  361   return true;
  362 
  363 }
  364 
  365 void DialogicManager::openAllDevices()
  366 {
  367   device_map_t::iterator itr;
  368 
  369   for (itr = deviceMap_.begin (); itr != deviceMap_.end (); ++itr)
  370   {
  371     LOGDEBUG ("DialogicManager::openAllDevices() Opening Device: " << itr->first);
  372     itr->second->Open ();
  373   }
  374 }
  375 
  376 void DialogicManager::closeAllDevices()
  377 {
  378   device_map_t::iterator itr;
  379 
  380   for (itr = deviceMap_.begin (); itr != deviceMap_.end (); ++itr)
  381   {
  382     LOGDEBUG ("DialogicManager::closeAllDevices() Closing Device: " << itr->first);
  383     itr->second->Close();
  384   }
  385 }
  386 
  387 /*
  388  * vim:ts=4:set nu:
  389  */

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.8