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

📄 voip_cli_cmd.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
			}

		} break;

		case 2:	/* Validate Rx IP port */
		{
			if( !VoipCliIsValidNumericValue( pszUserInput ) )
			{
				/* Restore a valid value */
				sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.SelectStream.un16RxIPPort );
				return TBX_FALSE;
			}

		} break;

		case 3:	/* Validate Tx IP port */
		{
			if( !VoipCliIsValidNumericValue( pszUserInput ) )
			{
				/* Restore a valid value */
				sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.SelectStream.un16TxIPPort );
				return TBX_FALSE;
			}

		} break;

		case 4:	/* Validate reset stats indication */
		{
			if( !VoipCliIsValidBoolValue( pszUserInput ) )
			{
				/* Restore a valid value */
				sprintf( pszUserInput, "%s", (g_DefaultPrompts.SelectStream.fResetStats == TBX_TRUE) ? "YES":"NO" );
				return TBX_FALSE;
			}

		} break;
	}

	return TBX_TRUE;
}

TBX_VOID VoipCliCmdSelectStreamApply(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	TBX_BOOL	fGlobalStats;
	TBX_BOOL	fResetStats;

	fGlobalStats = VoipCliStringToBool( io_pCmdContext->paszUserInput[ 0 ].szLine );
	fResetStats = VoipCliStringToBool( io_pCmdContext->paszUserInput[ 4 ].szLine );

	/* Save new default prompt values */
	g_DefaultPrompts.SelectStream.fGlobalStats = fGlobalStats;
	g_DefaultPrompts.SelectStream.un32InterfaceIndex =
		(TBX_UINT32)strtoul( io_pCmdContext->paszUserInput[ 1 ].szLine, NULL, 0 );
	g_DefaultPrompts.SelectStream.un16RxIPPort =
		(TBX_UINT16)strtoul( io_pCmdContext->paszUserInput[ 2 ].szLine, NULL, 0 );
	g_DefaultPrompts.SelectStream.un16TxIPPort =
		(TBX_UINT16)strtoul( io_pCmdContext->paszUserInput[ 3 ].szLine, NULL, 0 );
	g_DefaultPrompts.SelectStream.fResetStats = fResetStats;

	/* Apply stream resource selection */
	VoipCliCmdSelectStreamApplyInternal();

	/* No more input to take. Return to main menu input. */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_NONE;
}

TBX_VOID VoipCliCmdSelectStreamApplyInternal()
{
	PVOIP_CLI_CONTEXT			pCliContext = &g_pContext->CliContext;
	TB640_STREAM_INTERFACE_TYPE	Interface;

	if( g_DefaultPrompts.SelectStream.un32InterfaceIndex == 0 )
	{
		Interface = TB640_STREAM_INTERFACE_TYPE_BASE;
	}
	else
	{
		Interface = TB640_STREAM_INTERFACE_TYPE_VOIP;
	}

	if( pCliContext->pActiveAdapterContext->AdapterInfo.hAdapter )
	{
		/* Poll stream resource statistics if adapter is connected */
		VoipCliSendPollStreamResStats( pCliContext, g_DefaultPrompts.SelectStream.fGlobalStats, Interface,
			g_DefaultPrompts.SelectStream.un16RxIPPort,
			g_DefaultPrompts.SelectStream.un16TxIPPort,
			g_DefaultPrompts.SelectStream.fResetStats );
	}
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipCliCmdResetBertStatsApply	:	Apply the command
 |
 |  io_pCmdContext					:	Context of the command-line.
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK
 |										TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdResetBertStatsApply(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	/* Reset Bert stats */
	VoipCliSendResetBertStats();

	/* No more input to take. Return to main menu input. */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_NONE;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipCliCmdReloadConfigInit		:	Prepare user prompts for the 'Reload configuration' command
 |  VoipCliCmdReloadConfigValidate	:	Validate each user's input (called once per prompt)
 |  VoipCliCmdReloadConfigApply		:	Apply the command
 |
 |  io_pCmdContext					:	Context of the command-line.
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK
 |										TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdReloadConfigInit(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	/* Start gathering input to get configuration file name */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_RELOAD_CONFIG;

	/* Set prompt command */
	strcpy( io_pCmdContext->paszPrompt[0].szLine, "Enter config file name: " );

	/* Set default user input value */
	sprintf( io_pCmdContext->paszUserInput[0].szLine, "%s", g_pContext->szConfigFileName );
}

TBX_BOOL VoipCliCmdReloadConfigValidate(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PTBX_CHAR	pszUserInput = io_pCmdContext->paszUserInput[ io_pCmdContext->un32CurrentPromptIdx ].szLine;

	if( strlen(pszUserInput) >= sizeof(g_pContext->szConfigFileName) )
		return TBX_FALSE;

	return TBX_TRUE;
}

TBX_VOID VoipCliCmdReloadConfigApply(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	/* Save new default prompt values */
	strcpy( g_DefaultPrompts.ReloadConfig.szConfigFileName, io_pCmdContext->paszUserInput[0].szLine );

	/* Change the default configuration file name */
	strncpy( g_pContext->szConfigFileName, io_pCmdContext->paszUserInput[0].szLine, sizeof(g_pContext->szConfigFileName) );
	g_pContext->szConfigFileName[sizeof(g_pContext->szConfigFileName) - 1] = '\0';

	/* Reload configuration */
	VoipCliSendReloadConfig();

	/* No more input to take. Return to main menu input. */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_NONE;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipCliCmdSetTraceLevelInit		:	Prepare user prompts for the 'Set Trace Level' command
 |  VoipCliCmdSetTraceLevelValidate	:	Validate each user's input (called once per prompt)
 |  VoipCliCmdSetTraceLevelApply	:	Apply the command
 |
 |  in_pCmdContext					:	Context of the command-line.
 |
 |  Note							:	~
 |
 |  Return							:	TBX_RESULT_OK
 |										TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdSetTraceLevelInit(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PVOIP_CLI_CONTEXT			pCliContext = &g_pContext->CliContext;
	TBX_CLI_TOOLS_INIT_PARAMS	CliToolsInitParams;

	/* Get the current log trace level */
	TbxCliToolsGetParams( pCliContext->hCliTools, &CliToolsInitParams, NULL, NULL );

	/* Start gathering input to get trace level */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_SET_TRACE_LEVEL;

	/* Set prompt command */
	sprintf( io_pCmdContext->paszPrompt[0].szLine, "Enter display trace level (0-%d): ", TRACE_LEVEL_MAX );
	sprintf( io_pCmdContext->paszPrompt[1].szLine, "Enter log file trace level (0-%d): ", TRACE_LEVEL_MAX );

	/* Set default user input value */
	sprintf( io_pCmdContext->paszUserInput[0].szLine, "%u", (int)CliToolsInitParams.TraceLevelStdout );
	sprintf( io_pCmdContext->paszUserInput[1].szLine, "%u", (int)CliToolsInitParams.TraceLevelLogFile );
}

TBX_BOOL VoipCliCmdSetTraceLevelValidate(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PVOIP_CLI_CONTEXT			pCliContext = &g_pContext->CliContext;
	TBX_CLI_TOOLS_INIT_PARAMS	CliToolsInitParams;
	PTBX_CHAR					pszUserInput = io_pCmdContext->paszUserInput[ io_pCmdContext->un32CurrentPromptIdx ].szLine;

	/* Get the current log trace level */
	TbxCliToolsGetParams( pCliContext->hCliTools, &CliToolsInitParams, NULL, NULL );

	if( io_pCmdContext->un32CurrentPromptIdx == 0 )	/* Validate the display trace level */
	{
		TBX_UINT32	un32DisplayTraceLevel = strtoul( pszUserInput, NULL, 10 );

		if( !VoipCliIsValidNumericValue( pszUserInput ) )
		{
			/* Restore a valid value */
			sprintf( pszUserInput, "%u", (int)CliToolsInitParams.TraceLevelStdout );
			return TBX_FALSE;
		}

		if( un32DisplayTraceLevel > TRACE_LEVEL_MAX )
		{
			TbxCliToolsLogPrint
			(
				pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL,
				"Invalid display trace level (%u). Must be between 0 and %d.\n",
				(unsigned int)un32DisplayTraceLevel,
				TRACE_LEVEL_MAX
			);
			/* Restore a valid value */
			sprintf( pszUserInput, "%u", (int)CliToolsInitParams.TraceLevelStdout );
			return TBX_FALSE;
		}
	}
	else if( io_pCmdContext->un32CurrentPromptIdx == 1 )	/* Validate the log file trace level */
	{
		TBX_UINT32	un32LogFileTraceLevel = strtoul( pszUserInput, NULL, 10 );

		if( !VoipCliIsValidNumericValue( pszUserInput ) )
		{
			/* Restore a valid value */
			sprintf( pszUserInput, "%u", (int)CliToolsInitParams.TraceLevelLogFile );
			return TBX_FALSE;
		}

		if( un32LogFileTraceLevel > TRACE_LEVEL_MAX )
		{
			TbxCliToolsLogPrint
			(
				pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL,
				"Invalid log file trace level (%u). Must be between 0 and %d.\n",
				(unsigned int)un32LogFileTraceLevel,
				TRACE_LEVEL_MAX
			);
			/* Restore a valid value */
			sprintf( pszUserInput, "%u", (int)CliToolsInitParams.TraceLevelLogFile );
			return TBX_FALSE;
		}
	}

	return TBX_TRUE;
}

TBX_VOID VoipCliCmdSetTraceLevelApply(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	/* Save new default prompt values */
	g_DefaultPrompts.SetTraceLevel.un32TraceLevelStdout = strtoul( io_pCmdContext->paszUserInput[0].szLine, NULL, 10 );
	g_DefaultPrompts.SetTraceLevel.un32TraceLevelLogFile = strtoul( io_pCmdContext->paszUserInput[1].szLine, NULL, 10 );

	/* Validate values */
	if( g_DefaultPrompts.SetTraceLevel.un32TraceLevelStdout > (TBX_UINT32)TRACE_LEVEL_MAX )
		g_DefaultPrompts.SetTraceLevel.un32TraceLevelStdout = (TBX_UINT32)TRACE_LEVEL_MAX;
	if( g_DefaultPrompts.SetTraceLevel.un32TraceLevelLogFile > (TBX_UINT32)TRACE_LEVEL_MAX )
		g_DefaultPrompts.SetTraceLevel.un32TraceLevelLogFile = (TBX_UINT32)TRACE_LEVEL_MAX;

	VoipCliSendSetTraceLevel
	(
		g_DefaultPrompts.SetTraceLevel.un32TraceLevelStdout,
		g_DefaultPrompts.SetTraceLevel.un32TraceLevelLogFile
	);

	/* No more input to take. Return to main menu input. */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_NONE;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipCliCmdStartStressTestInit		:	Prepare user prompts for the 'Start Stress Test' command
 |  VoipCliCmdStartStressTestValidate	:	Validate each user's input (called once per prompt)
 |  VoipCliCmdStartStressTestApply		:	Apply the command
 |
 |  in_pCmdContext						:	Context of the command-line.
 |
 |  Note								:	~
 |
 |  Return								:	TBX_RESULT_OK
 |											TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdStartStressTestInit(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PVOIP_CLI_CONTEXT		pCliContext = &g_pContext->CliContext;
	PVOIP_ADAPTER_CONTEXT	pAdapterContext = pCliContext->pActiveAdapterContext;

	if( pAdapterContext->StressTest.fActive == TBX_TRUE )
	{
		TbxCliToolsLogPrint(
			pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL,
			"Stress-test already active.\n" );
		return;
	}

	if( VoipCliIsValidStreamSocketIP(pAdapterContext->StressTest.szStreamSocketIP) == TBX_TRUE )
	{
		/* Save new default prompt values */
		strcpy( g_DefaultPrompts.StartStressTest.szStreamSocketIP, pAdapterContext->StressTest.szStreamSocketIP );
	}

	/* Start gathering input for 'disconnect resources' */
	io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_START_STRESS_TEST;

	/* Set prompt command */
	strcpy( io_pCmdContext->paszPrompt[0].szLine, "Enter stream socket IP address: " );
	strcpy( io_pCmdContext->paszPrompt[1].szLine, "Enter first resource type (0=trunk, 1=MBL, 2=prompt): " );
	strcpy( io_pCmdContext->paszPrompt[2].szLine, "Enter connections by second attempt: " );
	strcpy( io_pCmdContext->paszPrompt[3].szLine, "Enter minimum connection duration (in seconds): " );
	strcpy( io_pCmdContext->paszPrompt[4].szLine, "Enter maximum connection duration (in seconds): " );
	strcpy( io_pCmdContext->paszPrompt[5].szLine, "Abort on failure? " );
	strcpy( io_pCmdContext->paszPrompt[6].szLine, "Reset all connections? " );
	strcpy( io_pCmdContext->paszPrompt[7].szLine, "Do BER testing? " );
	strcpy( io_pCmdContext->paszPrompt[8].szLine, "Test duration in sec (-1 for infinite)? " );

	/* Set default user input value */
	sprintf( io_pCmdContext->paszUserInput[0].szLine, "%s", g_DefaultPrompts.StartStressTest.szStreamSocketIP );
	sprintf( io_pCmdContext->paszUserInput[1].szLine, "%u", (unsigned int)g_DefaultPrompts.StartStressTest.un32FirstResTypeIndex );
	sprintf( io_pCmdContext->paszUserInput[2].szLine, "%u", (unsigned int)g_DefaultPrompts.StartStressTest.un32NbConnectionsPerSecond );
	sprintf( io_pCmdContext->paszUserInput[3].szLine, "%u", (unsigned int)g_DefaultPrompts.StartStressTest.un32MinConnectionDuration );
	sprintf( io_pCmdContext->paszUserInput[4].szLine, "%u", (unsigned int)g_DefaultPrompts.StartStressTest.un32MaxConnectionDuration );
	sprintf( io_pCmdContext->paszUserInput[5].szLine, "%s", (g_DefaultPrompts.StartStressTest.fAutoAbort == TBX_TRUE)?"YES":"NO" );
	sprintf( io_pCmdContext->paszUserInput[6].szLine, "%s", (g_DefaultPrompts.StartStressTest.fDisconnectAllRes == TBX_TRUE)?"YES":"NO" );
	sprintf( io_pCmdContext->paszUserInput[7].szLine, "%s", (g_DefaultPrompts.StartStressTest.fDoBertTests == TBX_TRUE)?"YES":"NO" );
	sprintf( io_pCmdContext->paszUserInput[8].szLine, "%d", (unsigned int)g_DefaultPrompts.StartStressTest.un32TestDurationSec );
}

TBX_BOOL VoipCliCmdStartStressTestValidate(
	IN OUT	PTBX_CLI_TOOLS_CMD	io_pCmdContext )
{
	PVOIP_CLI_CONTEXT		pCliContext = &g_pContext->CliContext;
	PTBX_CHAR	pszUserInput = io_pCmdContext->paszUserInput[ io_pCmdContext->un32CurrentPromptIdx ].szLine;

	/* Make uppercase */
	ToUpper( pszUserInput );

	switch( io_pCmdContext->un32CurrentPromptIdx )
	{
		case 0:	/* Validate stream socket IP address */
		{
			if( pszUserInput[0] == '\0' )
			{
				TbxCliToolsLogPrint
				(
					pCliContext->hCliTools,
					TRACE_LEVEL_ERROR, NULL,
					"Stream socket IP address can't be empty.\n"
				);
				/* Restore a valid value */
				strcpy( pszUserInput, g_DefaultPrompts.StartStressTest.szStreamSocketIP );
				return TBX_FALSE;
			}
			else
			{
				if( !VoipCliIsValidStreamSocketIP( pszUserInput ) )
				{
					/* Restore a valid value */
					strcpy( pszUserInput, g_DefaultPrompts.StartStressTest.szStreamSocketIP );
					return TBX_FALSE;
				}
			}
		} break;

⌨️ 快捷键说明

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