📄 voip_adapter_alloc.c
字号:
(
in_pAdapterContext,
in_hMsg
);
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (Result);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
VoipCliAdapterStatePrint(
in_pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipHandleAdapterTrunkActivateResponse: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipSendAdapterStreamResAlloc : Allocates a stream resource on the adapter.
|
| in_pAdapterContext : Adapter configuration we are configuring
| in_pTargetStreamRes : Target stream resource to allocate
|
| Note : ~
|
| Return : TBX_RESULT_OK if the function succeeded
| Other error code if the function could not complete properly.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipSendAdapterStreamResAlloc(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN PVOIP_STREAM_RES in_pTargetStreamRes)
{
VOIP_SEND_REQUEST_BODY_PART1( STREAM_RES_ALLOC, 0 )
{
if( in_pAdapterContext->fStopUsingPending )
{
/* We must not use this adapter anymore (stop using). Don't send request. */
TBX_EXIT_SUCCESS (Result);
}
if( in_pAdapterContext->fNewConfigPending )
{
/* Config has been changed. Don't loose too much time trying to allocate things that may not be
required in the new config... */
TBX_EXIT_SUCCESS (Result);
}
VoipCliAdapterStatePrint
(
in_pAdapterContext,
TRACE_LEVEL_1,
"Allocating stream resource for connection 0x%08X\n",
in_pTargetStreamRes->Common.un32ConnectionId
);
/* Store the connection identifier we are configuring in the user context, to retrieve our context upon response reception */
TBX_MSG_USER_CONTEXT1_SET( hMsg, (TBX_UINT64)in_pTargetStreamRes->Common.un32ConnectionId );
/* Fill request parameters */
pMsg->Request.StreamResParams = in_pTargetStreamRes->Params;
}
/* Send request macro part 2: Send the request, return Result code */
VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterStreamResAlloc")
}
/* Function to handle the response of the message above */
TBX_RESULT VoipHandleAdapterStreamResAllocResponse(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
TBX_RESULT Result;
PTB640_RSP_STREAM_RES_ALLOC pResponse;
PVOIP_STREAM_RES pTargetStreamRes;
PVOIP_STREAM_RES pCurrentStreamRes;
TBX_UINT32 un32ConnectionId;
TBX_UINT64 un64UserContext1;
TBX_UINT32 aun32UserContext1[2];
TBX_CHAR szError[256];
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
pResponse = TBX_MSG_PAYLOAD_POINTER( in_hMsg );
un64UserContext1 = TBX_MSG_USER_CONTEXT1_GET( in_hMsg );
un32ConnectionId = (TBX_UINT32)un64UserContext1;
/* Count this received response */
if( in_pAdapterContext->un32NbResponsesExpected )
{
in_pAdapterContext->un32NbResponsesExpected--;
}
VoipCliAdapterStatePrint
(
in_pAdapterContext,
TRACE_LEVEL_1,
"Allocate stream resource for connection 0x%08X result is 0x%08X\n",
(int)un32ConnectionId,
(int)pResponse->Result
);
if( TBX_RESULT_FAILURE( pResponse->Result ) )
{
/* Request failed. */
TBX_EXIT_ERROR (pResponse->Result, 0, "Failed to alloc stream resource!");
}
if( VOIP_IS_VALID_CONNECTION_ID( un32ConnectionId ) == TBX_FALSE )
{
aun32UserContext1[0] = (TBX_UINT32)(un64UserContext1 >> 32);
aun32UserContext1[1] = (TBX_UINT32)(un64UserContext1);
sprintf(szError, "Retrieved invalid connection identifier from user context (0x%08X%08X)", aun32UserContext1[1], aun32UserContext1[0] );
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PARAM, 0, szError);
}
/* Find the corresponding target stream resource context */
Result = TBXHashFind
(
in_pAdapterContext->pTargetConfig->hStreamResHash,
(TBX_HASH_KEY)un32ConnectionId,
(PTBX_VOID*)&pTargetStreamRes
);
if( TBX_RESULT_FAILURE(Result) == TBX_TRUE )
{
TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to find target stream resource context!");
}
/* Get free stream resource context */
pCurrentStreamRes = TBXPoolOfBuffersAlloc
(
in_pAdapterContext->CurrentConfig.hPoolOfStreamRes,
(TBX_HASH_KEY)NULL
);
if( pCurrentStreamRes == NULL )
{
TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to allocate element from pool of stream resource buffers.");
}
/* Insert stream resource handle */
Result = TBXHashInsert
(
in_pAdapterContext->CurrentConfig.hResHandleHash,
(TBX_HASH_KEY)pResponse->hStreamRes,
pCurrentStreamRes
);
if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
{
TBX_EXIT_ERROR (Result, 0, "Failed to insert element in resource handle hash table.");
}
/* Allocate and initialize our "current" context. (config will be copied later in file "voip_adapter_set.c") */
pCurrentStreamRes->Common.hRes = pResponse->hStreamRes;
pCurrentStreamRes->Common.fAllocated = TBX_TRUE;
pCurrentStreamRes->Common.fMustClear = TBX_FALSE;
pCurrentStreamRes->Common.fUsed = TBX_TRUE;
pCurrentStreamRes->Common.un32ConnectionId = un32ConnectionId;
pCurrentStreamRes->Params = pTargetStreamRes->Params;
/* Insert stream resource context in hash table of connection identifiers */
Result = TBXHashInsert
(
in_pAdapterContext->CurrentConfig.hStreamResHash,
(TBX_HASH_KEY)un32ConnectionId,
pCurrentStreamRes
);
if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
{
TBX_EXIT_ERROR (Result, 0, "Failed to insert element in stream resource hash table.");
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
VoipCliAdapterStatePrint(
in_pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipHandleAdapterStreamResAllocResponse: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipSendAdapterVpGroupAlloc : Allocates a voice processing group on the adapter.
|
| in_pAdapterContext : Adapter configuration we are configuring
| in_pTargetvpGroup : Target voice processing group to allocate
|
| Note : ~
|
| Return : TBX_RESULT_OK if the function succeeded
| Other error code if the function could not complete properly.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipSendAdapterVpGroupAlloc(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN PVOIP_VP_GROUP in_pTargetVpGroup)
{
TBX_UINT32 un32Index;
VOIP_SEND_REQUEST_BODY_PART1( VP_GROUP_ALLOC, sizeof( in_pTargetVpGroup->aRes[0].Params ) * in_pTargetVpGroup->un32NbResources )
{
if( in_pAdapterContext->fStopUsingPending )
{
/* We must not use this adapter anymore (stop using). Don't send request. */
TBX_EXIT_SUCCESS (Result);
}
if( in_pAdapterContext->fNewConfigPending )
{
/* Config has been changed. Don't loose too much time trying to allocate things that may not be
required in the new config... */
TBX_EXIT_SUCCESS (Result);
}
VoipCliAdapterStatePrint
(
in_pAdapterContext,
TRACE_LEVEL_1,
"Allocating voice processing group for connection 0x%08X\n",
in_pTargetVpGroup->Common.un32ConnectionId
);
if( (in_pTargetVpGroup->GroupParams.GroupType == TB640_VP_GROUP_TYPE_0) && (in_pAdapterContext->CurrentConfig.fVpGroup0Available == TBX_FALSE) )
{
TBX_EXIT_SUCCESS( TBX_RESULT_FAIL );
}
if( (in_pTargetVpGroup->GroupParams.GroupType == TB640_VP_GROUP_TYPE_1) && (in_pAdapterContext->CurrentConfig.fVpGroup1Available == TBX_FALSE) )
{
TBX_EXIT_SUCCESS( TBX_RESULT_FAIL );
}
/* Store the connection identifier we are configuring in the user context, to retrieve our context upon response reception */
TBX_MSG_USER_CONTEXT1_SET( hMsg, (TBX_UINT64)in_pTargetVpGroup->Common.un32ConnectionId );
/* Fill request parameters */
pMsg->Request.un32NbResources = in_pTargetVpGroup->un32NbResources;
pMsg->Request.GroupParams = in_pTargetVpGroup->GroupParams;
for( un32Index = 0; un32Index < in_pTargetVpGroup->un32NbResources; un32Index++ )
{
pMsg->Request.aResourcesParam[ un32Index ] = in_pTargetVpGroup->aRes[ un32Index ].Params;
}
}
/* Send request macro part 2: Send the request, return Result code */
VOIP_SEND_REQUEST_BODY_PART2("VoipSendAdapterVpGroupAlloc")
}
/* Function to handle the response of the message above */
TBX_RESULT VoipHandleAdapterVpGroupAllocResponse(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN TBX_MSG_HANDLE in_hMsg)
{
TBX_RESULT Result;
PTB640_RSP_VP_GROUP_ALLOC pResponse;
PVOIP_VP_GROUP pTargetVpGroup;
PVOIP_VP_GROUP pCurrentVpGroup;
TBX_UINT32 un32ConnectionId;
TBX_UINT32 un32Index;
TBX_UINT64 un64UserContext1;
TBX_UINT32 aun32UserContext1[2];
TBX_CHAR szError[256];
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
pResponse = TBX_MSG_PAYLOAD_POINTER( in_hMsg );
un64UserContext1 = TBX_MSG_USER_CONTEXT1_GET( in_hMsg );
un32ConnectionId = (TBX_UINT32)un64UserContext1;
/* Count this received response */
if( in_pAdapterContext->un32NbResponsesExpected )
{
in_pAdapterContext->un32NbResponsesExpected--;
}
VoipCliAdapterStatePrint
(
in_pAdapterContext,
TRACE_LEVEL_1,
"Allocate voice processing group for connection 0x%08X result is 0x%08X\n",
(int)un32ConnectionId,
(int)pResponse->Result
);
if( TBX_RESULT_FAILURE( pResponse->Result ) )
{
/* Request failed. */
TBX_EXIT_ERROR (pResponse->Result, 0, "Failed to alloc voice processing resource!");
}
if( VOIP_IS_VALID_CONNECTION_ID( un32ConnectionId ) == TBX_FALSE )
{
aun32UserContext1[0] = (TBX_UINT32)(un64UserContext1 >> 32);
aun32UserContext1[1] = (TBX_UINT32)(un64UserContext1);
sprintf(szError, "Retrieved invalid connection identifier from user context (0x%08X%08X)", aun32UserContext1[1], aun32UserContext1[0] );
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PARAM, 0, szError);
}
/* Find the corresponding target voice processing group context */
Result = TBXHashFind
(
in_pAdapterContext->pTargetConfig->hVpGroupHash,
(TBX_HASH_KEY)un32ConnectionId,
(PTBX_VOID*)&pTargetVpGroup
);
if( TBX_RESULT_FAILURE(Result) == TBX_TRUE )
{
TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to find target voice processing group context!");
}
/* Get free voice processing context */
pCurrentVpGroup = TBXPoolOfBuffersAlloc
(
in_pAdapterContext->CurrentConfig.hPoolOfVpGroups,
(TBX_HA
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -