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

📄 sessioncontainer.cpp

📁 Windows CE .Net 下面 VOIP编程的经典实例。对于初学Windows 平台下VOIP编程技术的程序员颇具借鉴意义!
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//

/*************************************************************************


  Disclaimer:

    This code and information is provided "as is" without warranty of
    any kind, either expressed or implied, including but not limited to
    the implied warranties of merchantability and/or fitness for a
    particular purpose.

Module Name:

	SessionContainer.cpp

Abstract:
	
	CSessonContainer (IRTCSession to CSession map and storage object) function declarations.

Notes:
	
	The session container is an abstraction allowing us to use any implementation of a map as we see fit.
 	It is used to provide a global storage for the session objects and allow for easy access of the CSession
 	class with use of a IRTCSession pointer (critical for the event handling).  Hopefully this will make the 
 	code cleaner for support of multiple IM sessions, etc..

 	This class provides a central location for storing CSession objects, used here as
 	HANDLEs.  A chained hash table is used for quick lookup, with size presently limited
 	to SESSION_CONTAINER_HASH_SIZE (17) which should be large enough and sufficiently prime
 	 to ensure that each session will get it's own unique bucket (keeping the search speed near O(1)).

 	Important: Presently a remove from the container will call delete on any CSession* 
 		stored inside the container.  Modify later?

**************************************************************************/

#include "SessionContainer.h"
#include "Session.h"

/************************************************************************************************

  CSessionContainer::CSessionContainer()

	  default ctor

 ************************************************************************************************/

CSessionContainer::CSessionContainer()
{		
}


/************************************************************************************************
 
   CSessionContainer::~CSessionContainer()
 
 	Cleanup the container by calling Clear(). (will hangup any open sessions)
 
 *************************************************************************************************/

CSessionContainer::~CSessionContainer()
{
	// shutdown msg called by destructor of the session
	Clear();
}

/************************************************************************************************ 

  Add()
 
	Interface into the CHashTable. return the same session on success and NULL on failure.

 *************************************************************************************************/


HANDLE 
CSessionContainer::Add( 
					   IN HANDLE pSess,
					   IN CSession* pCSession
					   )
{	
	if (m_ht.Add(pSess, pCSession))
		return pSess;
	else
		return NULL;
}

/************************************************************************************************
 
   CSessionContainer::Access()
 
 	Get at the pointer for the CSession object, allows for easier debugging.
 
 	NOTE: Since a pointer is returned, explicitly ASSERT to check for non-existence errors.

 ************************************************************************************************/

CSession* CSessionContainer::Access( 
									IN HANDLE hKey
									) 
{
	CSession* pRetVal = NULL;
	pRetVal = m_ht.Access(hKey);
	ASSERT( pRetVal != NULL );
	
	return pRetVal;
}


/************************************************************************************************

  CSessionContainer::Exist()
 
 	Check for the existence of hKey in the hash table
 
 ************************************************************************************************/

BOOL
CSessionContainer::Exist( 
						 IN HANDLE hKey
						 ) 
{
	return m_ht.Exist( hKey );	
}

/************************************************************************************************
 
   CSessionContainer::Remove()
 	
 	Remove the Session from the container and call it's destructor, removes
 	both the node and the session itself.
 
 ************************************************************************************************/

void 
CSessionContainer::Remove(
						  IN HANDLE hKey						  
						  )
{	
	m_ht.Remove( hKey );
}

/************************************************************************************************
 
   CSessionContainer::Clear()
 
 	Remove all sessions from the container, explicitly call their destructors.
 
 ************************************************************************************************/

void 
CSessionContainer::Clear() 
{
	m_ht.Clear();
}

⌨️ 快捷键说明

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