The following code provides an example of the function calls and procedures used to implement a network monitoring application.
// Application entry point
main()
{
// Start GlobalCall
gc_Start (NULL) ;
// Open the call logging device
long hDevice;
cl_Open(&hDevice, ":P_ISDN:M_HDLC:N_dtiB1:U_dtiB2", NULL);
// Enable the application event handler
sr_enbhdlr(hDevice, EV_ANYEVT, appEventHandler);
// Wait until <return> is hit
char szUnusedInput[256];
gets(szUnusedInput);
// Disable the application event handler
sr_dishdlr(hDevice, EV_ANYEVT, appEventHandler);
// Close the call logging device
cl_Close(hDevice);
// Stop GlobalCall
gc_Stop( ) ;
}
// Define the transaction bag structure that will be used as the transaction user attribute
struct TRANSACTIONBAG
{
char szCaller[256];
char szCallee[256];
char szChannel[256];
time_t timeStart;
time_t timeEnd;
};
// Application event handler
long appEventHandler(unsigned long hEvent)
{
long hDevice = sr_getevtdev(hEvent);
// Identify the type of event received
switch (sr_getevttype(hEvent))
{
case CLEV_MESSAGE:
// Get the call logging transaction ID
CL_EVENTDATA* pclEventData = (CL_EVENTDATA*)sr_getevtdatap(hEvent);
long idTransaction;
cl_GetTransaction(hDevice, &idTransaction, pclEventData);
// Is it the first message for this call logging transaction ?
int iResult = pclEventData->iResult;
if ((iResult & ECL_FIRST_MESSAGE) != 0)
{
// Create the transaction bag structure
TRANSACTIONBAG* pTransactionBag = new TRANSACTIONBAG;
memset(pTransactionBag, 0, sizeof(TRANSACTIONBAG));
// Associate the transaction bag structure with the call logging
transaction
cl_SetTransactionUsrAttr(hDevice, idTransaction, pTransactionBag);
// Remember the time when the call logging transaction started
pTransactionBag->timeStart = pclEventData->timeEvent;
}
// Is it the last message for this call logging transaction ?
if ((iResult & ECL_LAST_MESSAGE) != 0)
{
// Retrieve the transaction bag structure for this call logging
transaction
TRANSACTIONBAG* pTransactionBag;
cl_GetTransactionUsrAttr(hDevice, idTransaction,
(void**)&pTransactionBag);
// Remember the time when the call transaction ended
pTransactionBag->timeEnd = pclEventData->timeEvent;
// Get the caller number
cl_GetCalling(hDevice, pclEventData, pTransactionBag->szCaller, 256);
// same as: cl_GetVariable(hDevice, pclEventData, "CALLING",
pTransactionBag->szCaller, 256);
// Get the callee number
cl_GetCalled(hDevice, pclEventData, pTransactionBag->szCallee, 256);
// same as: cl_GetVariable(hDevice, pclEventData, "CALLED",
pTransactionBag->szCallee, 256);
// Get the channel on which the call logging transaction took place
cl_GetChannel(hDevice, pclEventData, pTransactionBag->szChannel, 256);
// same as: cl_GetVariable(hDevice, pclEventData, "CHANNEL",
pTransactionBag->szChannel, 256);
// Application-specific: record the call logging transaction statistics
RecordNetworkStatistics(pTransactionBag);
// Delete the transaction bag structure
delete pTransactionBag;
// We are now done with this call logging transaction
cl_ReleaseTransaction(hDevice, idTransaction);
}
// This event has been consumed
return 0;
break;
}
return 1;
}
Click here to contact Dialogic Customer Engineering
Copyright 2001, Dialogic Corporation