协议栈初始化:
MegacoStack stack;
MegacoEntity mgcTcp, mgcUdp;
Priority priority;
MegacoEntityAddress mgcAddr;
/* Initialize system */
MegacoSystemInit();
/* The MEGACO Stack has embedded logging messages which can
be used for debugging purposes. The logging messages can be
turned on or off. */
/* Start-up standard I/O listener */
stdioListener =
(LogListener*)MemAlloc(sizeof(LogListener));
LogListenerConstruct(stdioListener, LOGMASK_ERROR,
LogStdio, stderr);
LogRegisterListener(&Log, stdioListener);
/* Start-up file listener */
fileListener =
(LogListener*)MemAlloc(sizeof(LogListener));
LogListenerConstruct(fileListener, LOGMASK_NONE,
LogFile, (void*)LOG_FILEDEPTH);
LogRegisterListener(&Log, fileListener);
/* Construct stack */
PriorityConstruct(&priority, PRIORITYCLASS_LOW,
priorityValue);
MegacoStackConstruct(&stack, numThreads, &priority);
/* Register stack callbacks */
MegacoStackRegisterSecurityKeyCB(&stack, getKey,
userData);
MegacoStackRegisterAuthenticationCB(&stack, HmacMd5,
MD5_HASHLENGTH);
MegacoStackRegisterRawRecvCB(&stack, rawRecvCallback,
userData);
MegacoStackRegisterRawSendCB(&stack, rawSendCallback,
userData);
/* Construct entity address */
MegacoEntityAddressConstruct(&mgcAddr, "88.42.39.56", 0 /*
use default port */);
/* Construct entities */
MegacoEntityConstructLocal(&mgcTcp, &mgcAddr, True,
MEGACOENTITYTYPE_MGC, TRANSPORTTYPE_TCP,
MEGACOENCODING_TEXT, &stack);
MegacoEntityConstructLocal(&mgcUdp, &mgcAddr, True,
MEGACOENTITYTYPE_MGC, TRANSPORTTYPE_UDP,
MEGACOENCODING_TEXT, &stack);
/* Register callbacks for local entities */
MegacoEntityRegisterRecvRequestCB(&mgcTcp, processRequest,
userData);
MegacoEntityRegisterRecvRequestCB(&mgcUdp, processRequest,
userData);
MegacoEntityRegisterRecvErrorMsgCB(&mgcTcp, processError,
userData);
MegacoEntityRegisterRecvErrorMsgCB(&mgcUdp, processError,
userData);
/* Destroy temporary objects */
MegacoEntityAddressDestruct(&mgcAddr);
PriorityDestruct(&priority);
/* Register stack with the system */
MegacoSystemRegisterStack(&stack);
/* ... */
/* Unregister stack */
MegacoSystemUnregisterStack(&stack);
/* Destroy objects */
MegacoEntityDestruct(&mgcUdp);
MegacoEntityDestruct(&mgcTcp);
MegacoStackDestruct(&stack);
/* System cleanup */
MegacoSystemEnd();