📄 ha.c
字号:
TBX_EXIT_ERROR(result, 0, "Unable to allocate a message buffer");
}
*out_phMsg = hMsg;
/* Erase the payload */
memset (TBX_MSG_PAYLOAD_POINTER(hMsg), 0, TBX_MSG_PAYLOAD_LENGTH_GET(hMsg));
/* Format the message header */
TBX_FORMAT_MSG_HEADER ( \
hMsg, \
un32MsgId, \
TBX_MSG_TYPE_REQUEST, \
un32MsgSize, \
pAdapterInfo->hAdapter, \
0, \
0);
/* Retrieve the pointers */
pGetListMsg = (PTBX_VOID)TBX_MSG_PAYLOAD_POINTER(hMsg);
pGetParamsMsg = (PTBX_VOID)TBX_MSG_PAYLOAD_POINTER(hMsg);
/* Find which message to send */
switch (in_QueryType)
{
case TB640_ISDN_QUERY_TYPE_LIST:
pGetListMsg->Request.un32MsgVersion = 1;
pGetListMsg->Request.hTrunk = hTrunk;
break;
case TB640_ISDN_QUERY_TYPE_PARAMS:
pGetParamsMsg->Request.un32MsgVersion = 1;
pGetParamsMsg->Request.hTrunkRes = hTrunkRes;
break;
default:
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PARAM, 0, "Unknown query type");
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnAdapterTrunkResRetrievedInfo: This function is called by the automatic query function when the params and the state
| of a particular trunk resources has been retrieved.
|
| in_pvAppContext : User-defined context
| in_un32UserContext: Handle of the trunk
| in_hEntity : Handle of the trunk resource
| in_pMsgGetParams: Pointer to the get params response message
| in_pMsgGetState : Pointer to the get states response message
|
| Note : This function will fail if it detects an mismatch between our stored configuration and what was found
| on the adapter.
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640IsdnAdapterTrunkResRetrievedInfo (
IN PTBX_VOID in_pvAppContext,
IN TBX_UINT32 in_un32UserContext,
IN TBX_UINT32 in_hEntity,
IN PTBX_VOID in_pMsgGetParams,
IN PTBX_VOID in_pMsgGetState)
{
TBX_RESULT result;
TBX_UINT32 un32AdapterIdx;
TBX_UINT32 un32OpLibIdx;
PTB640_ISDN_ADAPTER_INFO pAdapterInfo;
TB640_TRUNK_HANDLE hTrunk = (TB640_TRUNK_HANDLE)in_un32UserContext;
TB640_RESOURCE_HANDLE hTrunkRes = (TB640_RESOURCE_HANDLE)in_hEntity;
PTB640_RSP_TRUNK_RES_GET_PARAMS pGetParamsMsg = in_pMsgGetParams;
PTB640_ISDN_TRUNK_INFO pTrunkInfo;
PTB640_ISDN_TRUNK_RESOURCE_INFO pTrunkResInfo;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
/* Retrieve the adapter index and operation lib index */
TB640_ISDN_RETRIEVE_APP_CONTEXT (in_pvAppContext, un32AdapterIdx, un32OpLibIdx);
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapterIdx]);
/* Validate both return values */
if TBX_RESULT_FAILURE(pGetParamsMsg->Result)
{
TBX_EXIT_ERROR (pGetParamsMsg->Result, 0, "get_params refused");
}
/* Retrieve the trunk information structure */
result = TBXHashFind (pAdapterInfo->hTrunkHash, (TBX_HASH_KEY)hTrunk, (PTBX_VOID*)&pTrunkInfo);
if (TBX_RESULT_FAILURE(result))
{
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PARAM, 0, "Unknown trunk handle");
}
/* Validate the trunk resource number */
if (pGetParamsMsg->TrunkResParams.un32TimeSlot >= TB640_ISDN_MAX_TIMESLOT_IN_TRUNK)
{
/* Got an invalid value */
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PARAM, 0, "Invalid timeslot number retrieved");
}
/* Retrieve the trunk resource info */
pTrunkResInfo = &(pTrunkInfo->aResourceInfo [pGetParamsMsg->TrunkResParams.un32TimeSlot]);
/* Remember the new handle */
pTrunkResInfo->hTrunkResource = hTrunkRes;
/* Increment the number of 'allocated' resource */
pTrunkInfo->un32NbTrunkResource++;
/* Check if there is a resouce to allocate on this timeslot */
if (pTrunkInfo->TrunkConfiguration.Type == TB640_TRUNK_TYPE_E1)
{
if (pGetParamsMsg->TrunkResParams.un32TimeSlot == 0)
{
/* This is the framing timeslot.. no resource to allocate here */
pTrunkResInfo->Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_FRAMING_DOWN;
}
else if (pGetParamsMsg->TrunkResParams.un32TimeSlot == 16)
{
/* This is the D-channel timeslot.. no resource to allocate here */
pTrunkResInfo->Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_LINK_DOWN;
}
else
{
pTrunkResInfo->Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_IDLE;
}
}
else
{
if (pGetParamsMsg->TrunkResParams.un32TimeSlot == 0)
{
/* Timeslot 0 is not used by convention */
pTrunkResInfo->Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_FRAMING_DOWN;
}
else if (pGetParamsMsg->TrunkResParams.un32TimeSlot == 24)
{
/* This is the framing timeslot.. no resource to allocate here */
pTrunkResInfo->Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_LINK_DOWN;
}
else
{
pTrunkResInfo->Statistics.State = TB640_ISDN_TRUNK_RESOURCE_STATE_IDLE;
}
}
/* Re-insert into the hash table */
TBXHashInsert (pAdapterInfo->hTrunkResHash, (TBX_HASH_KEY)hTrunkRes, pTrunkResInfo);
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnAdapterResyncTrunkRes: This function is called to re-sync the handle and states of trunk resource. If handles
| are not found, it means the board has been either rebooted or cleared. In that case, we will
| re-allocate the resource.
|
| in_pvAppContext : User-defined context
| in_hTrunk : Trunk on which get the trunk resource
|
| Note : This function will fail if the configuration found on the board does not correspond to what was
| supposed to be there.
|
| Return : No return value
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640IsdnAdapterResyncTrunkRes (
IN PTBX_VOID in_pvAppContext,
IN TB640_TRUNK_HANDLE in_hTrunk)
{
TBX_UINT32 un32AdapterIdx;
TBX_UINT32 un32OpLibIdx;
PTB640_ISDN_ADAPTER_INFO pAdapterInfo;
TBX_RESULT result;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
/* Retrieve the adapter index and operation lib index */
TB640_ISDN_RETRIEVE_APP_CONTEXT (in_pvAppContext, un32AdapterIdx, un32OpLibIdx);
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapterIdx]);
/* Get the list, params and states of trunks loaded in the structure */
result = TB640IsdnAdapterQueryInfo (in_pvAppContext, in_hTrunk, TB640IsdnAdapterTrunkResQueryInfo, TB640IsdnAdapterTrunkResRetrievedInfo);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to resync trunks resources");
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print error message */
TB640_ISDN_LOG (TRACE_LEVEL_ALWAYS, "%s (Result = 0x%08X, %s, line %d)\n", TBX_ERROR_DESCRIPTION, TBX_ERROR_RESULT, __FILE__, TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
| Trunk resync functions
*------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnAdapterTrunkQueryInfo: This function is called by the automatic query function to gather the list, params and
| states of all trunks. This function allocates and formats proper messaging
|
| in_pvAppContext : User-defined context
| in_un32UserContext: User context (not used)
| in_QueryType : Query type (list, get params or get states)
| in_hEntity : Handle of the trunk in case of "get params" or "get states"
| out_phMsg : Pointer to a variable that will hold the allocated message
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640IsdnAdapterTrunkQueryInfo (
IN PTBX_VOID in_pvAppContext,
IN TBX_UINT32 in_un32UserContext,
IN TB640_ISDN_QUERY_TYPE in_QueryType,
IN TBX_UINT32 in_hEntity,
OUT PTBX_MSG_HANDLE out_phMsg)
{
TBX_UINT32 un32AdapterIdx;
TBX_UINT32 un32OpLibIdx;
TBX_UINT32 un32MsgSize;
TBX_UINT32 un32MsgId;
TBX_RESULT result;
TBX_MSG_HANDLE hMsg;
PTB640_ISDN_ADAPTER_INFO pAdapterInfo;
PTB640_MSG_TRUNK_OP_GET_LIST pGetListMsg;
PTB640_MSG_TRUNK_OP_GET_PARAMS pGetParamsMsg;
PTB640_MSG_PMALARMMGR_STATES_GET pGetStatesMsg;
TB640_TRUNK_HANDLE hTrunk = (TB640_TRUNK_HANDLE)in_hEntity;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
/* Retrieve the adapter index and operation lib index */
TB640_ISDN_RETRIEVE_APP_CONTEXT (in_pvAppContext, un32AdapterIdx, un32OpLibIdx);
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapterIdx]);
/* Find which message to send */
switch (in_QueryType)
{
case TB640_ISDN_QUERY_TYPE_LIST:
un32MsgSize = sizeof(*pGetListMsg); un32MsgId = TB640_MSG_ID_TRUNK_OP_GET_LIST; break;
case TB640_ISDN_QUERY_TYPE_PARAMS:
un32MsgSize = sizeof(*pGetParamsMsg); un32MsgId = TB640_MSG_ID_TRUNK_OP_GET_PARAMS; break;
case TB640_ISDN_QUERY_TYPE_STATES:
un32MsgSize = sizeof(*pGetStatesMsg); un32MsgId = TB640_MSG_ID_PMALARMMGR_STATES_GET; break;
default:
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PARAM, 0, "Unknown query type");
}
/* Format the "get list" request */
result = TBXGetMsg (g_AppContext->hTbxLib, un32MsgSize, &hMsg);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to allocate a message buffer");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -