📄 voip_config.c
字号:
TBX_HASH_KEY VoipConnectionGetKey(
IN PTBX_VOID in_pUserContext,
IN PTBX_VOID in_pConnectionContext)
{
(TBX_VOID)in_pUserContext;
return (TBX_HASH_KEY)( ((PVOIP_CONNECTION_CONTEXT)in_pConnectionContext)->un32ConnectionId );
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipStreamResGetKey : Function to get hash key from pointer to stream resource context.
| The Hash table hash key is the connection identifier.
|
| in_pStreamRes : Pointer to stream resource context
| (cast to PVOIP_STREAM_RES)
|
| Note : ~
|
| Return : Hash key associated with connection identifier.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_HASH_KEY VoipStreamResGetKey(
IN PTBX_VOID in_pUserContext,
IN PTBX_VOID in_pStreamRes)
{
(TBX_VOID)in_pUserContext;
return (TBX_HASH_KEY)( ( (PVOIP_STREAM_RES)in_pStreamRes )->Common.un32ConnectionId );
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipVpGroupGetKey : Function to get hash key from pointer to voice processing group context.
| The Hash table hash key is the connection identifier.
|
| in_pVpGroup : Pointer to voice processing context
| (cast to PVOIP_VP_GROUP)
|
| Note : ~
|
| Return : Hash key associated with voice processing group identifier.
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_HASH_KEY VoipVpGroupGetKey(
IN PTBX_VOID in_pUserContext,
IN PTBX_VOID in_pVpGroup)
{
(TBX_VOID)in_pUserContext;
return (TBX_HASH_KEY)( ( (PVOIP_VP_GROUP)in_pVpGroup )->Common.un32ConnectionId );
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterAllocConfig : Allocate all hash tables and data structures to store
| the information on an adapter configuration
|
| in_pAdapterConfig : Adapter configuration to allocate
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipAdapterAllocConfig(
IN PVOIP_ADAPTER_CONFIG in_pAdapterConfig)
{
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
/* Allocate the hash table to retrieve trunk config from trunk name */
in_pAdapterConfig->hTrunkNameHash = TBXHashCreateWithString
(
VOIP_MAX_TRUNK_PER_ADAPTER,
VoipTrunkNameGetKey,
NULL
);
if( in_pAdapterConfig->hTrunkNameHash == (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate hash of trunk configs by name.");
}
TBXHashSetCreateFileLine( in_pAdapterConfig->hTrunkNameHash, __FILE__, __LINE__ );
/* Allocate the hash table to retrieve MBL port config from MBL port name */
in_pAdapterConfig->hMblPortNameHash = TBXHashCreateWithString
(
VOIP_MAX_MBL_PORT_PER_ADAPTER,
VoipMblPortNameGetKey,
NULL
);
if( in_pAdapterConfig->hMblPortNameHash == (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate hash of MBL port configs by name.");
}
TBXHashSetCreateFileLine( in_pAdapterConfig->hMblPortNameHash, __FILE__, __LINE__ );
/* Allocate the hash table to retrieve resource context from resource handle */
in_pAdapterConfig->hResHandleHash = TBXHashCreate(
VOIP_MAX_RES_PER_ADAPTER,
VoipResHandleGetKey,
NULL);
if( in_pAdapterConfig->hResHandleHash == (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate hash of resource context by handle.");
}
TBXHashSetCreateFileLine( in_pAdapterConfig->hResHandleHash, __FILE__, __LINE__ );
/* Allocate the pool of stream resource contexts */
in_pAdapterConfig->hPoolOfStreamRes = TBXPoolOfBuffersCreate
(
VOIP_MAX_STREAM_RES,
sizeof(VOIP_STREAM_RES),
NULL,
NULL,
TBX_FALSE
);
if( in_pAdapterConfig->hPoolOfStreamRes == (TBX_POOL_OF_BUFFERS_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate pool of stream resource contexts.");
}
TBXPoolOfBuffersSetCreateFileLine( in_pAdapterConfig->hPoolOfStreamRes, __FILE__, __LINE__ );
/* Allocate the pool of voice processing group contexts */
in_pAdapterConfig->hPoolOfVpGroups = TBXPoolOfBuffersCreate
(
VOIP_MAX_VP_GROUP,
sizeof(VOIP_VP_GROUP),
NULL,
NULL,
TBX_FALSE
);
if( in_pAdapterConfig->hPoolOfVpGroups == (TBX_POOL_OF_BUFFERS_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate pool of voice processing group contexts.");
}
TBXPoolOfBuffersSetCreateFileLine( in_pAdapterConfig->hPoolOfVpGroups, __FILE__, __LINE__ );
/* Allocate the pool of connection contexts */
in_pAdapterConfig->hPoolOfConnections = TBXPoolOfBuffersCreate
(
VOIP_MAX_CONNECTION_PER_ADAPTER,
sizeof(VOIP_CONNECTION_CONTEXT),
NULL,
NULL,
TBX_FALSE
);
if( in_pAdapterConfig->hPoolOfConnections == (TBX_POOL_OF_BUFFERS_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate pool of connection contexts.");
}
TBXPoolOfBuffersSetCreateFileLine( in_pAdapterConfig->hPoolOfConnections, __FILE__, __LINE__ );
/* Allocate the hash table to retrieve connection context from connection identifier */
in_pAdapterConfig->hConnectionHash = TBXHashCreate(
VOIP_MAX_CONNECTION_PER_ADAPTER,
VoipConnectionGetKey,
NULL);
if( in_pAdapterConfig->hConnectionHash == (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate hash of connection context by connection identifier.");
}
TBXHashSetCreateFileLine( in_pAdapterConfig->hConnectionHash, __FILE__, __LINE__ );
/* Allocate the hash table to retrieve stream resource context from connection identifier */
in_pAdapterConfig->hStreamResHash = TBXHashCreate(
VOIP_MAX_STREAM_RES,
VoipStreamResGetKey,
NULL);
if( in_pAdapterConfig->hStreamResHash == (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate hash of stream resource context by connection identifier.");
}
TBXHashSetCreateFileLine( in_pAdapterConfig->hStreamResHash, __FILE__, __LINE__ );
/* Allocate the hash table to retrieve voice processing group context from connection identifier */
in_pAdapterConfig->hVpGroupHash = TBXHashCreate(
VOIP_MAX_STREAM_RES,
VoipVpGroupGetKey,
NULL);
if( in_pAdapterConfig->hVpGroupHash == (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate hash of voice processing group context by connection identifier.");
}
TBXHashSetCreateFileLine( in_pAdapterConfig->hVpGroupHash, __FILE__, __LINE__ );
/* Allocate the pool of prompt contexts */
in_pAdapterConfig->hPoolOfPrompts = TBXPoolOfBuffersCreate
(
VOIP_MAX_PROMPTS,
sizeof(VOIP_PROMPT_CONTEXT),
VoipPromptContextGetKey,
NULL,
TBX_FALSE
);
if( in_pAdapterConfig->hPoolOfPrompts == (TBX_POOL_OF_BUFFERS_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate pool of prompt contexts.");
}
TBXPoolOfBuffersSetCreateFileLine( in_pAdapterConfig->hPoolOfPrompts, __FILE__, __LINE__ );
/* Allocate the pool of raw data file contexts */
in_pAdapterConfig->hPoolOfRawDataFiles = TBXPoolOfBuffersCreate
(
VOIP_MAX_RAW_DATA_FILES,
sizeof(VOIP_RAW_DATA_FILE_CONTEXT),
VoipRawDataFileContextGetKey,
NULL,
TBX_FALSE
);
if( in_pAdapterConfig->hPoolOfRawDataFiles == (TBX_POOL_OF_BUFFERS_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate pool of raw data file contexts.");
}
TBXPoolOfBuffersSetCreateFileLine( in_pAdapterConfig->hPoolOfRawDataFiles, __FILE__, __LINE__ );
/* Allocate the hash table to retrieve prompt context from prompt name */
in_pAdapterConfig->hPromptNameHash = TBXHashCreateWithString
(
VOIP_MAX_PROMPTS,
VoipPromptNameGetKey,
NULL
);
if( in_pAdapterConfig->hPromptNameHash == (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate hash of prompt contexts by name.");
}
TBXHashSetCreateFileLine( in_pAdapterConfig->hPromptNameHash, __FILE__, __LINE__ );
/* Allocate the hash table to retrieve raw data file context from raw data file name */
in_pAdapterConfig->hRawDataFileNameHash = TBXHashCreateWithString
(
VOIP_MAX_RAW_DATA_FILES,
VoipRawDataFileNameGetKey,
NULL
);
if( in_pAdapterConfig->hRawDataFileNameHash == (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate hash of raw data file contexts by name.");
}
TBXHashSetCreateFileLine( in_pAdapterConfig->hRawDataFileNameHash, __FILE__, __LINE__ );
/* Allocate the hash table to retrieve raw data file context from raw data file name */
in_pAdapterConfig->hRawDataFileIdHash64 = TBXHash64Create
(
VOIP_MAX_RAW_DATA_FILES,
VoipRawDataFileIdGetKey,
NULL
);
if( in_pAdapterConfig->hRawDataFileIdHash64 == (TBX_HASH_64_HANDLE)TBX_HANDLE_INVALID )
{
TBX_EXIT_ERROR (TBX_RESULT_OUT_OF_MEMORY, 0, "Failed to allocate hash of raw data file contexts by id.");
}
TBXHash64SetCreateFileLine( in_pAdapterConfig->hRawDataFileIdHash64, __FILE__, __LINE__ );
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
in_pAdapterConfig->fAllocated = TBX_TRUE;
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipAdapterClearConfig : Clear the configuration structure.
|
| in_pAdapterConfig : Adapter configuration to free
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipAdapterClearConfig(
IN PVOIP_ADAPTER_CONFIG in_pAdapterConfig)
{
/* Free the hash table of MBL port names */
if( in_pAdapterConfig->hMblPortNameHash != (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBXHashDestroy( in_pAdapterConfig->hMblPortNameHash );
in_pAdapterConfig->hMblPortNameHash = (TBX_HASH_HANDLE)TBX_HANDLE_INVALID;
}
/* Free the hash table of trunk names */
if( in_pAdapterConfig->hTrunkNameHash != (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBXHashDestroy( in_pAdapterConfig->hTrunkNameHash );
in_pAdapterConfig->hTrunkNameHash = (TBX_HASH_HANDLE)TBX_HANDLE_INVALID;
}
/* Free the hash table of resource handles */
if( in_pAdapterConfig->hResHandleHash != (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBXHashDestroy( in_pAdapterConfig->hResHandleHash );
in_pAdapterConfig->hResHandleHash = (TBX_HASH_HANDLE)TBX_HANDLE_INVALID;
}
/* Free the pool of stream resource contexts */
TBXPoolOfBuffersDestroy( in_pAdapterConfig->hPoolOfStreamRes );
in_pAdapterConfig->hPoolOfStreamRes = (TBX_POOL_OF_BUFFERS_HANDLE)TBX_HANDLE_INVALID;
/* Free the pool of voice processing group contexts */
TBXPoolOfBuffersDestroy( in_pAdapterConfig->hPoolOfVpGroups );
in_pAdapterConfig->hPoolOfVpGroups = (TBX_POOL_OF_BUFFERS_HANDLE)TBX_HANDLE_INVALID;
/* Free the pool of connection contexts */
TBXPoolOfBuffersDestroy( in_pAdapterConfig->hPoolOfConnections );
in_pAdapterConfig->hPoolOfConnections = (TBX_POOL_OF_BUFFERS_HANDLE)TBX_HANDLE_INVALID;
/* Free the hash table of connection contexts */
if( in_pAdapterConfig->hConnectionHash != (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBXHashDestroy( in_pAdapterConfig->hConnectionHash );
in_pAdapterConfig->hConnectionHash = (TBX_HASH_HANDLE)TBX_HANDLE_INVALID;
}
/* Free the hash table of stream resource contexts */
if( in_pAdapterConfig->hStreamResHash != (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBXHashDestroy( in_pAdapterConfig->hStreamResHash );
in_pAdapterConfig->hStreamResHash = (TBX_HASH_HANDLE)TBX_HANDLE_INVALID;
}
/* Free the hash table of voice processing group contexts */
if( in_pAdapterConfig->hVpGroupHash != (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBXHashDestroy( in_pAdapterConfig->hVpGroupHash );
in_pAdapterConfig->hVpGroupHash = (TBX_HASH_HANDLE)TBX_HANDLE_INVALID;
}
/* Destroy the pool of raw data file contexts */
if( in_pAdapterConfig->hPoolOfRawDataFiles != TBX_HANDLE_INVALID )
{
TBXPoolOfBuffersDestroy( in_pAdapterConfig->hPoolOfRawDataFiles );
in_pAdapterConfig->hPoolOfRawDataFiles = TBX_HANDLE_INVALID;
}
/* Destroy the pool of prompt contexts */
if( in_pAdapterConfig->hPoolOfPrompts != TBX_HANDLE_INVALID )
{
TBXPoolOfBuffersDestroy( in_pAdapterConfig->hPoolOfPrompts );
in_pAdapterConfig->hPoolOfPrompts = TBX_HANDLE_INVALID;
}
/* Free the hash table of raw data file ids */
if( in_pAdapterConfig->hRawDataFileIdHash64 != (TBX_HASH_64_HANDLE)TBX_HANDLE_INVALID )
{
TBXHash64Destroy( in_pAdapterConfig->hRawDataFileIdHash64 );
in_pAdapterConfig->hRawDataFileIdHash64 = (TBX_HASH_64_HANDLE)TBX_HANDLE_INVALID;
}
/* Free the hash table of raw data file names */
if( in_pAdapterConfig->hRawDataFileNameHash != (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBXHashDestroy( in_pAdapterConfig->hRawDataFileNameHash );
in_pAdapterConfig->hRawDataFileNameHash = (TBX_HASH_HANDLE)TBX_HANDLE_INVALID;
}
/* Free the hash table of prompt names */
if( in_pAdapterConfig->hPromptNameHash != (TBX_HASH_HANDLE)TBX_HANDLE_INVALID )
{
TBXHashDestroy( in_pAdapterConfig->hPromptNameHash );
in_pAdapterConfig->hPromptNameHash = (TBX_HASH_HANDLE)TBX_HANDLE_INVALID;
}
/* Memset everything else to 0 */
memset( in_pAdapterConfig, 0, sizeof(*in_pAdapterConfig) );
return TBX_RESULT_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -