📄 voip_adapter_sync.c
字号:
{
/* Initialize local variables */
pResponse = TBX_MSG_PAYLOAD_POINTER( in_hMsg );
/* Count this received response */
if( in_pAdapterContext->un32NbResponsesExpected )
{
in_pAdapterContext->un32NbResponsesExpected--;
}
hBertRes = (TB640_RESOURCE_HANDLE)TBX_MSG_USER_CONTEXT1_GET( in_hMsg );
if( TBX_RESULT_FAILURE( pResponse->Result ) )
{
/* Request failed. */
TBX_EXIT_ERROR (pResponse->Result, 0, "Failed to get BERT resource params!");
}
pCurrentBertRes = &in_pAdapterContext->CurrentConfig.aBertRes[ 0 ];
/* Insert resource handle in hash table */
Result = TBXHashInsert(
in_pAdapterContext->CurrentConfig.hResHandleHash,
(TBX_HASH_KEY)hBertRes,
pCurrentBertRes);
if( TBX_RESULT_FAILURE( Result ) )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_RESOURCE, 0, "Failed to insert BERT resource in resource handle hash table!");
}
/* Store received parameters into our local table */
pCurrentBertRes->Common.hRes = hBertRes;
pCurrentBertRes->Common.un32ConnectionId = 0;
pCurrentBertRes->Common.fAllocated = TBX_TRUE;
pCurrentBertRes->Common.fMustClear = TBX_FALSE;
pCurrentBertRes->Params = pResponse->Params;
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
VoipCliAdapterStatePrint(
in_pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipHandleAdapterGetBertResParamsResponse: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipSendAdapterGetBertResStates : Send message of type TB640_MSG_ID_BERT_RES_GET_STATES
|
| in_pAdapterContext : Adapter to send the message to.
| in_hBertRes : Handle of the BERT resource to query parameters for
| in_fReset : True to reset stats
|
| Note : ~
|
| Return : TBX_RESULT_OK if the function succeeded
| Other error code if the function could not complete properly.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipSendAdapterGetBertResStates(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN TB640_RESOURCE_HANDLE in_hBertRes,
IN TBX_BOOL in_fReset)
{
VOIP_SEND_REQUEST_BODY_PART1( BERT_RES_GET_STATES, 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 BERT resource states\n"
);
/* Fill request parameters */
pMsg->Request.fResetStats = in_fReset;
pMsg->Request.hResource = in_hBertRes;
/* Store the BERT resource handle we are querying in the user context, to retrieve our context upon response reception */
TBX_MSG_USER_CONTEXT1_SET( hMsg, (TBX_UINT64)in_hBertRes );
}
/* Send request macro part 2: Send the request, return result code */
VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterGetBertResStates")
}
/* Function to handle the response of the message above */
TBX_RESULT VoipHandleAdapterGetBertResStatesResponse(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
PTB640_RSP_BERT_RES_GET_STATES pResponse;
TB640_RESOURCE_HANDLE hBertRes;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
pResponse = TBX_MSG_PAYLOAD_POINTER( in_hMsg );
/* Count this received response */
if( in_pAdapterContext->un32NbResponsesExpected )
{
in_pAdapterContext->un32NbResponsesExpected--;
}
hBertRes = (TB640_RESOURCE_HANDLE)TBX_MSG_USER_CONTEXT1_GET( in_hMsg );
if( TBX_RESULT_FAILURE( pResponse->Result ) )
{
/* Request failed. */
TBX_EXIT_ERROR (pResponse->Result, 0, "Failed to get BERT resource states!");
}
/* Store the BERT resource state for this adapter */
in_pAdapterContext->Status.aBertRes[ 0 ] = pResponse->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,
"VoipHandleAdapterGetBertResStatesResponse: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipSendAdapterGetTrunkList : Send message of type TB640_MSG_ID_TRUNK_OP_GET_LIST
|
| in_pAdapterContext : Adapter to send the message to.
|
| Note : ~
|
| Return : TBX_RESULT_OK if the function succeeded
| Other error code if the function could not complete properly.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipSendAdapterGetTrunkList(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext)
{
/* Send request macro part 1: Allocate and prepare message buffer */
VOIP_SEND_REQUEST_BODY_PART1( TRUNK_OP_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,
"Listing trunks\n"
);
/* No specific parameters to set in this message type */
}
/* Send request macro part 2: Send the request, return result code */
VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterGetTrunkList")
}
/* Function to handle the response of the message above */
TBX_RESULT VoipHandleAdapterGetTrunkListResponse(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
TBX_RESULT Result;
TBX_UINT32 un32Index;
PTB640_RSP_TRUNK_OP_GET_LIST pResponse;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
pResponse = TBX_MSG_PAYLOAD_POINTER( in_hMsg );
/* Count this received response */
if( in_pAdapterContext->un32NbResponsesExpected )
{
in_pAdapterContext->un32NbResponsesExpected--;
}
if( TBX_RESULT_FAILURE( pResponse->Result ) )
{
/* Request failed. */
TBX_EXIT_ERROR (pResponse->Result, 0, "Failed to get trunk list!");
}
/* Query parameters and states for every listed trunk */
for( un32Index = 0; un32Index < pResponse->un32TrunkCount; un32Index++ )
{
Result = VoipSendAdapterGetTrunkParams( in_pAdapterContext, pResponse->ahTrunk[ un32Index ] );
if( TBX_RESULT_FAILURE( Result ) )
{
TBX_EXIT_SUCCESS (Result); /* Return error code, but don't display error in this function */
}
Result = VoipSendAdapterGetTrunkStates( in_pAdapterContext, pResponse->ahTrunk[ un32Index ] );
if( TBX_RESULT_FAILURE( Result ) )
{
TBX_EXIT_SUCCESS (Result); /* Return error code, but don't display error in this function */
}
Result = VoipSendAdapterGetTrunkResList( in_pAdapterContext, pResponse->ahTrunk[ 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,
"VoipHandleAdapterGetTrunkListResponse: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipSendAdapterGetTrunkParams : Send message of type TB640_MSG_ID_TRUNK_OP_GET_PARAMS
|
| 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 VoipSendAdapterGetTrunkParams(
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_OP_GET_PARAMS, 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 parameters for trunk 0x%X\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("VoipSendAdapterGetTrunkParams")
}
/* Function to handle the response of the message above */
TBX_RESULT VoipHandleAdapterGetTrunkParamsResponse(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
PTB640_RSP_TRUNK_OP_GET_PARAMS pResponse;
TBX_CHAR szErrorString[ 256 ];
PVOIP_TRUNK_CONFIG pCurrentTrunkConfig;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
pResponse = TBX_MSG_PAYLOAD_POINTER( in_hMsg );
/* Count this received response */
if( in_pAdapterContext->un32NbResponsesExpected )
{
in_pAdapterContext->un32NbResponsesExpected--;
}
if( TBX_RESULT_FAILURE( pResponse->Result ) )
{
/* Request failed. */
TBX_EXIT_ERROR (pResponse->Result, 0, "Failed to get trunk params!");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -