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

📄 main.cpp

📁 Conferencing code using Dialogic hardware
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/**********@@@SOFT@@@WARE@@@COPY@@@RIGHT@@@**********************************
* DIALOGIC CONFIDENTIAL
*
* Copyright (C) 2006-2007 Dialogic Corporation. All Rights Reserved.
* The source code contained or described herein and all documents related
* to the source code ("Material") are owned by Dialogic Corporation or its
* suppliers or licensors. Title to the Material remains with Dialogic Corporation
* or its suppliers and licensors. The Material contains trade secrets and
* proprietary and confidential information of Dialogic or its suppliers and
* licensors. The Material is protected by worldwide copyright and trade secret
* laws and treaty provisions. No part of the Material may be used, copied,
* reproduced, modified, published, uploaded, posted, transmitted, distributed,
* or disclosed in any way without Dialogic's prior express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be
* express and approved by Dialogic in writing.
*
***********************************@@@SOFT@@@WARE@@@COPY@@@RIGHT@@@**********/
//***********************************************************************
//***********************************************************************

//////////////////////////////////////////////////////////////////////
// main.cpp: implementation of the application business logics.
//
//////////////////////////////////////////////////////////////////////

#include <signal.h>

#include "pdl.h"

// Global objects
//------------------
CGenLog     * glb_pAppLog = 0;       // Application log

CDetectCfg  * glb_pDetectCfg = 0;    // Detect configuration

ConferencePool *glb_pConferencePool; // Container for all conference boards
                                     // Used to search conference by pass code

// This module static data
//--------------------------
static CnfDemoPrm  * m_pAppParams;   // Cnf Demo parameters
static CSrlThread  * m_pSrlThread;   // Represent thread and
                                     // is container for all devices & containers served by this thread 

static bool prompt_done;             // the prompt is already shown

static const char *CNF_MODULE_NAME = "MAIN";        // for logging purposes
static const int appMaxLogLines = 7200;             // defaults for logging
static const char *cfgFile = "conf_demo.cfg";

static NAME_TABLE exit_tbl_stru[] = {
    { "Normal exit",    EXIT_OK    },
    { "Config file error",   EXIT_CFG   },
    { "Resources ( service started? licenses? Other APP running(HMP)? )",  EXIT_INIT  },
    { "Log file error",   EXIT_LOG   },
    { "Open/init devices", EXIT_START },
    { "Validate ( state machine error? )",  EXIT_VALIDATE  },
    { "Failure",  EXIT_FAIL  },
    { 0, 0 }
};
static CNameTable exit_tbl(exit_tbl_stru);



// Forward Declaration
//----------------------
static void intr_handler(int exit_code);


// Global functions
//----------------------
//*****************************************************************************
// Purpose	: 
//    Request to exit
// Parameters:	
//    flag (true if it is internal request)
//          false if request is coming from OS
// Returns:	
//    none
//*****************************************************************************
static volatile bool exit_request = false; // indicates request to exit was sent
static volatile bool exit_now = false;     // indicates request for immediate exit
static volatile bool exiting = false;      // indicates exit in progress
static bool fatal_error = false;
void glb_exit_request(bool is_internal, bool is_fatal){
  if (is_fatal){
      fatal_error = true;
  }
  if (!exiting){
      if(exit_request){
         // Second attempt, exit now!
         if (!is_internal){
             GLBLOG(LOG_APP, CNF_MODULE_NAME, "Immediate exit requested");
             exit_now = true;
         }
      }else {
         // Gracefull exit
         GLBLOG(LOG_APP, CNF_MODULE_NAME, "Exit requested please wait...");
         if (m_pSrlThread) {
             m_pSrlThread->SignalExitRequest();
         }
      }
      exit_request = true;
  }else {
      GLBLOG(LOG_APP, CNF_MODULE_NAME, "Exiting ...");
  }
 return;
} //	End of glb_exit_request()


// Local functions
//----------------------
//*****************************************************************************
// Purpose	: 
//    set intr_handlers function to serve OS exit request ( kill / ctrl-C / etc.)
// Parameters:	
//    none
// Returns:	
//    none
//*****************************************************************************
static void set_intr_handler(){
#  ifdef WIN32
	signal(SIGBREAK, intr_handler);
#   else // LINUX
    signal(SIGQUIT,  intr_handler);
# endif // LINUX

	signal(SIGINT,   intr_handler);
	signal(SIGTERM,  intr_handler);
	signal(SIGILL,   intr_handler);
	signal(SIGFPE,   intr_handler);
	signal(SIGABRT,  intr_handler);
 return;
} //	End of set_intr_handler()

//*****************************************************************************
// Purpose	: 
//    handle exit request from OS - set flag for APP to exit
// Parameters:	
//    exit_code(we don't care about it's value ) - it comes from OS
// Returns:	
//    none
//*****************************************************************************
static void intr_handler(int exit_code){

  GLBLOG(LOG_APP, CNF_MODULE_NAME, "Signal (code=%d)",exit_code);

  // 
  glb_exit_request(false,false);
  
  // re-set exit handlers for customers that have lost their patience
  set_intr_handler();
    
  return;
}  //	End of intr_handler()



//*****************************************************************************
// Purpose	: 
//    display how many licenses needs current configuration
// Parameters:	
//    none
// Returns:	
//    none
//*****************************************************************************
static void display_license_info(){
   if (m_pAppParams){
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "To run current confuguration, you need at least following licenses:");
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "  Voice           = %d", m_pAppParams->GetRequestedNumberOfDxDevices());
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "  RTP             = %d", m_pAppParams->GetRequestedNumberOfIptDevices());
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "  IP Call Control = %d", m_pAppParams->GetRequestedNumberOfIptDevices());
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "  Conferencing    = %d", m_pAppParams->GetRequestedNumberOfConferences());
   }
 return;
}

//*****************************************************************************
// Purpose	: 
//    release resources and exit (assumes all state machines in NULL state)
// Parameters:	
//    return code (to OS).
//      0 indicates OK
//      1 indicates failure
// Returns:	
//    never returns
//*****************************************************************************
static void do_exit(EXIT_CODE ret_code) {
 exiting = true;

   if (EXIT_INIT == ret_code ){
       display_license_info();
   }

   delete glb_pConferencePool;

   // Delete global objects
   delete m_pSrlThread;

   // gc_Stop
   gc_stop_wrapper();
   
   // Delete global objects
   delete glb_pDetectCfg; 

   delete m_pAppParams;   

   // Provide exit reasons
   glb_pAppLog->Dump();

   const char *ret_name = exit_tbl.find_name(ret_code);

   GLBLOG(LOG_ALL, CNF_MODULE_NAME, "Exiting with code %d '%s'", ret_code, ret_name);

   // Keep console alive: print message and wait a stroke 
   con_wait_a_key(ret_code, "Cleanup complete.");

   delete glb_pAppLog;

   // Done
   printf ("\n*** End cnf Demo***\n");
   exit(ret_code); 
}  //	End of do_exit()


//*****************************************************************************
// Purpose	: 
//    Display message shown bellow
// Parameters:	
//    none
// Returns:	
//    int
//*****************************************************************************
static void LogPrompt(){
 if (!prompt_done) {
   if (!exit_request) {
       prompt_done = true;
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "***********************************");
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "*                                 *");
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "*       Ready to answer calls     *");
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "*                                 *");
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "* Name=%-27s*",glb_pDetectCfg->GetHostName() );
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "* Addr=%-27s*",glb_pDetectCfg->GetHostAddr() );
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "*                                 *");
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "* operational mode: %-14s*",get_call_control_mode_name(m_pAppParams->GetPCCMode()));
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "* using %3d ipt SIP  devices      *",m_pAppParams->GetRequestedNumberOfIptDevices("SIP"));
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "* using %3d ipt H323 devices      *",m_pAppParams->GetRequestedNumberOfIptDevices("H323"));
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "* using %3d dti devices           *",m_pAppParams->GetRequestedNumberOfDtiDevices());
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "*                                 *");
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "* using %3d conferences           *",glb_pConferencePool->GetNumberOfConferences());
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "*                                 *");
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "*                                 *");
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "*       Press <Ctrl-C> to exit    *");
       GLBLOG(LOG_ALL, CNF_MODULE_NAME, "***********************************");
   } // !exit requste
 } // ! prompt_done
}  //	End of LogPrompt()

⌨️ 快捷键说明

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