MCUInformation.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:2k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // MCUInformation.cpp: implementation of the CMCUInformation class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "MCUInformation.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CMCUInformation::CMCUInformation()
- {
- ::InitializeCriticalSection( & this->session );
- }
- CMCUInformation::~CMCUInformation()
- {
- ::DeleteCriticalSection( &this->session );
- }
- void CMCUInformation::Release( void )
- {
- int size = 0;
- while( ! this->mcu_map.empty( ) )
- {
- CMCUNode * node = ( CMCUNode * )this->mcu_map.begin( )->second;
- size = this->mcu_map.size( );
- node->cmdTCP->Close( );
- while( size == this->mcu_map.size( ) ) ::Sleep( 100 );
- }
- }
- CMCUNode * CMCUInformation::AddMCUNode( CTCP * cmdTCP , const char * mcu_name )
- {
- this->LockMap( );
- for( INT_PTR_MAP::iterator itr = this->mcu_map.begin( ); itr != this->mcu_map.end( ); itr ++ )
- {
- CMCUNode * node = ( CMCUNode * )itr->second;
- if( node->mcu_name == mcu_name )
- {
- this->UnlockMap( );
- return NULL;
- }
- }
- CMCUNode * node = new CMCUNode( );
- node->cmdTCP = cmdTCP;
- node->mcu_name = mcu_name;
- node->mcu_id = ( int )cmdTCP;
- this->mcu_map[ node->mcu_id ] = node;
- this->UnlockMap( );
- return node;
- }
- void CMCUInformation::RemoveMCUNode( int mcu_id )
- {
- this->LockMap( );
- INT_PTR_MAP::iterator itr = this->mcu_map.find( mcu_id );
- if( itr!= this->mcu_map.end( ) )
- {
- CMCUNode * node = ( CMCUNode * )itr->second;
- this->mcu_map.erase( itr );
- node->cmdTCP->Close( );
- ::Sleep( 1000 );
- delete node->cmdTCP;
- delete node;
- }
- this->UnlockMap( );
- }
- CMCUNode * CMCUInformation::GetMCUNode( int mcu_id )
- {
- this->LockMap( );
- INT_PTR_MAP::iterator itr = this->mcu_map.find( mcu_id );
- if( itr == this->mcu_map.end( ) )
- {
- this->UnlockMap( );
- return NULL;
- }
- this->UnlockMap( );
- return ( CMCUNode * )itr->second;
- }
- INT_PTR_MAP * CMCUInformation::LockMap( void )
- {
- ::EnterCriticalSection( &this->session );
- return &this->mcu_map;
- }
- void CMCUInformation::UnlockMap( void )
- {
- ::LeaveCriticalSection( &this->session );
- }