📄 voip_adapter_alloc.c
字号:
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterAllocSubState2 : Compares the Target configuration of the adapter with
| its Current configuration, and allocates all resources that
| don't match the Current configuration (second step).
|
| in_pAdapterContext : Adapter we are configuring
|
| Note : ~
|
| Return : TBX_RESULT_OK if the function succeeded
| Other error code if the function could not complete properly.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipAdapterAllocSubState2(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext)
{
TBX_RESULT Result;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
Result = TBX_RESULT_OK;
/*
* Allocate trunk resources
*/
{
TBX_UINT32 un32TrunkNb;
TBX_UINT32 un32TimeSlotNb;
PVOIP_TRUNK_CONFIG pCurrentTrunkConfig;
PVOIP_TRUNK_CONFIG pTargetTrunkConfig;
PVOIP_TRUNK_RES pCurrentTrunkRes;
for( un32TrunkNb = 0; un32TrunkNb < VOIP_MAX_TRUNK_PER_ADAPTER; un32TrunkNb++ )
{
pCurrentTrunkConfig = &in_pAdapterContext->CurrentConfig.aTrunk[ un32TrunkNb ];
pTargetTrunkConfig = &in_pAdapterContext->pTargetConfig->aTrunk[ un32TrunkNb ];
if( pCurrentTrunkConfig->fAllocated == TBX_TRUE )
{
for( un32TimeSlotNb = 1; un32TimeSlotNb < (pCurrentTrunkConfig->un32MaxTimeSlot + 1); un32TimeSlotNb++ )
{
pCurrentTrunkRes = &pCurrentTrunkConfig->aRes[ un32TimeSlotNb ];
if( pCurrentTrunkRes->Common.fAllocated == TBX_FALSE )
{
/* Allocate the configuration for this trunk (that function will allocate it if not already done) */
Result = VoipSendAdapterTrunkResAlloc(
in_pAdapterContext,
pTargetTrunkConfig,
un32TimeSlotNb);
if( TBX_RESULT_FAILURE( Result ) )
{
TBX_EXIT_ERROR (Result, 0, "Failed to allocate trunk resource");
}
}
}
}
}
}
/*
* Allocate MBL port resources
*/
{
TBX_UINT32 un32PortNb;
TBX_UINT32 un32StreamNb;
TBX_UINT32 un32TimeSlotNb;
PVOIP_MBL_PORT_CONFIG pCurrentMblPortConfig;
PVOIP_MBL_PORT_CONFIG pTargetMblPortConfig;
PVOIP_MBL_RES pCurrentMblPortRes;
for( un32PortNb = 0; un32PortNb < VOIP_MAX_MBL_PORT_PER_ADAPTER; un32PortNb++ )
{
pCurrentMblPortConfig = &in_pAdapterContext->CurrentConfig.aMblPort[ un32PortNb ];
pTargetMblPortConfig = &in_pAdapterContext->pTargetConfig->aMblPort[ un32PortNb ];
if( pCurrentMblPortConfig->fAllocated == TBX_TRUE )
{
for( un32StreamNb = 0; un32StreamNb < VOIP_MAX_STREAM_PER_MBL_PORT; un32StreamNb++ )
{
for( un32TimeSlotNb = 0; un32TimeSlotNb < VOIP_MAX_TIMESLOT_PER_MBL_STREAM; un32TimeSlotNb++ )
{
pCurrentMblPortRes = &pCurrentMblPortConfig->aRes[ un32StreamNb ] [ un32TimeSlotNb ];
if( pCurrentMblPortRes->Common.fAllocated == TBX_FALSE )
{
/* Allocate the configuration for this MBL port (that function will allocate it if not already done) */
Result = VoipSendAdapterMblPortResAlloc(
in_pAdapterContext,
pTargetMblPortConfig,
un32StreamNb,
un32TimeSlotNb);
if( TBX_RESULT_FAILURE( Result ) )
{
TBX_EXIT_ERROR (Result, 0, "Failed to allocate MBL resource");
}
}
}
}
}
}
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
VoipCliAdapterStatePrint(
in_pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipAdapterAllocSubState2: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterAllocSubState3 : Compares the Target configuration of the adapter with
| its Current configuration, and allocates all resources that
| don't match the Current configuration (third step).
|
| in_pAdapterContext : Adapter we are configuring
|
| Note : ~
|
| Return : TBX_RESULT_OK if the function succeeded
| Other error code if the function could not complete properly.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipAdapterAllocSubState3(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext)
{
TBX_RESULT Result;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
Result = TBX_RESULT_OK;
/*
* Allocate connections
*/
{
PVOIP_CONNECTION_CONTEXT pCurrentConnectionContext;
PVOIP_CONNECTION_CONTEXT pTargetConnectionContext;
pTargetConnectionContext = TBXPoolOfBuffersFirst( in_pAdapterContext->pTargetConfig->hPoolOfConnections );
while( pTargetConnectionContext )
{
if( pTargetConnectionContext->fAllocated == TBX_TRUE )
{
/* Find the corresponding current connection context */
Result = TBXHashFind
(
in_pAdapterContext->CurrentConfig.hConnectionHash,
(TBX_HASH_KEY)pTargetConnectionContext->un32ConnectionId,
(PTBX_VOID*)&pCurrentConnectionContext
);
if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
{
/*
* Allocate the connection context
*/
Result = VoipSendAdapterConnectionAlloc(
in_pAdapterContext,
pTargetConnectionContext);
if( TBX_RESULT_FAILURE( Result ) )
{
TBX_EXIT_ERROR (Result, 0, "Failed to allocate connection context");
}
}
}
pTargetConnectionContext = TBXPoolOfBuffersNext( in_pAdapterContext->pTargetConfig->hPoolOfConnections, pTargetConnectionContext );
}
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
VoipCliAdapterStatePrint(
in_pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipAdapterAllocSubState3: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterPromptAlloc : Allocates a prompt for this adapter.
|
| in_pAdapterContext : Adapter configuration we are configuring
| in_pTargetPromptContext : Target prompt to allocate
|
| Note : ~
|
| Return : TBX_RESULT_OK if the function succeeded
| Other error code if the function could not complete properly.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipAdapterPromptAlloc(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext,
IN PVOIP_PROMPT_CONTEXT in_pTargetPromptContext)
{
TBX_RESULT Result;
PVOIP_PROMPT_CONTEXT pCurrentPromptContext;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
if( in_pAdapterContext->fStopUsingPending )
{
/* We must not use this adapter anymore (stop using). Don't send request. */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
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 (TBX_RESULT_OK);
}
VoipCliAdapterStatePrint
(
in_pAdapterContext,
TRACE_LEVEL_1,
"Allocating prompt %s\n",
in_pTargetPromptContext->Params.szPromptName
);
/* Get free prompt context */
pCurrentPromptContext = TBXPoolOfBuffersAlloc
(
in_pAdapterContext->CurrentConfig.hPoolOfPrompts,
(TBX_HASH_KEY)in_pTargetPromptContext->un32ConnectionId
);
if( pCurrentPromptContext == NULL )
{
TBX_EXIT_ERROR (TBX_RESULT_NOT_FOUND, 0, "Failed to allocate element from pool of prompt buffers.");
}
/* Insert prompt context in hash table of prompt names */
Result = TBXHashInsert
(
in_pAdapterContext->CurrentConfig.hPromptNameHash,
(TBX_HASH_KEY)in_pTargetPromptContext->Params.szPromptName,
pCurrentPromptContext
);
if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
{
TBX_EXIT_ERROR (Result, 0, "Failed to insert element in prompt name hash table.");
}
/* Allocate and initialize our "current" context. (config will be copied later in file "voip_adapter_set.c") */
pCurrentPromptContext->fAllocated = TBX_TRUE;
pCurrentPromptContext->un32ConnectionId = in_pTargetPromptContext->un32ConnectionId;
pCurrentPromptContext->Params = in_pTargetPromptContext->Params;
/* Allocate stream server prompt context */
Result = VoipStreamServerPromptAlloc(
pCurrentPromptContext->Params.un16RxIPPort,
in_pAdapterContext->AdapterInfo.szIpAddress0,
pCurrentPromptContext->Params.szPathName,
&pCurrentPromptContext->un32StreamServerPromptId,
pCurrentPromptContext->Params.un32NbRepeat);
if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
{
TBX_EXIT_ERROR (Result, 0, "Failed to allocate stream server prompt.");
}
/* Start playing prompt */
Result = VoipStreamServerStartPlay(
pCurrentPromptContext->un32StreamServerPromptId );
if( TBX_RESULT_FAILURE( Result ) )
{
TBX_EXIT_ERROR (Result, 0, "Failed to start playing prompt");
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
VoipCliAdapterStatePrint(
in_pAdapterContext,
TRACE_LEVEL_ERROR,
"VoipAdapterPromptAlloc: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterRawDataFileAlloc : Allocates a raw data file for this adapter.
|
| in_pAdapterContext : Adapter configuration we are configuring
| in_pTargetRawDataFileContext : Target raw data file to allocate
|
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -