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

📄 config.c

📁 telcobridges pri develop,30b+d
💻 C
📖 第 1 页 / 共 5 页
字号:

			/***************************************************************/
			/* At this point, we start sync'ing process for this adapter   */
			/***************************************************************/

			/* Yield the CPU to make sure all async lib processes to get into their receive thread */
			TBX_SLEEP_MS (50);

			/* Let's start the standby process by simulating 'adapter removed' events */
			for (un32Count2=0; un32Count2<(((pAdapterInfo->un32NbTrunk-1)/TB640_ISDN_MAX_TRUNK_PER_OPERATION_LIBRARY)+1); un32Count2++)
			{
				/* Format the fake "adapter removed" event that will toggle the standby procedure */
				result = TBXGetMsg (g_AppContext->hTbxLib, sizeof(*pEvtAdapterRemoved), &hMsg);
				if (TBX_RESULT_FAILURE (result))
				{
					TBX_EXIT_ERROR(result, 0, "Unable to allocate a message buffer");
				}

				/* Format the message header */
				TBX_FORMAT_MSG_HEADER (						\
				  hMsg,										\
				  TBX_MSG_ID_API_NOTIF_ADAPTER_REMOVED,		\
				  TBX_MSG_TYPE_EVENT,						\
				  sizeof(*pEvtAdapterRemoved),				\
				  pAdapterInfo->hAdapter,					\
				  0,										\
				  0);

				/* Format the message payload */
				pEvtAdapterRemoved = (PTBX_EVT_API_NOTIF_ADAPTER_REMOVED)TBX_MSG_PAYLOAD_POINTER (hMsg);
				pEvtAdapterRemoved->hAdapter = pAdapterInfo->hAdapter;

				/* Simulate an 'adapter removed' */
				result = TBXAsyncInsertManualMsg (pAdapterInfo->ahOperationLib [un32Count2], &hMsg);
				if (TBX_RESULT_FAILURE (result))
				{
					TBX_EXIT_ERROR(result, 0, "Unable to manually insert an event into the async lib");
				}
			}

			/* Yield the CPU to make sure all async lib processes got the fake 'remove' event */
			TBX_SLEEP_MS (50);

			/***************************************************************/
			/* At this point, this adapter should be in standby mode...	   */
			/***************************************************************/

			/* Let's start the resync process by simulating 'adapter added' events */
			for (un32Count2=0; un32Count2<(((pAdapterInfo->un32NbTrunk-1)/TB640_ISDN_MAX_TRUNK_PER_OPERATION_LIBRARY)+1); un32Count2++)
			{
				/* Format the fake "adapter removed" event that will toggle the standby procedure */
				result = TBXGetMsg (g_AppContext->hTbxLib, sizeof(*pEvtAdapterAdded), &hMsg);
				if (TBX_RESULT_FAILURE (result))
				{
					TBX_EXIT_ERROR(result, 0, "Unable to allocate a message buffer");
				}

				/* Format the message header */
				TBX_FORMAT_MSG_HEADER (						\
				  hMsg,										\
				  TBX_MSG_ID_API_NOTIF_ADAPTER_ADDED,		\
				  TBX_MSG_TYPE_EVENT,						\
				  sizeof(*pEvtAdapterAdded),				\
				  pAdapterInfo->hAdapter,					\
				  0,										\
				  0);

				/* Format the message payload */
				pEvtAdapterAdded = (PTBX_EVT_API_NOTIF_ADAPTER_ADDED)TBX_MSG_PAYLOAD_POINTER (hMsg);
				pEvtAdapterAdded->Info.hAdapter = pAdapterInfo->hAdapter;

				/* Simulate an 'adapter removed' */
				result = TBXAsyncInsertManualMsg (pAdapterInfo->ahOperationLib [un32Count2], &hMsg);
				if (TBX_RESULT_FAILURE (result))
				{
					TBX_EXIT_ERROR(result, 0, "Unable to manually insert an event into the async lib");
				}
			}

			/* Wait until the adapter is re-sync'ed */
			while (pAdapterInfo->fSynced == TBX_FALSE)
			{
				TBX_SLEEP_MS (10);
			}

			/***************************************************************/
			/* At this point, this adapter should be in resync'ed mode... */
			/***************************************************************/
		}

		/* 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
	{
		if (hMsg != NULL)
		{
			TBXReleaseMsg (g_AppContext->hTbxLib, hMsg);
			hMsg = NULL;
		}
	}

	RETURN;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640IsdnCleanSystem:	This function desallocates and free the trunks, stacks, CTBus resources and operation librairies
 |							that were (maybe partially) opened by TB640IsdnConfigureSystem().
 |
 |  ~		        :	No arguments used
 |
 |  Note			:	~
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640IsdnCleanSystem (void)
{
	TBX_RESULT							result;
	TBX_UINT32							un32Count;
	TBX_UINT32							un32Count2;
	TBX_UINT32							un32TransientCalls;
	PTB640_ISDN_ADAPTER_INFO			pAdapterInfo;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		un32TransientCalls = 0;

		/* Check if the TBX library was opened */
		if (g_AppContext->hTbxLib == (TBX_LIB_HANDLE)NULL)
		{
			/* Nothing to do (library hasn't been opened */
			TBX_EXIT_SUCCESS (TBX_RESULT_OK);
		}

		TB640_ISDN_LOG (TRACE_LEVEL_4, "Stopping receive threads...\n");

		/* Close the operation libraries (this will stop all the RX processing threads) */
		for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
		{
			pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Count]);
			for (un32Count2=0; un32Count2<TB640_ISDN_NB_OPERATION_LIBRARY_REQUIRED; un32Count2++)
			{
				if (pAdapterInfo->ahOperationLib [un32Count2] != (TBX_ASYNC_LIB_HANDLE)NULL)
				{
					/* Close the library */
					result = TBXAsyncClose (pAdapterInfo->ahOperationLib [un32Count2]);
					if (TBX_RESULT_FAILURE (result))
					{
						TBX_EXIT_ERROR(result, 0, "Unable to close operation library");
					}
					pAdapterInfo->ahOperationLib [un32Count2] = NULL;
				}
			}

			/* Destroy the transiant calls semaphore */
			if( pAdapterInfo->TransientCallsSem )
			{
				TBX_SEM_DESTROY (&(pAdapterInfo->TransientCallsSem));
			}
			un32TransientCalls += pAdapterInfo->un32TransientCalls;

			/* Destroy the adapter removal synchronization semaphore */
			if( pAdapterInfo->AttachOrDetachOpDoneSem )
			{
				TBX_SEM_DESTROY (&(pAdapterInfo->AttachOrDetachOpDoneSem));
			}

			/* Destroy the adapter states semaphore */
			if( pAdapterInfo->AdapterSem )
			{
				TBX_SEM_DESTROY (&(pAdapterInfo->AdapterSem));
			}
		}

		/* Check if there was any calls not in a 'stable' state */
		if (un32TransientCalls > 0)
		{
			TB640_ISDN_LOG (TRACE_LEVEL_4, "%d calls were still transient when you exited the application.\n", un32TransientCalls);
			TB640_ISDN_LOG (TRACE_LEVEL_4, "This could results in resource leak(s)\n");
		}

		/* Free stacks */
		TB640IsdnFreeStacks ();

		/* Destroy connections */
		TB640IsdnDestroyConnections ();

		/* Free trunk resources */
		TB640IsdnFreeTrunkResources ();

		/* Put trunks in maintenance mode */
		TB640IsdnMaintenanceTrunks ();

		/* Free trunks */
		TB640IsdnFreeTrunks ();

		/* Free CTbus resource on each adapters */
		TB640IsdnFreeCtBusResources ();

		/* Destroy the op context semaphores */
		for (un32Count=0; un32Count<g_AppContext->un32NbAdapter; un32Count++)
		{
			pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Count]);
			for (un32Count2=0; un32Count2<TB640_ISDN_NB_OPERATION_LIBRARY_REQUIRED; un32Count2++)
			{
				if( pAdapterInfo->Lock.aOperationLibSem[un32Count2] != (TBX_SEM)TBX_HANDLE_INVALID )
				{
					TBX_SEM_DESTROY (&(pAdapterInfo->Lock.aOperationLibSem[un32Count2]));
				}
			}
		}

		/* Closed opened adapters */
		TB640IsdnCloseAdapters ();

		/* Print TBX lib statistics */
		TBXLibStats (g_AppContext->hTbxLib);

		/* Close the TBX library */
		TBXCloseLib (g_AppContext->hTbxLib);
		g_AppContext->hTbxLib = (TBX_LIB_HANDLE)TBX_HANDLE_INVALID;

		/* Close the NULL file descriptor */
		if( g_AppContext->pFileStdErr )
		{
			fclose (g_AppContext->pFileStdErr);
			g_AppContext->pFileStdErr = NULL;
		}

		/* Destroy stress-test statistics semaphore */
		TBX_SEM_DESTROY (&g_StressStatsSem);

		/* 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;
}


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Utility functions
 *------------------------------------------------------------------------------------------------------------------------------*/
static void
TB640IsdnGetAdapterIpAddresses(
    IN		PTBX_ADAPTER_INFO	in_pAdapterInfo,
	OUT		TBX_CHAR			out_szIpAddresses[ 256 ]
)
{
	out_szIpAddresses [0] = '\0';
	if( in_pAdapterInfo->szIpAddress0[0] != 0 && in_pAdapterInfo->szIpAddress1[0] != '\0' )
	{
		sprintf
		(
			out_szIpAddresses,
			"%s, %s, redundant ethernet",
			in_pAdapterInfo->szIpAddress0,
			in_pAdapterInfo->szIpAddress1
		);
	}
	else if( in_pAdapterInfo->szIpAddress0[0] != 0 )
	{
		sprintf
		(
			out_szIpAddresses,
			"%s",
			in_pAdapterInfo->szIpAddress0
		);
	}
	else if( in_pAdapterInfo->szIpAddress1[0] != 0 )
	{
		sprintf
		(
			out_szIpAddresses,
			"%s",
			in_pAdapterInfo->szIpAddress1
		);
	}

	return;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640IsdnCheckAdapterFeatures:
 |

⌨️ 快捷键说明

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