[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 20 - (download) (annotate)
Tue Mar 31 16:04:15 2009 UTC (4 years, 1 month ago) by amartin
File size: 7908 byte(s)
Work in progress.
    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.h
   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 "CGcIsdnDevice.h"
   30 #include "dialogicmanager.h"
   31 
   32 /*----------------------------------------------------------------------------*/
   33 
   34 bool DialogicManager::init()
   35 {
   36   /* Init Dialogic standard runtime lib.
   37    */
   38   if ( !initSrlMode() )
   39   {
   40     return false;
   41   }
   42 
   43   /* Start GlobalCall using DM3 and IPM. Add others (SS7 etc) as needed.
   44    */
   45   GC_START_STRUCT gcLibStart;
   46   memset(&gcLibStart, 0, sizeof(GC_START_STRUCT));
   47 
   48   CCLIB_START_STRUCT ccstart[] = {
   49     { (char*)"GC_DM3CC_LIB", NULL },
   50     { (char*)"GC_IPM_LIB",   NULL }
   51   };
   52 
   53   gcLibStart.cclib_list = ccstart;
   54   gcLibStart.num_cclibs = 2;
   55 
   56   if ( gc_Start (&gcLibStart) != GC_SUCCESS )
   57   {
   58     LOGCRIT ("DialogicManager::Initialize() gc_Start Failed");
   59     return false;
   60   }
   61 
   62   /* Set the flag m_gcStarted to YES */
   63   //$$FIXME   SetGcStarted (true);
   64 
   65   //$$FIXME Load config from file?
   66 
   67   // Auto detect devices
   68   if ( !getDevices() )
   69   {
   70     return false;
   71   }
   72 
   73 /*$$AM
   74   if ( !createDevices() )
   75   {
   76     return false;
   77   }
   78 
   79   if ( !GetNumDevices() )
   80   {
   81     LOGCRIT ("DialogicManager::Initialize() No Dialogic devices found");
   82     return false;
   83   }
   84   */
   85   return true;
   86 }
   87 
   88 /*
   89  *    SRL MODEL TYPE - Single Threaded Async, event handler will be called in the Main thread
   90  */
   91 bool DialogicManager::initSrlMode()
   92 {
   93 #ifdef _WIN32
   94   int mode = SR_STASYNC | SR_POLLMODE;
   95 #else
   96   int mode = SR_POLLMODE;
   97 #endif
   98 
   99 /* Set SRL mode */
  100 #ifdef _WIN32
  101   if ( sr_setparm(SRL_DEVICE, SR_MODELTYPE, &mode) == -1 )
  102   {
  103     LOGCRIT("Unable to set to SR_STASYNC | SR_POLLMODE.");
  104     return false;
  105   }
  106   LOGDEBUG("SRL Model Set to SR_STASYNC | SR_POLLMODE");
  107 #else
  108   if ( sr_setparm(SRL_DEVICE, SR_MODEID, &mode) == -1 )
  109   {
  110     LOGCRIT("Unable to set mode ID to SR_POLLMODE.");
  111     return false;
  112   }
  113   LOGDEBUG("SRL Model Set to SR_STASYNC | SR_POLLMODE");
  114 #endif
  115 
  116   return true;
  117 }
  118 
  119 
  120 void DialogicManager::shutdown()
  121 {
  122 //$$AM  closeAllDevices();
  123 
  124   LOGDEBUG("DialogicManager::shutdown() Stopping Global Call");
  125   gc_Stop();
  126 }
  127 
  128 /*
  129  * Auto detect devices
  130  */
  131 bool DialogicManager::getDevices()
  132 {
  133   /* Determine number of physical boards by passing 0
  134    * Physical Board count and NULL Auid device info.
  135    * Function will fail but number of Physical Boards will be returned
  136    */
  137 
  138   int physicalBoards = 0;
  139   long rc = SRLGetAllPhysicalBoards(&physicalBoards, NULL);
  140   if ( rc != ESR_INSUFBUF )
  141   {
  142     /* If error other than ESR_INSUFBUF then either no virtual boards
  143      * or other unexpected error
  144      */
  145     LOGERROR("DialogicManager::getBoards() SRLGetAllPhysicalBoards() failed, error = 0x" << std::hex << rc);
  146     return false;
  147   }
  148 
  149   // Allocate memory for array of AUIDs
  150   AUID* auids = new AUID[physicalBoards];
  151 
  152   // Retrieve physical board info
  153   rc = SRLGetAllPhysicalBoards(&physicalBoards, auids);
  154   if ( rc != ESR_NOERR )
  155   {
  156     LOGERROR("DialogicManager::getBoards() SRLGetAllPhysicalBoards failed, error = 0x" << std::hex << rc);
  157     delete[] auids;
  158     return false;
  159   }
  160 
  161   /* -----------------------------------------------------------------
  162    * For each Physical Board AUID, determine associated virtual board
  163    */
  164   for ( int indxPhys = 0; indxPhys < physicalBoards; indxPhys++ )
  165   {
  166     // Set the AUID pointer to the current item
  167     AUID *auid = &auids[indxPhys];
  168 
  169     /* Determine number of virtual boards by passing 0
  170      * Virtual Boardcount and NULL SRL device info.
  171      * Function will fail but number of virtual boards will be returned
  172      */
  173     int nVirtualBoards = 0;
  174     SRLDEVICEINFO *srlBoards = NULL; // SRL Device Info for virtual board
  175     rc = SRLGetVirtualBoardsOnPhysicalBoard(*auid, &nVirtualBoards, srlBoards);
  176     if ( rc != ESR_INSUFBUF )
  177     {
  178       /* If error other than ESR_INSUFBUF then either no virtual boards
  179        * or other unexpected error
  180        */
  181       LOGERROR("SRLGetVirtualBoardsOnPhysicalBoard() failed, error = 0x" << std::hex << rc);
  182       delete[] auids;
  183       return false;
  184     }
  185 
  186     // Allocate memory for number of virtual boards found
  187     srlBoards= new SRLDEVICEINFO[nVirtualBoards];
  188 
  189     // Now retrieve all virtual boards on physical board
  190     rc = SRLGetVirtualBoardsOnPhysicalBoard(*auid, &nVirtualBoards, srlBoards);
  191     if ( rc != ESR_NOERR )
  192     {
  193       LOGERROR("DialogicManager::getBoards() SRLGetVirtualBoardsOnPhysicalBoard() failed, error = 0x" << std::hex << rc);
  194       delete[] srlBoards;
  195       delete[] auids;
  196       return false;
  197     }
  198     /* -------------------------------------------------------------
  199      * For each virtual board, determine associated virtual channels
  200      */
  201     for ( int indxBoard = 0; indxBoard < nVirtualBoards; indxBoard++ )
  202     {
  203       // Set the Board pointer to the current item
  204       SRLDEVICEINFO *srlBoard = &srlBoards[indxBoard];
  205 
  206       int nVirtualChans = 0;
  207       /* Determine number of virtual channels by passing 0
  208        * Virtual Channel count and NULL SRL device info.
  209        * Function will fail but number of virtual channels will
  210        * be returned.
  211        */
  212       rc = SRLGetSubDevicesOnVirtualBoard(srlBoard->szDevName, &nVirtualChans, NULL);
  213       if ( rc != ESR_INSUFBUF )
  214       {
  215         /* If error other than ESR_INSUFBUF then either no virtual
  216          * channels or other unexpected error.
  217          */
  218         LOGERROR("DialogicManager::getBoards() SRLGetSubDevicesOnVirtualBoard() failed, error = 0x" << std::hex << rc);
  219         delete[] srlBoards;
  220         delete[] auids;
  221         return false;
  222       }
  223 
  224       // Allocate memory for number of virtual channels found
  225       SRLDEVICEINFO* srlChannels = new SRLDEVICEINFO[nVirtualChans];
  226 
  227       // Now retrieve all virtual channels on physical board
  228       rc = SRLGetSubDevicesOnVirtualBoard(srlBoard->szDevName, &nVirtualChans, srlChannels);
  229       if ( rc != ESR_NOERR )
  230       {
  231         LOGERROR( "DialogicManager::getBoards() SRLGetSubDevicesOnVirtualBoard() failed, error = 0x" << std::hex << rc);
  232         delete[] srlChannels;
  233         delete[] srlBoards;
  234         delete[] auids;
  235         return false;
  236       }
  237 
  238       /* ---------------------------------------------------------
  239        * For each virtual channel, display associated AUID,
  240        * virtual board and device type.
  241        */
  242       for ( int indxChan = 0; indxChan < nVirtualChans; indxChan++ )
  243       {
  244         // Set the Channel pointer to the current item
  245         SRLDEVICEINFO *srlChannel = &srlChannels[indxChan];
  246 
  247         std::string devType = "unknown";
  248         switch ( srlChannel->iDevType )
  249         {
  250           case TYPE_R4_VOX_CHANNEL:      // 502 E.g., dxxxB1C1
  251             voxBoards_.push_back (srlChannel);
  252             devType = "R4_VOX_CHANNEL";
  253             voxChannels_++;
  254             break;
  255 
  256           case TYPE_R4_DTI_TIMESLOT:     // 504 E.g., dxxxB1T1
  257             dtiBoards_.push_back (srlChannel);
  258             devType = "R4_DTI_TIMESLOT";
  259             dtiChannels_++;
  260             break;
  261 
  262           case TYPE_R4_IPM_CHANNEL:      // 528 E.g., ipmB1C1
  263             devType = "R4_IPM_CHANNEL";
  264             ipmBoards_.push_back (srlChannel);
  265             ipmChannels_++;
  266             break;
  267 
  268           default:
  269             break;
  270         }
  271 
  272         /* Display AUID, virtual board, virtual channel and device type.
  273          * Device type values found in devmapr4.h
  274          */
  275         LOGINFO("DialogicManager::getBoards() " << *auid
  276           << "\t" << srlBoard->szDevName
  277           << "\t" << srlChannel->szDevName
  278           << "\t" << srlChannel->iDevType
  279           << " (" << devType << ")");
  280       } // end virtual channel loop
  281 
  282       delete[] srlChannels;
  283     } // end virtual board loop
  284 
  285     LOGINFO("DialogicManager::getBoards() Physical Board No:" << indxPhys << " has "
  286       << voxBoards_.size () << " Vox channels, "
  287       << dtiBoards_.size () << " DTI channels, "
  288       << ipmBoards_.size () << " IPM channels.");
  289     delete[] srlBoards;
  290   } // end physical board loop
  291 
  292   delete[] auids;
  293   return true;
  294 }
  295 
  296 
  297 /*
  298  * vim:ts=4:set nu:
  299  */

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