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

📄 ntwkdevice.cpp

📁 Conferencing code using Dialogic hardware
💻 CPP
📖 第 1 页 / 共 4 页
字号:
}  // End of Destructor()

// =====================================================
//  DX Functions
// =====================================================

//*****************************************************************************
// Purpose	: 
//    Close device
// Parameters:	
//    none
// Returns:	
//    true = success
//    false = failure
//*****************************************************************************
bool CNtwkDevice::Close(){
 bool brc = true;
 int rc;
    if( IsSrlState(SRLSTATE_OPENED, true) ){
        if ( IsSrlState(SRLSTATE_WAITEVENT, true) ){
             LOG( LOG_WARNING, GetName(),
                  "gc_Close() while waiting for event, state = %d %s",
                  GetCurrentState(), state_name(GetCurrentState()) );
                  DumpMissingEvents();
        }

        rc = gc_Close(m_srl_handle);
        LOG( RC(rc), GetName(),
             "%d = gc_Close(0x%x)",
             rc, m_srl_handle);

        brc = (rc == 0);
        if (!brc){
            process_gc_error();
        } else {
             m_srl_handle = INV_SRL_HANDLE;
        }
        
        close_dx();
	
        SetCurrentState(S_FINAL);
        SetSrlState(SRLSTATE_ALL, RESET_SRL_STATE);        
    }
 return brc;
}  // End of Close()

//*****************************************************************************
// Purpose	: 
//    process latest event info (cause)
// Parameters:	
//    metaevent
// Returns:	
//    bool - false indicates error while processing
//*****************************************************************************
bool CNtwkDevice::ProcessEventInfo(METAEVENT *metaeventp){
  int rc = gc_ResultInfo(metaeventp, &m_gc_info);
  LOG( RC(rc), GetName(),
       "%d = gc_ResultInfo(metaeventp, pInfo)", rc);
  gc_dump(&m_gc_info);

 return rc == GC_SUCCESS;
} // End of ProcessEventInfo()

// =====================================================
//  NTWK Functions
// =====================================================
//*****************************************************************************
// Purpose	: 
//    Reset line device and drop and release calls 
//          ( recover after blocking event)
// Parameters:	
//    none
// Returns:	
//    bool (true = success)
//*****************************************************************************
bool CNtwkDevice::ResetLineDev(){

  int rc = gc_ResetLineDev(m_srl_handle,EV_ASYNC);
      LOG( RCFATAL(rc), GetName(),
           "%d = gc_ResetLineDev(0x%x, EV_ASYNC)",
           rc, m_srl_handle);
      if (rc != GC_SUCCESS){
          SetSrlState ( SRLSTATE_FAILED_FATAL );
          process_gc_error();
          return false;
      }
      // next time, redo wait-call
      m_do_waitcall = true;
  return true;
} // End of ResetLineDev()

//*****************************************************************************
// Purpose	: 
//    Answer to incoming call
// Parameters:	
//    none
// Returns:	
//    bool (true = success)
//*****************************************************************************
bool CNtwkDevice::AnswerCall(){
int rc = GC_SUCCESS;

  rc = gc_AnswerCall(m_crn,1, EV_ASYNC);
  LOG( RC(rc), GetName(),
       "%d = gc_AnswerCall(crn = 0x%x, rings = 1, EV_ASYNC)",
       rc, m_crn);

  if ( rc != GC_SUCCESS){
       process_gc_error();
       return false;
  }  
  return true;
} // End of AnswerCall()

//*****************************************************************************
// Purpose	: 
//    Accept to incoming call
// Parameters:	
//    none
// Returns:	
//    bool (true = success)
//*****************************************************************************
bool CNtwkDevice::AcceptCall(){
  if (DoAcceptCall() ) {
	  int rc;
      rc = gc_AcceptCall(m_crn, 0, EV_ASYNC);
      LOG( RC(rc), GetName(),
             "%d = gc_AcceptCall(crn = 0x%x, rings = 0, EV_ASYNC)",
             rc, m_crn);
	  
      if ( rc != GC_SUCCESS){
           process_gc_error();
           return false;
	  }

  }else {
      PutEvent(USREV_SKIP_ACCEPT, GetName());
  }
  return true;
} // End of AcceptCall()

//*****************************************************************************
// Purpose	: 
//    Drop current call
// Parameters:	
//    none
// Returns:	
//    bool (true = success)
//*****************************************************************************
bool CNtwkDevice::DropCall(){
  int rc = gc_DropCall(m_crn, NORMAL_CLEARING, EV_ASYNC);
      LOG( RCFATAL(rc), GetName(),
           "%d = gc_DropCall(0x%x, cause = 0x%x (NORMAL_CLEARING), EV_ASYNC)",
           rc, m_crn, NORMAL_CLEARING);

      if ( rc != GC_SUCCESS){
           process_gc_error();
           SetSrlState ( SRLSTATE_FAILED_FATAL );
           return false;
      }
  return true;
} // End of DropCall()

//*****************************************************************************
// Purpose	: 
//    Release current call
// Parameters:	
//    none
// Returns:	
//    bool (true = success)
//*****************************************************************************
bool CNtwkDevice::ReleaseCall(){
  int rc = gc_ReleaseCallEx(m_crn, EV_ASYNC);
      LOG( RCFATAL(rc), GetName(),
           "%d = gc_ReleaseCallEx(0x%x, EV_ASYNC)",
            rc, m_crn);

      if ( rc != GC_SUCCESS){
           process_gc_error();
           SetSrlState ( SRLSTATE_FAILED_FATAL );
           return false;
      }
  return true;
}  // End of ReleaseCall()

//*****************************************************************************
// Purpose	: 
//    Watch for incoming calls
//      this function should be executed once at the beginning
//           and after each ResetLineDev
// Parameters:	
//    none
// Returns:	
//    bool (true = success)
//*****************************************************************************
bool CNtwkDevice::WaitCall(){

  InitForNewCall();

  if ( IsSrlState( SRLSTATE_REQUESTED_STOP,true) ){
       LOG(LOG_API, GetName(), "***Exit requested, leave WaitCall");
       SetCurrentState(S_FINAL);
       Close();
       return true;
  }

  if ( IsSrlState(SRLSTATE_BLOCKED | SRLSTATE_REQUESTED_STOP,true) ){
       LOG(LOG_API, GetName(), "***WaitCall in Blocked state: resume to S_UNBLOCKED");
       // indicate BLOCKED and go back to wait unblocked      
       return true;
  }

  if (m_do_waitcall) {
	  // do waitcall only after ResetLineDev and very first time
      int rc = gc_WaitCall(m_srl_handle, 0, 0, 0, EV_ASYNC);
          LOG( RCFATAL(rc), GetName(),
               "%d = gc_WaitCall(hndl=0x%x, crn:=0x%x, blk=0, tmo=0,  EV_ASYNC)",
               rc, m_srl_handle,m_crn);

          if ( rc != GC_SUCCESS){
               process_gc_error();
               SetSrlState ( SRLSTATE_FAILED_FATAL );
               return false;                             
          }
          m_do_waitcall = false;
      return true;
  }else {
      LOG( LOG_API, GetName(),
           "gc_WaitCall() - skipped");
  }
  return true;
}  // End of WaitCall()

//*****************************************************************************
// Purpose	: 
//    Initialize for next call
//      Call OnNewCall() - derived class hook  
// Parameters:	
//    none
// Returns:	
//    true = success
//*****************************************************************************
bool CNtwkDevice::InitForNewCall(){
     CloseVoiceFile();
     m_num_inv_passcode = 0;
     ClearDigits();
     m_crn = 0;
     *m_ani=0;
     *m_dnis=0;
     m_pCnfConf = 0;
     SetCnfBoard(0);

     if ( !   IsSrlState(SRLSTATE_REQUESTED_STOP, true)
         && ( S_FINAL != GetCurrentState()  ) ) {
         OnNewCall();  // Allow derived classes to initialize for next call
     }
  return true;
} // End of InitForNewCall()

//-----------------------------------------------------------------------
//     C O N F E R E N C E
//-----------------------------------------------------------------------
//*****************************************************************************
// Purpose	: 
//    Find conference party and join conference
// Parameters:	
//    none
// Returns:	
//    true = success
//*****************************************************************************
bool CNtwkDevice::AddParty(){
    CNF_ASSERT(m_pCnfConf, "Missing m_pCnfConf object");

    bool brc = m_pCnfConf->AddParty(m_cnf_party_srl_handle,this);

    LOG(LOG_DBG, GetName(), "%s = AddParty(0x%x)",brc?"true":"false", m_cnf_party_srl_handle);

 return brc;
}  // End of AddParty()

//*****************************************************************************
// Purpose	: 
//    Remove party from conference
// Parameters:	
//    none
// Returns:	
//    true = success
//*****************************************************************************
bool CNtwkDevice::RemoveParty(){
  CNF_ASSERT(m_pCnfConf, "Missing m_pCnfConf object");

  bool brc = m_pCnfConf->RemoveParty(m_cnf_party_srl_handle, this);
  LOG(LOG_DBG, GetName(), "%s = RemoveParty(0x%x)",brc?"true":"false", m_cnf_party_srl_handle);
 return brc;
}  // End of RemoveParty()


//*****************************************************************************
// Purpose	: 
//    The party is in conference, wait until disconnected
// Parameters:	
//    none
// Returns:	
//    true
//*****************************************************************************
bool CNtwkDevice::Relax(){
    LOG( LOG_APP,GetName(),
         "Party joined conference %s (id %d)",
         m_pCnfConf->GetName(), m_pCnfConf->GetId() );
 return true;
}  // End of Relax()


//*****************************************************************************
// Purpose	: 
//    Check if received digits match a conference
// Parameters:	
//    none
// Returns:	
//    true if no failure
//    EVENT: USREV_CHECK_PASS   if conference is found
//           USREV_CHECK_RETRY  if conference is not found, retry
//           USREV_CHECK_FAIL   if conference is not found, drop the call
//*****************************************************************************
bool CNtwkDevice::CheckForValidConference()  {
  PCnfConference pCnf;
  bool brc = true;
  if ( !glb_pConferencePool->FindConferenceByPassCode(m_digits.dg_value, &pCnf) ){
        if ( m_num_inv_passcode++ < MAX_RETRY) {
             LOG(LOG_DBG, GetName(), "Retry %d, cant match pass_code %s",
                 m_num_inv_passcode,m_digits.dg_value);
             brc = PutEvent(USREV_CHECK_RETRY, GetName());
        }else {
             LOG(LOG_DBG, GetName(), "Failed (attempt %d), cant match pass_code %s",m_num_inv_passcode,m_digits.dg_value);
             brc = PutEvent(USREV_CHECK_FAIL, GetName());
        }
  }else {
      brc = PutEvent(USREV_CHECK_PASS, GetName());
      m_pCnfConf = pCnf;
      SetCnfBoard(pCnf->GetCnfBoard());
  }
  return brc;
}  // End of CheckForValidConference()


//*****************************************************************************
// Purpose	: 
//    Check if received ANI matches a conference
//      any should match "C<pass_code>@..."
// Parameters:	
//    none
// Returns:	
//    true if no failure
//    EVENT: USREV_CHECK_PASS   if conference is found
//           USREV_CHECK_FAIL   if conference is not found, play the prompt
//*****************************************************************************
bool CNtwkDevice::CheckDnis()  {
  PCnfConference pCnf;
  bool brc = true;
  if ( tolower(*m_dnis) == 'c') {
       char my_dnis[GC_ADDRSIZE];
       str_safecopy(my_dnis,sizeof(my_dnis),m_dnis+1);
       char *ch = strchr(my_dnis,'@');
       if (ch) *ch = 0;
       if ( glb_pConferencePool->FindConferenceByPassCode(my_dnis, &pCnf) ){
            LOG( LOG_APP, GetName(),
                 "CheckDnis()::Matched to conference %s pass_code %s",
                 pCnf->GetName(), my_dnis);
            brc = PutEvent(USREV_CHECK_PASS, GetName());
            m_pCnfConf = pCnf;
            SetCnfBoard(pCnf->GetCnfBoard());
          return brc;
       }
  }
  LOG( LOG_API, GetName(),
       "CheckDnis():: Not matched to conference: %s",
       m_dnis);
  brc = PutEvent(USREV_CHECK_FAIL, GetName());
 return brc;
}  // End of CheckForValidConference()

⌨️ 快捷键说明

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