⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.c

📁 telcobridges tone develop
💻 C
📖 第 1 页 / 共 3 页
字号:
					{
						g_aTrunkInfo [ pRspGetParam->un32Trunk ].unNb64KbpsTimeslotAvailable = 31; /* Clear-channel E1 */
					}
					else
					{
						g_aTrunkInfo [ pRspGetParam->un32Trunk ].unNb64KbpsTimeslotAvailable = 24; /* Clear-channel T1 or J1 */
					}

					g_aTrunkInfo [pRspGetParam->un32Trunk].fAllocated = TBX_TRUE;
				}
				else
				{
					/* We received an error */
					result = pRspGetParam->Result;
				}
			}
			else
			{
				out_pun32TrunkNo++;
				out_pun32TrunkNo--;
			}

			/* Free the message buffer */
			if (hMsg != TBX_HANDLE_INVALID)
			{
				/* Free the message */
				TBXReleaseMsg (in_hLib, hMsg);
				hMsg = TBX_HANDLE_INVALID;
			}
		}
		else
		{
			out_pun32TrunkNo++;
			out_pun32TrunkNo--;
		}
	}
	else
	{
		out_pun32TrunkNo++;
		out_pun32TrunkNo--;
	}

	/* Propagate an error result */
	if (TBX_RESULT_FAILURE (apiResult))
	{
		result = apiResult;
	}

	/* Release the filter */
	if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
	{
		TBXDestroyMsgFilter (in_hLib, hFilter);
		hFilter = TBX_HANDLE_INVALID;
	}

	if( *out_pun32TrunkNo > 64 )
	{
		out_pun32TrunkNo++;
		out_pun32TrunkNo--;
	}

	return result;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  RetrieveTrunkState:	Retrieve the state of a trunk
 |
 |  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_un32TrunkNb	:	Trunk to retrieve its state
 |	in_fVerbose		:	Verbose
 |
 |  Note			:	Allocated trunks must be in 'active' state for the application to work properly.
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |						or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
RetrieveTrunkState (
  IN		TBX_LIB_HANDLE			in_hLib,
  IN		TBX_ADAPTER_HANDLE		in_hAdapter,
  IN		TBX_UINT32				in_un32TrunkNb,
  IN		TBX_BOOL				in_fVerbose )
{
	PTB640_MSG_TRUNK_STATES_GET			pMsgGetState;
	PTB640_REQ_TRUNK_STATES_GET			pReqGetState;
	PTB640_RSP_TRUNK_STATES_GET			pRspGetState;
	TBX_FILTER_HANDLE					hFilter;
	TBX_MSG_HANDLE						hMsg;
	TBX_RESULT							result;
	TBX_RESULT_API						apiResult;

	/* Initialize local variables */
	pMsgGetState = NULL;
	pReqGetState = NULL;
	pRspGetState = NULL;
	hMsg = TBX_HANDLE_INVALID;
	result = TBX_RESULT_OK;
	apiResult = TBX_RESULT_API_OK;
	hFilter = (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID;

	/* Display progress */
	if( in_fVerbose )
	{
		fprintf (stdout, "Retrieving trunk state...\n" );
	}

	/* Get a message buffer */
	apiResult = TBXGetMsg (in_hLib, sizeof(*pMsgGetState), &hMsg);
	if (TBX_RESULT_SUCCESS (apiResult))
	{
		/* Clear the buffer..  Not necessary but helps debugging.  If used, must be done BEFORE setting the message header fields */
		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_STATES_GET,
		  TBX_MSG_TYPE_REQUEST,
		  sizeof(*pMsgGetState),
		  in_hAdapter,
		  in_un32TrunkNb,
		  in_un32TrunkNb);

		/* Fill the request */
		pMsgGetState = (PTB640_MSG_TRUNK_STATES_GET) TBX_MSG_PAYLOAD_POINTER (hMsg);
		pReqGetState = (PTB640_REQ_TRUNK_STATES_GET)&pMsgGetState->Request;
		pReqGetState->un32MsgVersion = 1;
		pReqGetState->hTrunk = g_aTrunkInfo [in_un32TrunkNb].hTrunk;

		/* Send the request */
		apiResult = TBXSendMsg (in_hLib, hMsg, &hFilter);
		hMsg = TBX_HANDLE_INVALID;
		if (TBX_RESULT_SUCCESS (apiResult))
		{
			pMsgGetState = NULL;
		}
	}

	/* Free the message buffer */
	if (hMsg != TBX_HANDLE_INVALID)
	{
		/* Free the message */
		TBXReleaseMsg (in_hLib, hMsg);
		hMsg = TBX_HANDLE_INVALID;
	}

	if (TBX_RESULT_SUCCESS (result))
	{
		/* Wait for the response synchronously */
		apiResult = TBXReceiveMsg (in_hLib, hFilter, TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
		if (TBX_RESULT_SUCCESS (apiResult))
		{
			/* Make sure we have received a proper response */
			if (TBX_MSG_ID_GET(hMsg) == TB640_MSG_ID_TRUNK_STATES_GET)
			{
				/* We got the response */
				pMsgGetState = (PTB640_MSG_TRUNK_STATES_GET) TBX_MSG_PAYLOAD_POINTER (hMsg);
				pRspGetState = (PTB640_RSP_TRUNK_STATES_GET)&pMsgGetState->Response;

				/* Retrieve the index into our array */
				if( (TBX_UINT32)TBX_MSG_USER_CONTEXT1_GET (hMsg) == in_un32TrunkNb )
				{
					/* Was the configuration successful ? */
					if (TBX_RESULT_SUCCESS (pRspGetState->Result))
					{
						TB640_TRUNK_STATE	TrunkState = TB640_TRUNK_STATE_IDLE;
						if( pRspGetState->aStates[ 0 ].Type == TB640_TRUNK_TYPE_E1 )
						{
							TrunkState = pRspGetState->aStates[ 0 ].States.E1.State;
						}
						else if( pRspGetState->aStates[ 0 ].Type == TB640_TRUNK_TYPE_T1 )
						{
							TrunkState = pRspGetState->aStates[ 0 ].States.T1.State;
						}
						else if( pRspGetState->aStates[ 0 ].Type == TB640_TRUNK_TYPE_J1 )
						{
							TrunkState = pRspGetState->aStates[ 0 ].States.J1.State;
						}

						/* Get the activated state */
						g_aTrunkInfo [in_un32TrunkNb].fActivated = (TrunkState == TB640_TRUNK_STATE_ACTIVE);
					}
					else
					{
						/* We received an error */
						result = pRspGetState->Result;
					}
				}
				else
				{
					/* Error */
					result = TBX_RESULT_API_INCOMPLETE;
				}
			}

			/* Free the message buffer */
			if (hMsg != TBX_HANDLE_INVALID)
			{
				/* Free the message */
				TBXReleaseMsg (in_hLib, hMsg);
				hMsg = TBX_HANDLE_INVALID;
			}
		}
	}

	/* Propagate an error result */
	if (TBX_RESULT_FAILURE (apiResult))
	{
		result = apiResult;
	}

	/* Release the filter */
	if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
	{
		TBXDestroyMsgFilter (in_hLib, hFilter);
		hFilter = TBX_HANDLE_INVALID;
	}

	return result;
}



/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  ConfigureAdapterTrunk	:	This function configures a E1 trunk with default parameters.
 |								If the trunk was already configured, it is not re-configured.
 |
 |  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_un32TrunkNb			:	Trunk number. The number of the trunk to configure (0-63)
 |	out_pfTrunkAllocated	:	Returns TBX_TRUE if the trunk has been allocated, TBX_FALSE if it was already
 |								configured.
 |
 |  Note			:	The adapter must support E1 configuration if the user chooses default config.
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |						or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
ConfigureAdapterTrunk (
  IN		TBX_LIB_HANDLE			in_hLib,
  IN		TBX_ADAPTER_HANDLE		in_hAdapter,
  IN		TBX_UINT32				in_un32TrunkNb,
  OUT		PTBX_BOOL				out_pfTrunkAllocated)
{
	TBX_RESULT		result;
	TBX_BOOL		fE1;

	/* Initialize local variables */
	result = TBX_RESULT_OK;

	if( out_pfTrunkAllocated ) *out_pfTrunkAllocated = TBX_FALSE;
	if( g_aTrunkInfo [in_un32TrunkNb].fActivated )
	{
		/* Already allocated */
		return result;
	}

	/* E1 or T1 ? */
	fE1 = PromptUserWithDefault_TBX_BOOL ("Do you want configure trunk in E1 mode?", TBX_TRUE);

	/* Set the configuration */
	result = SetDefaultTrunkConfiguration (in_hLib, in_hAdapter, in_un32TrunkNb, fE1);
	if (TBX_RESULT_SUCCESS (result))
	{
		*out_pfTrunkAllocated = TBX_TRUE;
	}

	/* Was there an error along in the process ? */
	if (TBX_RESULT_FAILURE (result))
	{
		ValidateErrorCode (result, in_hAdapter, in_hLib);
	}

	return result;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  FreeAdapterTrunk	:	This function frees previously allocated trunk.
 |
 |  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_un32TrunkNb		:	Trunk number. The number of the trunk to free (0-63)
 |	out_pfTrunkFreed	:	Returns if trunk was freed or not
 |
 |  Note				:	The trunk list is stored in global variables set by the ConfigureAdapterTrunks() function.
 |							This function uses async method to send requestx by sending all messages related to a trunk
 |							sequentially (they will execute in the same order).  This method can be useful when command
 |							are not inter-related (or if you are sure of their success).
 |
 |  Return				:	TBX_RESULT_OK
 |							TBX_RESULT_FAIL
 |							or others
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
FreeAdapterTrunk (
  IN		TBX_LIB_HANDLE			in_hLib,
  IN		TBX_ADAPTER_HANDLE		in_hAdapter,
  IN		TBX_UINT32				in_un32TrunkToFree,
  OUT		PTBX_BOOL				out_pfTrunkFreed)
{
	PTB640_MSG_TRUNK_OP_FREE				pMsgTrunkFree;
	PTB640_REQ_TRUNK_OP_FREE				pReqTrunkFree;
	PTB640_RSP_TRUNK_OP_FREE				pRspTrunkFree;
	PTB640_MSG_TRUNK_OP_MAINTENANCE			pMsgTrunkMaintenance;
	PTB640_REQ_TRUNK_OP_MAINTENANCE			pReqTrunkMaintenance;
	PTB640_RSP_TRUNK_OP_MAINTENANCE			pRspTrunkMaintenance;
	TBX_FILTER_HANDLE						hFilter;
	TBX_MSG_HANDLE							hMsg;
	TBX_RESULT								result;
	TBX_RESULT_API							apiResult;
	TBX_BOOL								fTrunkFreed = TBX_TRUE;

	/* Initialize local variables */
	pMsgTrunkFree = NULL;
	pReqTrunkFree = NULL;
	pRspTrunkFree = NULL;
	pMsgTrunkMaintenance = NULL;
	pReqTrunkMaintenance = NULL;
	pRspTrunkMaintenance = NULL;
	hMsg = TBX_HANDLE_INVALID;
	result = TBX_RESULT_OK;
	apiResult = TBX_RESULT_API_OK;
	hFilter = (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID;

	if( out_pfTrunkFreed ) *out_pfTrunkFreed = TBX_FALSE;

	if (TBX_RESULT_SUCCESS (result))
	{
		/* Was this trunk activated by this application ? */
		if (g_aTrunkInfo [in_un32TrunkToFree].fActivated == TBX_TRUE)
		{
			/* Display progress */
			fprintf (stdout, "Freeing trunk...\n" );

			/* Get a message buffer */
			apiResult = TBXGetMsg (in_hLib, sizeof(*pMsgTrunkMaintenance), &hMsg);
			if (TBX_RESULT_SUCCESS (apiResult))
			{
				/* Clear the buffer..  Not necessary but helps debugging.  If used, must be done BEFORE setting the message header fields */
				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_OP_MAINTENANCE,
				  TBX_MSG_TYPE_REQUEST,
				  sizeof(*pMsgTrunkMaintenance),
				  in_hAdapter,
				  in_un32TrunkToFree,
				  in_un32TrunkToFree);

				/* Fill the request */
				pMsgTrunkMaintenance = (PTB640_MSG_TRUNK_OP_MAINTENANCE) TBX_MSG_PAYLOAD_POINTER (hMsg);
				pReqTrunkMaintenance = (PTB640_REQ_TRUNK_OP_MAINTENANCE)&pMsgTrunkMaintenance->Request;
				pReqTrunkMaintenance->un32MsgVersion = 1;
				pReqTrunkMaintenance->hTrunk = g_aTrunkInfo [in_un32TrunkToFree].hTrunk;

				/* Send the request */
				apiResult = TBXSendMsg (in_hLib, hMsg, &hFilter);
				hMsg = TBX_HANDLE_INVALID;
				if (TBX_RESULT_SUCCESS (apiResult))
				{
					pMsgTrunkMaintenance = NULL;
				}
			}

			/* Free the message buffer */
			if (hMsg != TBX_HANDLE_INVALID)
			{
				/* Free the message */
				TBXReleaseMsg (in_hLib, hMsg);
				hMsg = TBX_HANDLE_INVALID;
			}

			/* Wait for the response synchronously */
			apiResult = TBXReceiveMsg (in_hLib, hFilter, TB640_TONE_RECEIVE_TIMEOUT_MSEC, &hMsg);
			if (TBX_RESULT_SUCCESS (apiResult))
			{
				/* Make sure we have received a proper response */
				if (TBX_MSG_ID_GET(hMsg) == TB640_MSG_ID_TRUNK_OP_MAINTENANCE)
				{
					/* We got the response */
					pMsgTrunkMaintenance = (PTB640_MSG_TRUNK_OP_MAINTENANCE) TBX_MSG_PAYLOAD_POINTER (hMsg);
					pRspTrunkMaintenance = (PTB640_RSP_TRUNK_OP_MAINTENANCE)&pMsgTrunkMaintenance->Response;

					/* Retrieve the index into our array */
					if( (TBX_UINT32)TBX_MSG_USER_CONTEXT1_GET (hMsg) == in_un32TrunkToFree )
					{
						/* Was the configuration successful ? */
						if (TBX_RESULT_SUCCESS (pRspTrunkMaintenance->Result))
						{
							/* The trunk was desactivated (or is in the process of... */
							g_aTrunkInfo [in_un32TrunkToFree].fActivated = TBX_FALSE;
						}
						else
						{
							/* We received an error */
							result = pRspTrunkMaintenance->Result;
						}
					}
					else
					{
						/* error */
						result = TBX_RESULT_API_INCOMPLETE;
					}
				}

				/* Free the message buffer */
				if (hMsg != TBX_HANDLE_INVALID)
				{
					/* Free the message */
					TBXReleaseMsg (in_hLib, hMsg);
					hMsg = TBX_HANDLE_INVALID;
				}
			}

			/* Release the filter */
			if (hFilter != (TBX_FILTER_HANDLE)TBX_HANDLE_INVALID)
			{
				TBXDestroyMsgFilter (in_hLib, hFilter);
				hFilter = TBX_HANDLE_INVALID;
			}

		}

		if (g_aTrunkInfo [in_un32TrunkToFree].fAllocated == TBX_TRUE)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -