| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- #include "StdAfx.h"
- #include "TrunkAidedAllocator.h"
- #include "AidedUnit.h"
- #include "Config.h"
- #include "OneLeg.h"
- SINGLETON_IMPLEMENT(CTrunkAidedAllocator)
- CTrunkAidedAllocator::CTrunkAidedAllocator(void)
- {
- }
- CTrunkAidedAllocator::~CTrunkAidedAllocator(void)
- {
- __free();
- }
- /*****************************************************************
- **【函数名称】 __free
- **【函数功能】 释放资源
- **【参数】
- **【返回值】
- ****************************************************************/
- void CTrunkAidedAllocator::__free( void )
- {
- for(int i = 0; i < m_UnitList.GetCount(); ++i)
- {
- delete m_UnitList[i];
- }
- m_UnitList.RemoveAll();
- }
- /*****************************************************************
- **【函数名称】 __getAidedUnit
- **【函数功能】 获取辅助单元
- **【参数】
- **【返回值】
- ****************************************************************/
- CAidedUnit* CTrunkAidedAllocator::__getAidedUnit( LPCTSTR Prefix, bool NewWhenNULL/* = false*/ )
- {
- for(int i = 0; i < m_UnitList.GetCount(); ++i)
- {
- if(m_UnitList[i]->prefix() == Prefix)
- return m_UnitList[i];
- }
- if(NewWhenNULL)
- {
- CAidedUnit* pNewUnit = new CAidedUnit(Prefix);
- m_UnitList.Add(pNewUnit);
- return pNewUnit;
- }
- return NULL;
- }
- /*****************************************************************
- **【函数名称】 init
- **【函数功能】 初始化
- **【参数】
- **【返回值】
- ****************************************************************/
- void CTrunkAidedAllocator::init( void )
- {
- CCfgTrunkMatch& Match = CConfig::trunkMatch();
- POSITION Pos = Match.GetHeadPosition();
- while(Pos != NULL)
- {
- TRUNK_MATCH* pMatch = Match.GetNext(Pos);
- ASSERT(pMatch != NULL);
- CAidedUnit* pUnit = __getAidedUnit(pMatch->Prefix, true);
- ASSERT(pUnit != NULL);
- pUnit->add(pMatch);
- }
- }
- /*****************************************************************
- **【函数名称】 aidedAlloc
- **【函数功能】 辅助分配通道
- **【参数】
- **【返回值】
- ****************************************************************/
- COneLeg* CTrunkAidedAllocator::aidedAlloc( CString& CallerNum, CString& CalleeNum, TRUNK_ITEM** pTrunkItem )
- {
- CAidedUnit* pUnit = NULL;
- for(int i = 0; i < m_UnitList.GetCount(); ++i)
- {
- pUnit = m_UnitList[i];
- if(pUnit->match(CalleeNum))
- return pUnit->aidedAlloc(CallerNum, CalleeNum, pTrunkItem);
- }
- return NULL;
- }
- /*****************************************************************
- **【函数名称】 aidedAllocByDefault
- **【函数功能】 辅助分配通道若失败则用缺省中继项
- **【参数】
- **【返回值】
- ****************************************************************/
- COneLeg* CTrunkAidedAllocator::aidedAllocWithDefault( CString& CallerNum, CString& CalleeNum, TRUNK_ITEM** pTrunkItem )
- {
- CAidedUnit* pUnit = NULL;
- // 匹配出局字冠
- for(int i = 0; i < m_UnitList.GetCount(); ++i)
- {
- pUnit = m_UnitList[i];
- if(pUnit->match(CalleeNum))
- break;
- }
- // 未匹配到,则进行无匹配分配
- COneLeg* pCallLeg = NULL;
- for(int i = 0; i < m_UnitList.GetCount(); ++i)
- {
- pCallLeg = m_UnitList[i]->aidedAlloc(CallerNum, pTrunkItem);
- if(pCallLeg != NULL)
- break;
- }
- return pCallLeg;
- }
|