📄 ha.c
字号:
TB640_ISDN_LOG (TRACE_LEVEL_3, "Conflict detection during Ctbus res re-sync of adapter %s.\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
fSyncFailed = TBX_TRUE;
}
}
/* Then, let's resync the stacks */
if (!fSyncFailed)
{
TB640_ISDN_LOG (TRACE_LEVEL_3, "Sync'ing stacks for adapter %s\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
result = TB640IsdnAdapterResyncStack (in_pvAppContext);
if (TBX_RESULT_FAILURE (result))
{
TB640_ISDN_LOG (TRACE_LEVEL_3, "Conflict detection during stacks re-sync of adapter %s.\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
fSyncFailed = TBX_TRUE;
}
}
/* Then, let's resync the connection */
if (!fSyncFailed)
{
TB640_ISDN_LOG (TRACE_LEVEL_3, "Sync'ing connections for adapter %s\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
result = TB640IsdnAdapterResyncConnection (in_pvAppContext);
if (TBX_RESULT_FAILURE (result))
{
TB640_ISDN_LOG (TRACE_LEVEL_3, "Conflict detection during connection re-sync of adapter %s.\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
fSyncFailed = TBX_TRUE;
}
}
/* Then, let's make all call context to update their states */
if (!fSyncFailed)
{
TB640_ISDN_LOG (TRACE_LEVEL_3, "Updating call contexts for adapter %s\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
result = TB640IsdnAdapterUpdateCallContextStates (in_pvAppContext);
if (TBX_RESULT_FAILURE (result))
{
TB640_ISDN_LOG (TRACE_LEVEL_3, "Unable to process re-sync'ed states of adapter %s.\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
fSyncFailed = TBX_TRUE;
}
}
/* Display the result of the sync operation*/
if (fSyncFailed)
{
TB640_ISDN_LOG (TRACE_LEVEL_3, "Sync procedures FAILED for adapter %s.\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
TB640_ISDN_LOG (TRACE_LEVEL_3, "Forcing an adapter REMOVED for adapter %s.\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
/* Force a clean-up (will also wake-up other threads */
TB640IsdnAdapterRemovedHandler (in_pvAppContext, TBX_TRUE);
TB640_ISDN_LOG (TRACE_LEVEL_3, "Forcing an adapter ADDED for adapter %s.\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
/* Send a fake adapter ADDED */
for (un32Count1=0; un32Count1<pAdapterInfo->un32NbOperationLib; un32Count1++)
{
/* Format the fake "adapter removed" event that will toggle the standby procedure */
result = TBXGetMsg (g_AppContext->hTbxLib, sizeof(*pEvtAdapterAdded), &hMsg);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to allocate a message buffer");
}
/* Format the message header */
TBX_FORMAT_MSG_HEADER ( \
hMsg, \
TBX_MSG_ID_API_NOTIF_ADAPTER_ADDED, \
TBX_MSG_TYPE_EVENT, \
sizeof(*pEvtAdapterAdded), \
pAdapterInfo->hAdapter, \
0, \
0);
/* Format the message payload */
pEvtAdapterAdded = (PTBX_EVT_API_NOTIF_ADAPTER_ADDED)TBX_MSG_PAYLOAD_POINTER (hMsg);
pEvtAdapterAdded->Info.hAdapter = pAdapterInfo->hAdapter;
/* Simulate an 'adapter removed' */
result = TBXAsyncInsertManualMsg (pAdapterInfo->ahOperationLib [un32Count1], &hMsg);
if (TBX_RESULT_FAILURE (result))
{
TBX_EXIT_ERROR(result, 0, "Unable to manually insert an event into the async lib");
}
}
}
else
{
TB640_ISDN_LOG (TRACE_LEVEL_3, "Sync procedures completed for adapter %s.\n", pAdapterInfo->szAdapterName);
g_fRefreshDisplay |= (TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH | TB640_ISDN_CLI_REFRESH_DISPLAY);
/* Unlock all other operation lib threads */
for (un32Count1=0; un32Count1<(pAdapterInfo->un32NbOperationLib-1); un32Count1++)
{
TBX_SEM_GIV(pAdapterInfo->AttachOrDetachOpDoneSem);
}
/* Consider this adapter as 'sync'ed' */
pAdapterInfo->fSynced = TBX_TRUE;
}
/* Unlock all remaining operation lib semaphore */
for (un32Count=0; un32Count<pAdapterInfo->un32NbOperationLib; un32Count++)
{
if (un32OpLibIdx != un32Count)
{
TB640IsdnUnlockFromOpLibIdx( pAdapterInfo, un32Count );
}
}
}
/* Refresh the display */
g_fRefreshDisplay |= (TB640_ISDN_CLI_REFRESH_DISPLAY | TB640_ISDN_CLI_CLEAR_BEFORE_REFRESH);
/* 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
{
if (hMsg != NULL)
{
TBXReleaseMsg (g_AppContext->hTbxLib, hMsg);
hMsg = NULL;
}
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnAdapterEthUpHandler: This function is called by the operation library when it detects that a gateway is up
|
| in_pvAppContext : User-defined context
|
| Note : ~
|
| Return : No return value
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT TB640IsdnAdapterEthUpHandler (
IN PTBX_VOID in_pvAppContext)
{
TBX_BOOL fAttached;
TBX_BOOL fAttachFailed;
TBX_UINT32 un32AdapterIdx;
TBX_UINT32 un32OpLibIdx;
TBX_RESULT result;
TBX_MSG_HANDLE hMsg;
PTB640_MSG_ADAPTER_OP_ATTACH pMsg;
PTB640_REQ_ADAPTER_OP_ATTACH pReq;
PTB640_ISDN_ADAPTER_INFO pAdapterInfo;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
hMsg = NULL;
fAttachFailed = TBX_FALSE;
/* Retrieve the adapter index and operation lib index */
TB640_ISDN_RETRIEVE_APP_CONTEXT (in_pvAppContext, un32AdapterIdx, un32OpLibIdx);
pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32AdapterIdx]);
/* Check if the adapter is up */
TBX_SEM_GET(pAdapterInfo->AdapterSem, TBX_SEM_WAIT_FOREVER);
fAttached = pAdapterInfo->fAttached;
TBX_SEM_GIV(pAdapterInfo->AdapterSem);
/*
* Send an ATTACH only if we are not in the state 'adapter down' to prevent the case where the board has seen
* an adapter down but not the hostlib.
*/
if (fAttached)
{
/* Format the "attach" request */
result = TBXGetMsg (g_AppContext->hTbxLib, sizeof(*pMsg), &hMsg);
if (TBX_RESULT_FAILURE (result))
{
TB640_ISDN_LOG (TRACE_LEVEL_3, "Unable to allocate attach request to adapter %s.\n", pAdapterInfo->szAdapterName);
fAttachFailed = TBX_TRUE;
}
/* Send the attach request to the newly discovered adapter */
if (!fAttachFailed)
{
/* Format the message header */
TBX_FORMAT_MSG_HEADER ( \
hMsg, \
TB640_MSG_ID_ADAPTER_OP_ATTACH, \
TBX_MSG_TYPE_REQUEST, \
sizeof(*pMsg), \
pAdapterInfo->hAdapter, \
0, \
0);
/* Format the message payload */
pMsg = (PTB640_MSG_ADAPTER_OP_ATTACH)TBX_MSG_PAYLOAD_POINTER (hMsg);
pReq = &(pMsg->Request);
pReq->un32MsgVersion = 1;
pReq->fEnableAutoReattach = TBX_TRUE;
/* Send the message */
result = TBXSendMsg (g_AppContext->hTbxLib, hMsg, NULL);
hMsg = NULL;
if (TBX_RESULT_FAILURE(result))
{
TB640_ISDN_LOG (TRACE_LEVEL_3, "Unable to send attach request to adapter %s.\n", pAdapterInfo->szAdapterName);
}
}
}
/* 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 resource resync functions
*------------------------------------------------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------------------------------------------------
|
| TB640IsdnAdapterTrunkResQueryInfo: This function is called by the automatic query function to gather the list, params and
| states of all trunk resources for one trunk. This function allocates and formats proper
| messaging
|
| in_pvAppContext : User-defined context
| in_un32UserContext: Handle of the trunk
| in_QueryType : Query type (list, get params or get states)
| in_hEntity : Handle of the trunk resource 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 TB640IsdnAdapterTrunkResQueryInfo (
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_RES_GET_LIST pGetListMsg;
PTB640_MSG_TRUNK_RES_GET_PARAMS pGetParamsMsg;
TB640_TRUNK_HANDLE hTrunk = (TB640_TRUNK_HANDLE)in_un32UserContext;
TB640_RESOURCE_HANDLE hTrunkRes = (TB640_RESOURCE_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_RES_GET_LIST; break;
case TB640_ISDN_QUERY_TYPE_PARAMS:
un32MsgSize = sizeof(*pGetParamsMsg); un32MsgId = TB640_MSG_ID_TRUNK_RES_GET_PARAMS; break;
case TB640_ISDN_QUERY_TYPE_STATES:
un32MsgSize = 0; un32MsgId = 0; break;
default:
TBX_EXIT_ERROR (TBX_RESULT_INVALID_PARAM, 0, "Unknown query type");
}
/* Some actions are not allowed on trunk resources */
if (un32MsgSize == 0)
{
*out_phMsg = NULL;
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/* Format the "get list" request */
result = TBXGetMsg (g_AppContext->hTbxLib, un32MsgSize, &hMsg);
if (TBX_RESULT_FAILURE (result))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -