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

📄 voip_state.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 4 页
字号:
									/* Start demo */
									VoipDemoStart( pAdapterContext, pEvt );
								}
								else if( TBX_MSG_ID_GET( hMsg ) == VOIP_MSG_ID_OP_STOP_DEMO )
								{
									TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Stop demo...\n" );

									/* Stop demo */
									VoipDemoStop( pAdapterContext );
								}
								else if( TBX_MSG_ID_GET( hMsg ) == VOIP_MSG_ID_OP_NEXT_DEMO_STEP )
								{
									TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Next demo step...\n" );

									/* Update current step value */
									pAdapterContext->Demo.un32CurrentStep += 1;

									/* Next demo step */
									VoipDemoNextStep( pAdapterContext );
								}
								else
								{
									/* Trigger the current state machine's handler function for this adapter */
									if( pAdapterContext->pFctStateHandler )
									{
										pAdapterContext->pFctStateHandler( pAdapterContext, hMsg );
									}
								}
							}
							else
							{
								if
								(
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_ADAPTER_ADDED )		||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_ADAPTER_REMOVED )		||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_ADAPTER_ETH_UP )		||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_ADAPTER_ETH_DOWN )		||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_REMOTE_HOST_ADDED )	||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_REMOTE_HOST_REMOVED )	||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_REMOTE_HOST_ETH_UP )	||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_REMOTE_HOST_ETH_DOWN ) ||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_STREAM_SERVER_MSG )
								)
								{
									/* It is normal that we receive these events for other adapters... but we ignore them */
								}
								else
								{
									/* This message does not belong to any of our state machines. */
									TbxCliToolsLogPrint(
										pCliContext->hCliTools,
										TRACE_LEVEL_ERROR,
										NULL,
										"VoipStateMachineMain: Message (0x%X) from unknown adapter/host 0x%08X\n",
										(int)TBX_MSG_ID_GET( hMsg ),
										(int)TBX_MSG_ADAPTER_HANDLE_GET( hMsg ) );
								}
							}
						}
/*
						else
						{
							if
							(
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_ADAPTER_ADDED )		||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_ADAPTER_REMOVED )		||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_ADAPTER_ETH_UP )		||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_ADAPTER_ETH_DOWN )		||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_REMOTE_HOST_ADDED )	||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_REMOTE_HOST_REMOVED )	||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_REMOTE_HOST_ETH_UP )	||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_API_NOTIF_REMOTE_HOST_ETH_DOWN ) ||
								( TBX_MSG_ID_GET( hMsg ) == TBX_MSG_ID_STREAM_SERVER_MSG )
							)
							{
*/								/* It is normal that we receive these events for other adapters... but we ignore them */
/*							}
							else
							{
*/								/* This message does not belong to any of our state machines. */
/*								TbxCliToolsLogPrint(
									pCliContext->hCliTools,
									TRACE_LEVEL_ERROR,
									NULL,
									"VoipStateMachineMain: Message (0x%X) from unknown adapter/host 0x%08X\n",
									(int)TBX_MSG_ID_GET( hMsg ),
									(int)TBX_MSG_ADAPTER_HANDLE_GET( hMsg ) );
							}
						}
*/
					}
				}
			}

			if( hMsg != (TBX_MSG_HANDLE)TBX_HANDLE_INVALID )
			{

				TBXReleaseMsg (g_pContext->hTbxLib, hMsg);
			}

			if( !g_fContinue )
			{
				if( fQuitSequenceEntered )
				{
					/* Test if it's legal to quit this application right now... */
					VoipStateTestQuit();
				}
				else
				{
					/* Initiate quit sequence */
					VoipEnterQuitSequence();
					fQuitSequenceEntered = TBX_TRUE;
				}
			}
		}

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

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		/* Print the error to the user */
		TbxCliToolsLogPrint(
			pCliContext->hCliTools,
			TRACE_LEVEL_ERROR,
			NULL,
			"VoipStateMachineMain: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
		/* Release the thread semaphore */
		TBX_SEM_GIV (g_pContext->hThreadSem);
	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStateTestQuit	:	Test if it's legal to stop the state machine right now...
 |
 |  ~					:	No parameters
 |
 |  Note				:	~
 |
 |  Return				:	TBX_RESULT_OK if the function succeeded
 |							Other error code if the function could not complete properly.
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
static TBX_VOID VoipStateTestQuit( TBX_VOID )
{
	PVOIP_CLI_CONTEXT			pCliContext		= &g_pContext->CliContext;
	PVOIP_ADAPTER_CONTEXT		pAdapterContext;
	PVOIP_ADAPTER_CONTEXT_NODE	pAdapterContextNode;
	TBX_UINT32					un32NbEnabled	= 0;
	TBX_UINT32					un32NbTotal		= 0;
	TBX_BOOL					fCanQuit		= TBX_TRUE;

	if( fCanQuit )
	{
		/* Validate that all adapters are now disconnected */
		pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );
		while( pAdapterContextNode )
		{
			pAdapterContext = pAdapterContextNode->pAdapterContext;

			un32NbTotal++;
			if( pAdapterContext->State != VOIP_ADAPTER_STATE_NOT_USED )
			{
				un32NbEnabled++;
			}

			pAdapterContextNode = TBXPoolOfBuffersNext( g_pContext->hPoolOfAdapters, pAdapterContextNode );
		}

		if( un32NbEnabled )
		{
			fCanQuit = TBX_FALSE;
			if( g_QuitLastPrintTime != time( NULL ) )
			{
				g_QuitLastPrintTime = time( NULL );
				TbxCliToolsLogPrint(
					pCliContext->hCliTools,
					TRACE_LEVEL_ALWAYS,
					NULL,
					"Waiting for all adapters to be disabled (%d/%d still disabling)...\n",
					(int)un32NbEnabled,
					(int)un32NbTotal );
			}
		}
	}

	if( fCanQuit )
	{
		/* We can finally quit!!! Stop the state machine */
		g_fRunStateMachine = TBX_FALSE;
	}

	return;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipHandleHostAdded					:	Handle a new remote host application discovered
 |										
 |  in_hMsg								:	Host added message received
 |										
 |  Note								:	~
 |										
 |  Return								:	TBX_RESULT_OK if the function succeeded
 |											Other error code if the function could not complete properly.
 |								
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT	VoipHandleHostAdded
(
	IN		TBX_MSG_HANDLE					in_hMsg
)
{
	TBX_RESULT_API								Result;
	PTBX_EVT_API_NOTIF_REMOTE_HOST_ADDED		pHostAddedMsg;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		pHostAddedMsg			= TBX_MSG_PAYLOAD_POINTER( in_hMsg );

		if( g_pContext->TestModeContext.fTestMode == TBX_TRUE )
		{
			/* verify if the new host added is a test controller */
			if ( pHostAddedMsg->Info.un64UserContext1 == TB_TESTCONTROLLER_USER_CONTEXT )
			{
				TbxCliToolsLogPrint( 
					g_pContext->CliContext.hCliTools, 
					TRACE_LEVEL_0, 
					FWHITE,
					"adapter handle: 0x%X.", pHostAddedMsg->Info.hRemoteHost );

				/* check if confirmation launch has been sent */
				if( g_pContext->TestModeContext.fLaunchConfirmSend == TBX_FALSE )
				{
					g_pContext->TestModeContext.fLaunchConfirmSend = TBX_TRUE;
					/* initialize the host test controller handle */
					g_pContext->TestModeContext.hHostHandle = pHostAddedMsg->Info.hRemoteHost;

					/* send confirmation to test controller that we have started in test mode */
					Result = TBTestLibSendConfirmLaunchMessage
					( 
						g_pContext->hTbxLib,
						pHostAddedMsg->Info.hRemoteHost,
						0,
						g_pContext->TestModeContext.un32TestId,
						TBX_RESULT_AUTOTEST_OK,
						g_pContext->TestModeContext.szLogFileName
					);
					if( TBX_RESULT_FAILURE( Result ) )
					{
						TBX_EXIT_ERROR ( Result, 0, "Launch request failed." );
					}
					else
					{
						TbxCliToolsLogPrint( 
							g_pContext->CliContext.hCliTools, 
							TRACE_LEVEL_ALWAYS, 
							FGREEN,
							"Launch request success.\n");
					}
				}
			}
		}
		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
		TbxCliToolsLogPrint( 
			g_pContext->CliContext.hCliTools, 
			TRACE_LEVEL_ERROR, 
			FRED,
			"VoipHandleHostAdded: %s: 0x%X\n", TBX_ERROR_DESCRIPTION, Result );
	}

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

	RETURN;
}

⌨️ 快捷键说明

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