📄 voip_adapter_state.c
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
|
| Project: VOIP sample
|
| Filename: voip_adapter_state.c
|
| Copyright: TelcoBridges 2002-2004, All Rights Reserved
|
| Description: This file contains state machine functions for adapters in this VoIP System
|
| Notes: Tabs = 4
|
*-------------------------------------------------------------------------------------------------------------------------------
|
| Revision: $Revision: 1.39 $
|
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Includes
*------------------------------------------------------------------------------------------------------------------------------*/
#include "voip_includes.h"
/*--------------------------------------------------------------------------------------------------------------------------------
| Forward declarations
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Defines
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Types
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Versioning
*------------------------------------------------------------------------------------------------------------------------------*/
#ifdef WIN32
/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.39 $";
#endif
/*--------------------------------------------------------------------------------------------------------------------------------
| Global variables
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Macros
*------------------------------------------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------------------------------------------------------------
| Function Prototypes
*------------------------------------------------------------------------------------------------------------------------------*/
#define VOIP_HANDLE_COMMON_EVENTS( _pAdapterContext, _hMsg, _fIgnore ) \
case TB640_MSG_ID_CLK_SYNC_NOTIF_STATE_CHANGE: \
{ \
if( !(_fIgnore) ) \
{ \
/* Handle this response */ \
Result = VoipHandleAdapterClockStateChange( (_pAdapterContext), (_hMsg) ); \
if( TBX_RESULT_FAILURE( Result ) ) (_pAdapterContext)->StateResult = Result; \
} \
} break;
/*--------------------------------------------------------------------------------------------------------------------------------
| Implementation
*------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterStateUndefined : Handles adapter state: Undefined.
| This function should not be called, ever.
|
| io_pAdapterContext : Context of the adapter
| in_hMsg : Message received for this adapter
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipAdapterStateUndefined(
IN PTBX_VOID io_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
VoipCliAdapterStatePrint
(
io_pAdapterContext,
TRACE_LEVEL_ERROR,
"Bug: VoipAdapterStateUndefined Called, message 0x%08X, adapter 0x%X\n",
TBX_MSG_ID_GET( in_hMsg ),
TBX_MSG_ADAPTER_HANDLE_GET( in_hMsg )
);
return;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterStateNotUsed : Handles adapter state: VOIP_ADAPTER_STATE_NOT_USED.
| This function is called when receiving response/event
| for an adapter we are not using in this state machine.
|
| io_pAdapterContext : Context of the adapter
| in_hMsg : Message received for this adapter
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipAdapterStateNotUsed(
IN PTBX_VOID io_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
TBX_RESULT Result;
PVOIP_ADAPTER_CONTEXT pAdapterContext = io_pAdapterContext;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
Result = TBX_RESULT_OK;
switch( TBX_MSG_ID_GET( in_hMsg ) )
{
VOIP_HANDLE_COMMON_EVENTS( pAdapterContext, in_hMsg, TBX_TRUE )
case VOIP_MSG_ID_NOTIF_STATE_ENTER:
{
/* Sanity check */
if( pAdapterContext->un32NbResponsesExpected != 0 )
{
VoipCliAdapterStatePrint
(
pAdapterContext,
TRACE_LEVEL_ERROR,
"BUG: State entered while %d responses still awaited from previous state!\n",
(int)pAdapterContext->un32NbResponsesExpected
);
pAdapterContext->un32NbResponsesExpected = 0;
}
/* Set initial state result */
pAdapterContext->StateResult = TBX_RESULT_OK;
pAdapterContext->fStateTimedout = TBX_FALSE;
pAdapterContext->fDetachSent = TBX_FALSE;
/* We are no more waiting for "Stop Using" */
pAdapterContext->fStopUsingPending = TBX_FALSE;
pAdapterContext->fSyncCompleted = TBX_FALSE;
/* Clear any config that could be stored in this adapter */
VoipAdapterClearConfig( &pAdapterContext->CurrentConfig );
VoipAdapterClearConfig( &pAdapterContext->TargetConfig1 );
VoipAdapterClearConfig( &pAdapterContext->TargetConfig2 );
/* Clear this adapter's current status */
memset( &pAdapterContext->Status, 0, sizeof(pAdapterContext->Status) );
/* Update CLI context */
VoipCliUpdate();
} break;
case TBX_MSG_ID_API_NOTIF_ADAPTER_ADDED:
{
/* Leave state machine in "not used" state */
} break;
case VOIP_MSG_ID_NOTIF_ADAPTER_ACTIVATED_CHANGED:
{
/* Nothing to do here */
} break;
case VOIP_MSG_ID_NOTIF_STOP_USING:
{
/* We are already not using this adapter */
} break;
case VOIP_MSG_ID_NOTIF_APPLY_NEW_CONFIG:
{
pAdapterContext->fNewConfigPending = TBX_TRUE;
} break;
case VOIP_MSG_ID_NOTIF_RECHECK_STATES:
{
/* Nothing to do */
} break;
default:
{
/* Ignore any other message/event from this not used adapter */
} break;
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print the error to the user */
VoipCliAdapterStatePrint(
pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipAdapterStateNotUsed: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
return;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterStateNotReady : Handles adapter state: VOIP_ADAPTER_STATE_NOT_READY.
| This function is called when receiving response/event
| for an adapter we are not attached to yet.
|
| io_pAdapterContext : Context of the adapter
| in_hMsg : Message received for this adapter
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipAdapterStateNotReady(
IN PTBX_VOID io_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
TBX_RESULT Result;
PVOIP_ADAPTER_CONTEXT pAdapterContext = io_pAdapterContext;
TBX_CHAR szErrorMsg[ 256 ];
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
Result = TBX_RESULT_OK;
switch( TBX_MSG_ID_GET( in_hMsg ) )
{
VOIP_HANDLE_COMMON_EVENTS( pAdapterContext, in_hMsg, TBX_TRUE )
case VOIP_MSG_ID_NOTIF_STATE_ENTER:
{
/* Set initial state result */
pAdapterContext->StateResult = TBX_RESULT_OK;
pAdapterContext->fStateTimedout = TBX_FALSE;
pAdapterContext->fDetachSent = TBX_FALSE;
/* Not expecting any more responses. */
pAdapterContext->un32NbResponsesExpected = 0;
/* Clear resources info for that adapter */
VoipAdapterClearConfig( &pAdapterContext->CurrentConfig );
/* Clear this adapter's current status */
memset( &pAdapterContext->Status, 0, sizeof(pAdapterContext->Status) );
if( pAdapterContext->fPresent )
{
/* Enter the first state machine state for this adapter: Synchronize with adapter's state */
VoipAdapterChangeState( pAdapterContext, VOIP_ADAPTER_STATE_SYNC );
}
} break;
case TBX_MSG_ID_API_NOTIF_ADAPTER_ADDED:
{
/* Enter the first state machine state for this adapter: Synchronize with adapter's state */
VoipAdapterChangeState( pAdapterContext, VOIP_ADAPTER_STATE_SYNC );
} break;
case VOIP_MSG_ID_NOTIF_ADAPTER_ACTIVATED_CHANGED:
{
/* Nothing to do here */
} break;
case VOIP_MSG_ID_NOTIF_STOP_USING:
{
VoipCliAdapterStatePrint( pAdapterContext, TRACE_LEVEL_3, "Stop using adapter\n" );
/* We are not connected to this adapter. There is nothing to do to disable it. */
VoipAdapterChangeState( pAdapterContext, VOIP_ADAPTER_STATE_NOT_USED );
} break;
case VOIP_MSG_ID_NOTIF_APPLY_NEW_CONFIG:
{
pAdapterContext->fNewConfigPending = TBX_TRUE;
} break;
case VOIP_MSG_ID_NOTIF_RECHECK_STATES:
{
/* Nothing to do */
} break;
case VOIP_MSG_ID_NOTIF_UPDATE_ALL_STATES:
{
/* Nothing to do */
} break;
case VOIP_MSG_ID_NOTIF_STATE_TIMEOUT:
{
/* Not supposed to happen */
TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Received timeout, while supposed to be infinity.");
} break;
default:
{
/* Not supposed to happen! */
if( TBX_MSG_TYPE_GET( in_hMsg ) == TBX_MSG_TYPE_RESPONSE )
{
if( pAdapterContext->un32NbResponsesExpected )
pAdapterContext->un32NbResponsesExpected--;
}
sprintf( szErrorMsg, "Unexpected message id 0x%X for this state\n", (int)TBX_MSG_ID_GET( in_hMsg ) );
TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, szErrorMsg);
} break;
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print the error to the user */
VoipCliAdapterStatePrint(
pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipAdapterStateNotReady: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -