📄 tone.c
字号:
TBX_EXIT_ERROR (Result, 0, "ToneVpGrpFree Failed");
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print the error to the user */
fprintf (stderr, "%s\n", TBX_ERROR_DESCRIPTION);
ValidateErrorCode (Result, in_hAdapter, in_hLib);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| ToneTrunkResAllocate : Allocates a trunk resource
|
| in_hLib : Handle to the TBX library returned by TBXOpenLib()
| in_hAdapter : Handle to an adapter that was previously selected and attached to by SelectAdapter()
| in_hTrunk : Trunk on which to allocate a timeslot
| in_un32TimeSlot : Timeslot to Allocate
| out_phRes : returned Trunk resource
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
| or others
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT ToneTrunkResAllocate (
IN TBX_LIB_HANDLE in_hLib,
IN TBX_ADAPTER_HANDLE in_hAdapter,
IN TB640_TRUNK_HANDLE in_hTrunk,
IN TBX_UINT32 in_un32TimeSlot,
OUT PTB640_RESOURCE_HANDLE out_phRes )
{
TBX_RESULT_API Result;
PTB640_MSG_TRUNK_RES_ALLOC pMsgTrunkResAlloc;
TBX_MSG_HANDLE hMsg;
TBX_FILTER_HANDLE hFilter;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Get a message buffer */
Result = TBXGetMsg (in_hLib, sizeof(*pMsgTrunkResAlloc), &hMsg);
if (TBX_RESULT_SUCCESS (Result))
{
/* Clear the buffer... */
memset (TBX_MSG_PAYLOAD_POINTER (hMsg), 0, TBX_MSG_PAYLOAD_MAX_LENGTH_GET (hMsg));
/* Set the message header */
TBX_FORMAT_MSG_HEADER (
hMsg,
TB640_MSG_ID_TRUNK_RES_ALLOC,
TBX_MSG_TYPE_REQUEST,
sizeof(*pMsgTrunkResAlloc),
in_hAdapter,
0,
0);
/* Fill the request */
pMsgTrunkResAlloc = TBX_MSG_PAYLOAD_POINTER (hMsg);
pMsgTrunkResAlloc->Request.un32MsgVersion = 1;
pMsgTrunkResAlloc->Request.TrunkResParams.un32StructVersion = 1;
pMsgTrunkResAlloc->Request.TrunkResParams.ChannelRate = TB640_RESOURCE_CHANNEL_RATE_64KBPS;
pMsgTrunkResAlloc->Request.TrunkResParams.hTrunk = in_hTrunk;
pMsgTrunkResAlloc->Request.TrunkResParams.ResType = TB640_RESDEF_TYPE_FD;
pMsgTrunkResAlloc->Request.TrunkResParams.un32Channel = 0;
pMsgTrunkResAlloc->Request.TrunkResParams.un32TimeSlot= in_un32TimeSlot;
/* Send the request */
Result = TBXSendMsg (in_hLib, hMsg, &hFilter);
hMsg = TBX_HANDLE_INVALID;
if (TBX_RESULT_SUCCESS (Result))
{
pMsgTrunkResAlloc = NULL;
/* Wait for the response synchronously */
Result = TBXReceiveMsg (in_hLib, hFilter, TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
if (TBX_RESULT_SUCCESS (Result))
{
/* We got the response */
pMsgTrunkResAlloc = TBX_MSG_PAYLOAD_POINTER (hMsg);
Result = pMsgTrunkResAlloc->Response.Result;
*out_phRes = pMsgTrunkResAlloc->Response.hTrunkRes;
}
}
/* Release the filter */
if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
{
TBXDestroyMsgFilter (in_hLib, hFilter);
hFilter = TBX_HANDLE_INVALID;
}
}
/* Free the message buffer */
if (hMsg != TBX_HANDLE_INVALID)
{
/* Free the message */
TBXReleaseMsg (in_hLib, hMsg);
hMsg = TBX_HANDLE_INVALID;
}
/* Was there an error along in the process ? */
if (TBX_RESULT_FAILURE (Result))
{
TBX_EXIT_ERROR (Result, 0, "TrunkResAllocate Failed");
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print the error to the user */
fprintf (stderr, "%s\n", TBX_ERROR_DESCRIPTION);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| ToneTrunkResFree : Free a trunk resource
|
| in_hLib : Handle to the TBX library returned by TBXOpenLib()
| in_hAdapter : Handle to an adapter that was previously selected and attached to by SelectAdapter()
| in_hRes : Trunk resource to free
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
| or others
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT ToneTrunkResFree (
IN TBX_LIB_HANDLE in_hLib,
IN TBX_ADAPTER_HANDLE in_hAdapter,
IN TB640_RESOURCE_HANDLE in_hRes )
{
TBX_RESULT_API Result;
PTB640_MSG_TRUNK_RES_FREE pMsgTrunkResFree;
TBX_MSG_HANDLE hMsg;
TBX_FILTER_HANDLE hFilter;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Get a message buffer */
Result = TBXGetMsg (in_hLib, sizeof(*pMsgTrunkResFree), &hMsg);
if (TBX_RESULT_SUCCESS (Result))
{
/* Clear the buffer... */
memset (TBX_MSG_PAYLOAD_POINTER (hMsg), 0, TBX_MSG_PAYLOAD_MAX_LENGTH_GET (hMsg));
/* Set the message header */
TBX_FORMAT_MSG_HEADER (
hMsg,
TB640_MSG_ID_TRUNK_RES_FREE,
TBX_MSG_TYPE_REQUEST,
sizeof(*pMsgTrunkResFree),
in_hAdapter,
0,
0);
/* Fill the request */
pMsgTrunkResFree = TBX_MSG_PAYLOAD_POINTER (hMsg);
pMsgTrunkResFree->Request.un32MsgVersion = 1;
pMsgTrunkResFree->Request.hTrunkRes = in_hRes;
/* Send the request */
Result = TBXSendMsg (in_hLib, hMsg, &hFilter);
hMsg = TBX_HANDLE_INVALID;
if (TBX_RESULT_SUCCESS (Result))
{
pMsgTrunkResFree = NULL;
/* Wait for the response synchronously */
Result = TBXReceiveMsg (in_hLib, hFilter, TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
if (TBX_RESULT_SUCCESS (Result))
{
/* We got the response */
pMsgTrunkResFree = TBX_MSG_PAYLOAD_POINTER (hMsg);
Result = pMsgTrunkResFree->Response.Result;
}
}
/* Release the filter */
if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
{
TBXDestroyMsgFilter (in_hLib, hFilter);
hFilter = TBX_HANDLE_INVALID;
}
}
/* Free the message buffer */
if (hMsg != TBX_HANDLE_INVALID)
{
/* Free the message */
TBXReleaseMsg (in_hLib, hMsg);
hMsg = TBX_HANDLE_INVALID;
}
/* Was there an error along in the process ? */
if (TBX_RESULT_FAILURE (Result))
{
TBX_EXIT_ERROR (Result, 0, "TrunkResAllocate Failed");
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
/* Print the error to the user */
fprintf (stderr, "%s\n", TBX_ERROR_DESCRIPTION);
ValidateErrorCode (Result, in_hAdapter, in_hLib);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| ToneConnect : Connects two resource half duplex
|
| in_hLib : Handle to the TBX library returned by TBXOpenLib()
| in_hAdapter : Handle to an adapter that was previously selected and attached to by SelectAdapter()
| in_hSrc : Source resource
| in_hDst : Destination resource
| out_phConn : Returned Connection handle
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
| or others
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT ToneConnect(
IN TBX_LIB_HANDLE in_hLib,
IN TBX_ADAPTER_HANDLE in_hAdapter,
IN TB640_RESOURCE_HANDLE in_hSrc,
IN TB640_RESOURCE_HANDLE in_hDst,
OUT PTB640_CONNECTION_HANDLE out_phConn )
{
TBX_RESULT_API Result;
PTB640_MSG_CONN_OP_CREATE pMsgConCreate;
PTB640_PATH_DESCRIPTION pPathDesc;
TBX_MSG_HANDLE hMsg;
TBX_FILTER_HANDLE hFilter;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Get a message buffer */
Result = TBXGetMsg (in_hLib, sizeof(*pMsgConCreate), &hMsg);
if (TBX_RESULT_SUCCESS (Result))
{
/* Clear the buffer... */
memset (TBX_MSG_PAYLOAD_POINTER (hMsg), 0, TBX_MSG_PAYLOAD_MAX_LENGTH_GET (hMsg));
/* Set the message header */
TBX_FORMAT_MSG_HEADER (
hMsg,
TB640_MSG_ID_CONN_OP_CREATE,
TBX_MSG_TYPE_REQUEST,
sizeof(*pMsgConCreate),
in_hAdapter,
0,
0);
/* Fill the request */
pMsgConCreate = TBX_MSG_PAYLOAD_POINTER (hMsg);
pMsgConCreate->Request.un32MsgVersion = 1;
pMsgConCreate->Request.un32PathDescCount = 1;
pMsgConCreate->Request.un64UserContext1 = 0;
pMsgConCreate->Request.un64UserContext2 = 0;
pPathDesc = &pMsgConCreate->Request.aPathDesc[0];
pPathDesc->un32StructVersion = 1;
pPathDesc->fFullDuplex = TBX_FALSE;
pPathDesc->hResSrc = in_hSrc;
pPathDesc->hResDst = in_hDst;
/* Send the request */
Result = TBXSendMsg (in_hLib, hMsg, &hFilter);
hMsg = TBX_HANDLE_INVALID;
if (TBX_RESULT_SUCCESS (Result))
{
pMsgConCreate = NULL;
/* Wait for the response synchronously */
Result = TBXReceiveMsg (in_hLib, hFilter, TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
if (TBX_RESULT_SUCCESS (Result))
{
/* We got the response */
pMsgConCreate = TBX_MSG_PAYLOAD_POINTER (hMsg);
Result = pMsgConCreate->Response.Result;
*out_phConn = pMsgConCreate->Response.hConn;
}
}
/* Release the filter */
if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
{
TBXDestroyMsgFilter (in_hLib, hFilter);
hFilter = TBX_HANDLE_INVALID;
}
}
/* Free the message buffer */
if (hMsg != TBX_HANDLE_INVALID)
{
/* Free the message */
TBXReleaseMsg (in_hLib, hMsg);
hMsg = TBX_HANDLE_INVALID;
}
/* Was there an error along in the process ? */
if (TBX_RESULT_FAILURE (Result))
{
TBX_EXIT_ERROR (Result, 0, "ToneConnect Failed");
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -