⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 Conferencing code using Dialogic hardware
💻 CPP
📖 第 1 页 / 共 2 页
字号:

//*****************************************************************************
// Purpose	: 
//    wait all available SRL devices to reach init state
//         exit in case pf error
// Parameters:	number of seconds to wait
//    none
// Returns:	
//    none
//*****************************************************************************
static void wait_srl(int tmo){
           
 PSrlDevice pDev;
   // Wait engine to open all conferences and conference boards
   if ( !m_pSrlThread->WaitSrlState(tmo*1000, SRLSTATE_INIT_COMPLETE, true, &pDev ) ) {
          GLBLOG( LOG_ERR2, CNF_MODULE_NAME,
                 "(%s) Failed to reach SRLSTATE_INIT_COMPLETE in %d sec",
                  pDev->GetName(), tmo);
                 do_exit(EXIT_START);
   }  
 return;
}

//*****************************************************************************
// Purpose	: 
//    Creata all conferences and wait initialisation
// Parameters:	
//    none
// Returns:	
//    int
//*****************************************************************************
static bool CreateConferences(PCommonParams pCommonParams) {

  // * --- Create conference objects
  CnfBoard    * pCnfBoard;
  PBrdParams pBrdParams = m_pAppParams->GetBrdPrm();
  PCnfPrmContainer pCnfPrmContainer = m_pAppParams->GetConferencePrmContainer();
  pCnfBoard = new CnfBoard(pCommonParams, pBrdParams, pCnfPrmContainer);
  if (!pCnfBoard->IsSrlState(SRLSTATE_RESERVED, true) ) {
      // Missing conference virtual board
      delete pCnfBoard;
      do_exit(EXIT_INIT);
  } 

  // Attach board
  m_pSrlThread->push_back(pCnfBoard);

  // Wait initialization, 5 seconds per conference
  // int sec = APP_TMO_SHORT * m_pAppParams->GetNumberOfConferences();
  int sec = 10; // 10 sec total
  wait_srl(sec);

 return true;
}
//*****************************************************************************
// Purpose	: 
//    Create all dti boards and wait initialization
// Parameters:	
//    none
// Returns:	
//    int
//*****************************************************************************
static bool CreateDtiDevices(PCommonParams pCommonParams) {

   //----- Create Ip objects, number of devices is Ok -----
   PDtiParams pDtiParams = m_pAppParams->GetDtiPrm() ;
   if(pDtiParams) {
        unsigned int inx_dev;
        for( inx_dev = 0; inx_dev < pDtiParams->m_number_of_channels; inx_dev++){
             PPstnDevice pDevice;
             pDevice = new CPstnDevice(pCommonParams, pDtiParams);
             EXIT_CODE e_code = pDevice->GetExitCode();
             if (EXIT_OK == e_code) {
                  m_pSrlThread->push_back(pDevice);
             }else {
                  delete pDevice; 
                  do_exit(e_code);
                  break;
             } 
        } // for inx_dev 

     // Wait initialization, 5 sec per IPT device
//    int sec = APP_TMO_SHORT * m_pAppParams->cp_NumIptDevices;
      int sec = 10; // 10 sec total
      wait_srl(sec);
   }// if PDtiParams
 return true;
}

//*****************************************************************************
// Purpose	: 
//    Create all dti boards and wait initialization
// Parameters:	
//    none
// Returns:	
//    int
//*****************************************************************************
static bool CreateIpDevices(PCommonParams pCommonParams) {

   //----- Create Ip objects, number of devices is Ok -----
   unsigned int inx_ipt = 0;
   PIptParams pIptParams;
   while(m_pAppParams->GetIptPrm(inx_ipt, &pIptParams)){
        unsigned int inx_dev;
        for( inx_dev = 0; inx_dev < pIptParams->m_number_of_channels; inx_dev++){
             PIptDevice pDevice;
             pDevice = new CIptDevice(pCommonParams, pIptParams);
             EXIT_CODE e_code = pDevice->GetExitCode();
             if (EXIT_OK == e_code) {
                  m_pSrlThread->push_back(pDevice);
             }else {
                  delete pDevice; 
                  do_exit(e_code);
                  break;
             } 
        } // for inx_dev: 0 to m_nunber_of_channels
        inx_ipt++;
   }// while = next group of devices

   // Wait initialization, 5 sec per IPT device
   // int sec = APP_TMO_SHORT * m_pAppParams->cp_NumIptDevices;
   int sec = 10; // 10 sec total
   wait_srl(sec);
 return true;
}

//*****************************************************************************
// Purpose	: 
//    start the app
// Parameters:	
//    none
// Returns:	
//    int
//*****************************************************************************
int main() {
EXIT_CODE ret_code = EXIT_OK;

   // setup exit handlers
   set_intr_handler();

   // Temporarily, Log to console
   glb_pAppLog = new ConsoleLog;
   
   GLBLOG(LOG_ALL, CNF_MODULE_NAME, "%s", BINARY_VERSION_STRING);

   // Read configuration file
   m_pAppParams = new CnfDemoPrm(glb_pAppLog);
   PCommonParams pCommonParams = m_pAppParams->GetCommonPrm();

   if (! m_pAppParams->ReadConfigFile(cfgFile)  || exit_request) {
         do_exit(EXIT_CFG);
   }

   // Set verbosity level

   glb_pAppLog->SetVerbosity(pCommonParams->m_log_level);

   { 
     // --- Create log file ---
       CFileLog *pFileLog = new CFileLog();
       if (! pFileLog->InitLog(pCommonParams->m_log_file, pCommonParams->m_maxlogsize) ){
             GLBLOG( LOG_ERR2, CNF_MODULE_NAME,
                     "Error creating log object(%s,%d)",
                     pCommonParams->m_log_file, pCommonParams->m_maxlogsize );
             do_exit(EXIT_LOG);
       }
       pFileLog->SetVerbosity(pCommonParams->m_log_level);

       //
       // Swap logs:
       //  pAppLog => ConsoleLog
       pFileLog->DefineChainLog(glb_pAppLog);
       glb_pAppLog = pFileLog;

       // -- Dump actual parameters 
       m_pAppParams->Dump();
   } // Block


   // -- Start GC
   if ( !gc_start_wrapper(m_pAppParams) ){
       // if gc is not started, IPT devices will not be detected
       do_exit(EXIT_INIT);
   }

   { //----- Detect & Dump configuration -----
       glb_pDetectCfg = new CDetectCfg(m_pAppParams);
       glb_pDetectCfg->DetectConfiguration(); 
       glb_pDetectCfg->DumpSize();       
   } // block (detect)

   { // Create SRL object and Devices
     //=================================
       m_pSrlThread = new CSrlThread(pCommonParams);
       if (! m_pSrlThread->InitMode(SRL_TMO, SRL_POLLED_MODE)) {
             GLBLOG( LOG_ERR2, CNF_MODULE_NAME,
                    "Error initializing SrlThread object(%d,%d)",
                    SRL_TMO, SRL_POLLED_MODE  );
             do_exit(EXIT_INIT);
       }


       if (! m_pAppParams->AdjustNumberOfDevices(glb_pDetectCfg->GetNumberOf(DEV_DX),
                                                 glb_pDetectCfg->GetNumberOf(DEV_IPT),
                                                 glb_pDetectCfg->GetNumberOf(DEV_DTI))){
            do_exit(EXIT_CFG);
       }

       // Container for all conference boards
       // Ised for searching for a conference by given pass code
       glb_pConferencePool = new ConferencePool(); 
              
       if (!exit_request) {
            CreateConferences(pCommonParams); 
       }

       if (!exit_request) {
            CreateDtiDevices(pCommonParams);
       }

       // exit request may change 
       if ( !exit_request) {
            CreateIpDevices(pCommonParams);
       }

   } // Block Create SRL Object & devices

   LogPrompt();

   //---- The main loop until:
   // 1. At least one device is still opened
   // or 2. exit-now flag is set ( but does will exit gracefully in this case)
   while ( m_pSrlThread->AnySrlState(SRLSTATE_OPENED, true, 0) ){
           if (exit_now) {
               break;
           } 
           m_pSrlThread->TheThreadBody();
           if (!m_pSrlThread->AnySrlState(SRLSTATE_CALL_ACTIVE, true, 0)) {
               LogPrompt();
           }else {
               prompt_done = false;
           }
            
   }
   if (fatal_error){
       ret_code = EXIT_FAIL;
   }else {
       if ( m_pSrlThread->AnySrlState(SRLSTATE_FAILED_FATAL, true, 0) ){
            ret_code = EXIT_FAIL;
       }
   }
   
   do_exit(ret_code);

 // fake, 
 // some compilers will complain about missing return here
 // other compilers require main() to return int
 return(0);
}   //	End of main()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -