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

📄 ha.c

📁 telcobridges pri develop,30b+d
💻 C
📖 第 1 页 / 共 5 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VoiceLink TB640 sample (ISDN)
 |
 |	Filename:   	ha.c
 |
 |	Copyright:  	TelcoBridges 2002-2003, All Rights Reserved
 |
 |	Description:	This file contains the function necessary to recover from an application failure
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.23 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Includes
 *------------------------------------------------------------------------------------------------------------------------------*/

/* System includes */
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>

/* Local includes */
#include "tbx_ostypes.h"
#include "tbx_id.h"
#include "tbx_result.h"
#include "tbx_msg.h"
#include "tbx_std.h"
#include "tbx_api.h"
#include "tbx_featmgr.h"
#include "tb640_id.h"
#include "tb640_handle.h"
#include "tb640_adpmgr.h"
#include "tb640_trkmgr.h"
#include "tb640_isdnmgr.h"
#include "tb640_connmgr.h"
#include "tb640_pmalarmmgr.h"
#include "tb640_ctbusmgr.h"
#include "tbx_os_wrapper.h"

#include "tbx_hash.h"
#include "tbx_pool_of_buffers.h"
#include "tbx_timer.h"
#include "tbxasync.h"
#include "tbx_cli.h"
#include "isdn.h"
#include "prototypes.h"
#include "macros.h"


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Forward declarations
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Defines
 *------------------------------------------------------------------------------------------------------------------------------*/


/* Nb time to try for an attach */
#define TB640_ISDN_RESYNC_NB_ATTACH_ATTEMPT							5

/* Max time in msec to wait for a response to a ATTACH synchronous request */
#define TB640_ISDN_RESYNC_ATTACH_REQUEST_TIMEOUT_MSEC				5000

/* Max time in msec to wait for a response to a synchronous request */
#define TB640_ISDN_RESYNC_SYNCHRONOUS_REQUEST_TIMEOUT_MSEC			15000

/* Max time in msec to wait for a response to a asynchronous request */
#define TB640_ISDN_RESYNC_ASYNCHRONOUS_REQUEST_TIMEOUT_MSEC			15000




/*--------------------------------------------------------------------------------------------------------------------------------
 |  Types
 *------------------------------------------------------------------------------------------------------------------------------*/

/* This enumeration represent the different types of action to be done by a callback function */
typedef enum _TB640_ISDN_QUERY_TYPE
{
	TB640_ISDN_QUERY_TYPE_LIST,
	TB640_ISDN_QUERY_TYPE_PARAMS,
	TB640_ISDN_QUERY_TYPE_STATES

} TB640_ISDN_QUERY_TYPE, *PTB640_ISDN_QUERY_TYPE;


typedef TBX_RESULT (* PFCT_TB640_ISDN_QUERY_SETUP)(
  IN		PTBX_VOID 						in_pvAppContext,
  IN		TBX_UINT32						in_un32UserContext,
  IN		TB640_ISDN_QUERY_TYPE			in_QueryType,
  IN		TBX_UINT32						in_hEntity,
  OUT		PTBX_MSG_HANDLE					out_phMsg);


typedef TBX_RESULT (* PFCT_TB640_ISDN_RETRIEVED_INFO) (
  IN		PTBX_VOID 					in_pvAppContext,
  IN		TBX_UINT32					in_un32UserContext,
  IN		TBX_UINT32					in_hEntity,
  IN		PTBX_VOID					in_pMsgGetParams,
  IN		PTBX_VOID					in_pMsgGetState);



/*--------------------------------------------------------------------------------------------------------------------------------
 |  Versioning
 *------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
	/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.23 $";
#endif


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Macros
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Function Prototypes
 *------------------------------------------------------------------------------------------------------------------------------*/

TBX_RESULT TB640IsdnAdapterResyncTrunk (
  IN		PTBX_VOID 					in_pvAppContext);

TBX_RESULT TB640IsdnAdapterResyncCtbusRes (
  IN		PTBX_VOID 					in_pvAppContext);

TBX_RESULT TB640IsdnAdapterResyncStack (
  IN		PTBX_VOID 					in_pvAppContext);

TBX_RESULT TB640IsdnAdapterResyncConnection (
  IN		PTBX_VOID 					in_pvAppContext);

TBX_RESULT TB640IsdnAdapterUpdateCallContextStates (
  IN		PTBX_VOID 					in_pvAppContext);

TBX_RESULT TB640IsdnAdapterQueryInfo (
  IN		PTBX_VOID 						in_pvAppContext,
  IN		TBX_UINT32						in_un32UserContext,
  IN		PFCT_TB640_ISDN_QUERY_SETUP		in_pFctQuery,
  IN		PFCT_TB640_ISDN_RETRIEVED_INFO	in_pFctRetrieved);


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Implementation
 *------------------------------------------------------------------------------------------------------------------------------*/


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640IsdnAsyncLibAdapterRemovedHandler:	This function is called by the operation library when it detects that an adapter has been
 |											removed (or is no longer usable).
 |
 |  in_pvAppContext	:	User-defined context
 |
 |  Note			:	This function only needs to return OK
 |
 |  Return          :	No return value
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640IsdnAsyncLibAdapterRemovedHandler (
  IN		PTBX_VOID 					in_pvAppContext)
{
	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print error message */
		TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}

	RETURN;
}



/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640IsdnAdapterRemovedHandler:	This function is called by the operation library when it detects that an adapter has been
 |									removed (or is no longer usable).
 |
 |  in_pvAppContext	:	User-defined context
 |	in_fForceClean	:	Force a clean
 |
 |  Note			:	~
 |
 |  Return          :	No return value
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640IsdnAdapterRemovedHandler (
  IN		PTBX_VOID 					in_pvAppContext,
  IN		TBX_BOOL					in_fForceClean)
{
	TBX_BOOL							fPerformCleanup;
	TBX_UINT32							un32AdapterIdx;
	TBX_UINT32							un32OpLibIdx;
	TBX_UINT32							un32Count1;
	TBX_UINT32							un32Count2;
	TBX_UINT32							un32NbCtbus;
	TBX_UINT32							un32CtbusIdx;
	PTB640_ISDN_ADAPTER_INFO			pAdapterInfo;
	PTB640_ISDN_TRUNK_INFO				pTrunkInfo;
	PTB640_ISDN_TRUNK_RESOURCE_INFO		pTrunkResInfo;
	PTB640_ISDN_CTBUS_INFO				pCtbusInfo;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		fPerformCleanup = TBX_FALSE;
		un32NbCtbus = 0;

		/* Retrieve the adapter index and operation lib index */
		TB640_ISDN_RETRIEVE_APP_CONTEXT (in_pvAppContext, un32AdapterIdx, un32OpLibIdx);
		pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapterIdx]);

		/* Stop all stress-testing */


		if (!in_fForceClean)
		{
			/* Lock the adapter state semaphore */
			TBX_SEM_GET(pAdapterInfo->AdapterSem, TBX_SEM_WAIT_FOREVER);

			/*
			 * Check if the adapter is already tagged as "detached".  This is necessary since we will receive one event
			 * per operation lib.
			 */
			if (pAdapterInfo->fAttached != TBX_FALSE)
			{
				/* Indicate the removal */
				pAdapterInfo->fAttached = TBX_FALSE;
				TB640_ISDN_LOG (TRACE_LEVEL_3, "Adapter %s removal detected.  Standby procedures engaged...\n", pAdapterInfo->szAdapterName);
				g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
			}

			/* Check if we are the last operation lib to flag the removal */
			pAdapterInfo->un32NbSyncReceived++;
			if (pAdapterInfo->un32NbSyncReceived == pAdapterInfo->un32NbOperationLib)
			{
				fPerformCleanup = TBX_TRUE;
				pAdapterInfo->un32NbSyncReceived = 0;
			}

			/* Unlock the adapter state semaphore */
			TBX_SEM_GIV(pAdapterInfo->AdapterSem);
		}

		/* Clean the operation library */
		TBXAsyncClean (pAdapterInfo->ahOperationLib [un32OpLibIdx]);

		/* Either wait for clean-up or do the clean-up depending if we are the last operation lib to have received the detach event */
		if (fPerformCleanup == TBX_FALSE && !in_fForceClean)
		{
			TB640IsdnUnlockFromOpLibIdx( pAdapterInfo, un32OpLibIdx );
			TBX_SEM_GET(pAdapterInfo->AttachOrDetachOpDoneSem, TBX_SEM_WAIT_FOREVER);
			TB640IsdnLockFromOpLibIdx( pAdapterInfo, un32OpLibIdx );
		}
		else
		{
			/* Adapter is not sync'ed anymore */
			pAdapterInfo->fSynced = TBX_FALSE;

			/* Clear the transiant call stats */
			TBX_SEM_GET(pAdapterInfo->TransientCallsSem, TBX_SEM_WAIT_FOREVER);
			pAdapterInfo->un32TransientCalls = 0;
			TBX_SEM_GIV(pAdapterInfo->TransientCallsSem);

			/* Clear the trunk and trunk resource handles */
			for (un32Count1=0; un32Count1<TB640_ISDN_MAX_SUPPORTED_TRUNKS_PER_ADAPTER; un32Count1++)
			{
				pTrunkInfo = &(pAdapterInfo->aTrunkInfo [un32Count1]);
				if (pTrunkInfo->TrunkConfiguration.Type != (TB640_TRUNK_TYPE)NULL)
				{
					/* Reset the member variable for a trunk */
					pTrunkInfo->un8Trunk = (TBX_UINT8)un32Count1;
					pTrunkInfo->hTrunk = (TB640_TRUNK_HANDLE)NULL;
					pTrunkInfo->fActivated = TBX_FALSE;
					pTrunkInfo->un32OpLibIdx = (un32Count1 / TB640_ISDN_MAX_TRUNK_PER_OPERATION_LIBRARY);
					pTrunkInfo->un32NbTrunkResource = 0;

#if 0
					/* Reset the flag that tells the trunk is included in stress-testing */
					pTrunkInfo->fIncludedInStressTesting = TBX_FALSE;
#endif

					/* Reset all trunk resources */
					for (un32Count2=0; un32Count2<TB640_ISDN_MAX_TIMESLOT_IN_TRUNK; un32Count2++)
					{
						pTrunkResInfo = &(pTrunkInfo->aResourceInfo [un32Count2]);

						/* Reset the member variable for a trunk resource */
						pTrunkResInfo->un8Trunk = (TBX_UINT8)un32Count1;
						pTrunkResInfo->un8Timeslot = (TBX_UINT8)un32Count2;
						pTrunkResInfo->hTrunkResource = (TB640_TRUNK_HANDLE)NULL;
						pTrunkResInfo->hCall = (TB640_CALL_HANDLE)NULL;
						pTrunkResInfo->hConnection = (TB640_CONNECTION_HANDLE)NULL;
						memset (&(pTrunkResInfo->Statistics), 0, sizeof(pTrunkResInfo->Statistics));
						pTrunkResInfo->Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_NOT_USED;
						pTrunkResInfo->un32HistoryReadIdx = 0;
						pTrunkResInfo->un32HistoryWriteIdx = 0;

⌨️ 快捷键说明

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