📄 voip_adapter_sync.c
字号:
/* Validate response content */
if( pResponse->un32Trunk >= VOIP_MAX_TRUNK_PER_ADAPTER )
{
sprintf( szErrorString, "Unexpected trunk number (%d, max supported is %d)\n", (int)pResponse->un32Trunk, (int)(VOIP_MAX_TRUNK_PER_ADAPTER-1) );
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_RESOURCE, 0, szErrorString);
}
/* Store received parameters into our local table */
pCurrentTrunkConfig = &in_pAdapterContext->CurrentConfig.aTrunk[ pResponse->un32Trunk ];
pCurrentTrunkConfig->fAllocated = TBX_TRUE;
pCurrentTrunkConfig->fActivated = TBX_FALSE;
pCurrentTrunkConfig->un32TrunkNumber = pResponse->un32Trunk;
pCurrentTrunkConfig->hTrunk = (TB640_TRUNK_HANDLE)TBX_MSG_USER_CONTEXT1_GET( in_hMsg );
pCurrentTrunkConfig->TrunkCfg = pResponse->TrunkCfg;
if (pCurrentTrunkConfig->TrunkCfg.Type == TB640_TRUNK_TYPE_E1)
{
pCurrentTrunkConfig->un32MaxTimeSlot = VOIP_MAX_TIMESLOT_PER_E1_TRUNK;
}
else
{
pCurrentTrunkConfig->un32MaxTimeSlot = VOIP_MAX_TIMESLOT_PER_T1_TRUNK;
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
VoipCliAdapterStatePrint(
in_pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipHandleAdapterGetTrunkParamsResponse: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipSendAdapterGetTrunkStates : Send message of type TB640_MSG_ID_TRUNK_OP_GET_STATES
|
| in_pAdapterContext : Adapter to send the message to.
| in_hTrunk : Handle of the trunk to query parameters for
|
| Note : ~
|
| Return : TBX_RESULT_OK if the function succeeded
| Other error code if the function could not complete properly.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipSendAdapterGetTrunkStates(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN TB640_TRUNK_HANDLE in_hTrunk)
{
/* Send request macro part 1: Allocate and prepare message buffer */
VOIP_SEND_REQUEST_BODY_PART1( TRUNK_STATES_GET, 0 )
{
if( in_pAdapterContext->fStopUsingPending )
{
/* We must not use this adapter anymore (stop using). Don't send request. */
TBX_EXIT_SUCCESS (Result);
}
VoipCliAdapterStatePrint
(
in_pAdapterContext,
TRACE_LEVEL_0,
"Getting trunk states for trunk 0x%08X\n",
(int)in_hTrunk
);
/* Fill request parameters */
pMsg->Request.hTrunk = in_hTrunk;
/* Store the trunk handle we are querying in the user context, to retrieve our context upon response reception */
TBX_MSG_USER_CONTEXT1_SET( hMsg, (TBX_UINT64)in_hTrunk );
}
/* Send request macro part 2: Send the request, return result code */
VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterGetTrunkStates")
}
/* Function to handle the response of the message above */
TBX_RESULT VoipHandleAdapterGetTrunkStatesResponse(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
PTB640_RSP_TRUNK_STATES_GET pResponse;
TB640_TRUNK_HANDLE hTrunk;
TBX_UINT32 un32TrunkNumber;
TB640_TRUNK_STATE TrunkState;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
pResponse = TBX_MSG_PAYLOAD_POINTER( in_hMsg );
un32TrunkNumber = (TBX_UINT32)-1;
/* Count this received response */
if( in_pAdapterContext->un32NbResponsesExpected )
{
in_pAdapterContext->un32NbResponsesExpected--;
}
hTrunk = (TB640_TRUNK_HANDLE)TBX_MSG_USER_CONTEXT1_GET( in_hMsg );
/* Retrieve the trunk that has that handle */
for( un32TrunkNumber = 0; un32TrunkNumber < VOIP_MAX_TRUNK_PER_ADAPTER; un32TrunkNumber++ )
{
if( in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNumber ].fAllocated )
{
if( in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNumber ].hTrunk == hTrunk )
{
break;
}
}
}
if( un32TrunkNumber == VOIP_MAX_TRUNK_PER_ADAPTER )
{
TBX_EXIT_ERROR (TBX_RESULT_MISMATCH, 0, "Failed to retrieve trunk we are trying to get states for!");
}
if( TBX_RESULT_FAILURE( pResponse->Result ) )
{
/* Request failed. */
TBX_EXIT_ERROR (pResponse->Result, 0, "Failed to get trunk states!");
}
/* Store the trunk state */
switch( pResponse->aStates[0].Type )
{
case TB640_TRUNK_TYPE_E1:
TrunkState = pResponse->aStates[0].States.E1.State;
break;
case TB640_TRUNK_TYPE_T1:
TrunkState = pResponse->aStates[0].States.T1.State;
break;
case TB640_TRUNK_TYPE_J1:
TrunkState = pResponse->aStates[0].States.J1.State;
break;
default:
/* Not supposed to happen */
TrunkState = TB640_TRUNK_STATE_FIRST;
break;
}
if
(
TrunkState == TB640_TRUNK_STATE_ACTIVE ||
TrunkState == TB640_TRUNK_STATE_ACTIVE_WITH_STACK
)
{
in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNumber ].fActivated = TBX_TRUE;
}
else
{
in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNumber ].fActivated = TBX_FALSE;
}
/* Keep the trunk states */
memcpy
(
&( in_pAdapterContext->Status.aTrunk[ un32TrunkNumber ].States ),
&( pResponse->aStates[0] ),
sizeof( in_pAdapterContext->Status.aTrunk[ un32TrunkNumber ].States )
);
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
VoipCliAdapterStatePrint(
in_pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipHandleAdapterGetTrunkStatesResponse: %s, trunk %d (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)un32TrunkNumber,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipSendAdapterGetTrunkResList : Send message of type TB640_MSG_ID_TRUNK_RES_GET_LIST
|
| in_pAdapterContext : Adapter to send the message to.
| in_hTrunk : Handle of the trunk to query parameters for
|
| Note : ~
|
| Return : TBX_RESULT_OK if the function succeeded
| Other error code if the function could not complete properly.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipSendAdapterGetTrunkResList(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN TB640_TRUNK_HANDLE in_hTrunk)
{
/* Send request macro part 1: Allocate and prepare message buffer */
VOIP_SEND_REQUEST_BODY_PART1( TRUNK_RES_GET_LIST, 0 )
{
if( in_pAdapterContext->fStopUsingPending )
{
/* We must not use this adapter anymore (stop using). Don't send request. */
TBX_EXIT_SUCCESS (Result);
}
VoipCliAdapterStatePrint
(
in_pAdapterContext,
TRACE_LEVEL_1,
"Getting trunk resources list for trunk 0x%08X\n",
(int)in_hTrunk
);
/* Fill request parameters */
pMsg->Request.hTrunk = in_hTrunk;
/* Store the trunk handle we are querying in the user context, to retrieve our context upon response reception */
TBX_MSG_USER_CONTEXT1_SET( hMsg, (TBX_UINT64)in_hTrunk );
}
/* Send request macro part 2: Send the request, return result code */
VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterGetTrunkResList")
}
/* Function to handle the response of the message above */
TBX_RESULT VoipHandleAdapterGetTrunkResListResponse(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
TBX_RESULT Result;
PTB640_RSP_TRUNK_RES_GET_LIST pResponse;
TB640_TRUNK_HANDLE hTrunk;
TBX_UINT32 un32TrunkNumber;
TBX_CHAR szErrorString[ 256 ];
TBX_UINT32 un32Index;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
pResponse = TBX_MSG_PAYLOAD_POINTER( in_hMsg );
/* Count this received response */
if( in_pAdapterContext->un32NbResponsesExpected )
{
in_pAdapterContext->un32NbResponsesExpected--;
}
hTrunk = (TB640_TRUNK_HANDLE)TBX_MSG_USER_CONTEXT1_GET( in_hMsg );
/* Retrieve the trunk that has that handle */
for( un32TrunkNumber = 0; un32TrunkNumber < VOIP_MAX_TRUNK_PER_ADAPTER; un32TrunkNumber++ )
{
if( in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNumber ].fAllocated )
{
if( in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNumber ].hTrunk == hTrunk )
{
break;
}
}
}
if( un32TrunkNumber == VOIP_MAX_TRUNK_PER_ADAPTER )
{
TBX_EXIT_ERROR (TBX_RESULT_MISMATCH, 0, "Failed to retrieve trunk we are trying to get resources list for!");
}
if( TBX_RESULT_FAILURE( pResponse->Result ) )
{
/* Request failed. */
TBX_EXIT_ERROR (pResponse->Result, 0, "Failed to get trunk resources list!");
}
/* Validate response content */
if( pResponse->un32TrunkResCount >= VOIP_MAX_RES_PER_TRUNK )
{
sprintf( szErrorString, "Unexpected trunk resources count (%d, max supported is %d)\n", (int)pResponse->un32TrunkResCount, (int)(VOIP_MAX_RES_PER_TRUNK-1) );
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_RESOURCE, 0, szErrorString);
}
/* Query parameters for every listed trunk resources */
for( un32Index = 0; un32Index < pResponse->un32TrunkResCount; un32Index++ )
{
Result = VoipSendAdapterGetTrunkResParams( in_pAdapterContext, hTrunk, pResponse->ahTrunkRes[ un32Index ] );
if( TBX_RESULT_FAILURE( Result ) )
{
TBX_EXIT_SUCCESS (Result); /* Return error code, but don't display error in this function */
}
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
VoipCliAdapterStatePrint(
in_pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipHandleAdapterGetTrunkResListResponse: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipSendAdapterGetTrunkResParams : Send message of type TB640_MSG_ID
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -