📄 cmgeneral.c
字号:
cmEvTransNewRawMessage,
cmEvTransSendRawMessage,
NULL/*cmEvTransHostNewMessage*/,
NULL/*cmEvTransHostBadMessage*/,
NULL/*cmEvTransHostMultiplexChangeState*/,
cmEvTransHostListen,
cmEvTransHostListening,
cmEvTransHostConnecting
};
cmElem* app;
int status;
RvBool useAnnexE;
RvInt32 watchdogInterval;
RvTimerQueue* timersQueue;
/* Define some stack defaults if not found in the configuration */
RvUint32 maxCalls = 20;
int maxChannels = 2;
int vtNodeCount = 2700;
int maxBuffSize = 2048;
int maxPoolSizeInKB = maxCalls*maxBuffSize/1024;
int proposed,accepted;
*lphApp=NULL;
/* Make sure startup was called */
status = cmStartUp();
if (status != RV_OK)
return status;
/* Allocate an instance for the stack */
if(RvMemoryAlloc(NULL, (void**)&app, sizeof(cmElem)) != RV_OK)
return -10;
memset(app, 0, sizeof(cmElem));
RvMutexLock(&rvCmGlobalMutex);
/* Create a threadInfo object if we have to */
app->pThreadInfo = RvThreadCurrent();
if (app->pThreadInfo == NULL)
{
static int cmStacksNum = 0;
RvChar threadName[20];
app->pThreadInfo = &app->threadInformation;
status = RvThreadConstructFromUserThread(app->pThreadInfo);
if (status != RV_OK)
{
RvMutexUnlock(&rvCmGlobalMutex);
return -10;
}
RvSprintf(threadName, "%d H323Stack", cmStacksNum);
RvThreadSetName(app->pThreadInfo, threadName);
}
/* Initialize a log instance */
cmiCreateLog(app);
/* Create a select engine to work with */
{
RvUint32 index = 0;
status = seliInit();
if (status == RV_OK)
status = ThreadInstanceFindIndex(RV_THREAD_INSTANCE_SELECT, &index);
if (status == RV_OK)
status = ThreadInstanceGetObject(index, (void**)&app->selectEngine);
if (status != RV_OK)
{
RvMutexUnlock(&rvCmGlobalMutex);
return status;
}
}
/*allocate an instance for the watchdog*/
status = RvWatchdogAllocate(&app->watchdog, 21);
if (status < 0)
{
RvMemoryFree(app);
RvMutexUnlock(&rvCmGlobalMutex);
return -10;
}
RvLockConstruct(&app->appLock);
RvMutexConstruct(&app->applicationLock);
/* Create a random number generator */
RvRandomGeneratorConstruct(&app->randomGenerator, (RvRandom)(RvTimestampGet()>>16));
/* Create a GUID generator */
app->guidGenerator = RvH323UniqueIdGeneratorConstruct(&app->randomGenerator);
/* Make sure to notify about the version of the stack... */
cmiAPIEnter((HAPP)app,(char*)"cmInititialize(name=%s,lphApp)",nprn(name));
RvLogDebug(&app->logAPI, (&app->logAPI,
"Conference Manager: Version " RV_H323_STACK_VERSION));
RvLogDebug(&app->logAPI, (&app->logAPI,
"Common Core: CBase Version: %s", RvCBaseVersion()));
RvLogDebug(&app->logAPI, (&app->logAPI,
"Common Core: CCore Version: %s", RvCCoreVersion()));
#if (RV_LOGMASK_COMPILEMASK & RV_LOGLEVEL_DEBUG)
{
static const RvChar* osNames[] = {
"Solaris", "Linux", "Win32", "VxWorks", "pSOS", "OSE", "Nucleus", "HP-UX", "Tru64", "UnixWare", "WinCE", "Emb Linux"
};
RvAssert(RV_OS_TYPE < (sizeof(osNames) / sizeof(char*)));
RvLogDebug(&app->logAPI, (&app->logAPI,
"Working on %s", osNames[RV_OS_TYPE]));
}
#endif
/* Start with the configuration */
if ( (app->hCfg=ciConstruct(name)) == NULL)
{
RvLogError(&app->logERR,
(&app->logERR, "cmInit: Configuration construction error (%s).", nprn(name)));
cmiAPIExit((HAPP)app,(char*)"cmInitialize()=ciConstruct Failed",app);
RvMemoryFree(app);
RvMutexUnlock(&rvCmGlobalMutex);
return -11;
}
/* Initialize the MIB */
app->hStatistic = mibCreateStatistic();
readSystemParameters(app, (int*)&maxCalls,&maxChannels,&vtNodeCount,&maxBuffSize,&maxPoolSizeInKB);
if ( (maxCalls<0)||(maxChannels<0)||(maxBuffSize<0)||(maxPoolSizeInKB<0) )
{
ciDestruct(app->hCfg);
cmiAPIExit((HAPP)app, "cmInitialize()=Error reading parameters");
RvMemoryFree(app);
RvMutexUnlock(&rvCmGlobalMutex);
return RV_ERROR_UNKNOWN;
}
app->maxChannels=maxChannels;
app->encodeBufferSize=maxBuffSize;
/*
The following simultaneous timers are possible per call
1.call.timer
2.call.q931.timer
3.call.q931.timerSE
4.call.control.outcap.timer
5.call.control.msd.timer
6.call.control.out_RM.timer
7.call.control.rtd.timer
1.call.control.channel[].timer
2.call.control.channel[].ml_timer
3.call.control.channel[].rc_timer
*/
app->hTimers = RvH323TimerConstruct((int)(maxCalls * (7 + maxChannels * 3 + 10)), &timersQueue);
if (app->hTimers == NULL)
{
ciDestruct(app->hCfg);
cmiAPIExit((HAPP)app, "cmInitialize()=Error allocating timers");
RvMemoryFree(app);
RvMutexUnlock(&rvCmGlobalMutex);
return -13;
}
/* Initialize ASN related modules (coder, pvt, pst) */
cmEmInstall(maxBuffSize);
status = initPVT_PST(app, vtNodeCount);
configTreesInit(app);
/* Initialize calls and channels objects */
app->hCalls=cmiInitCalls((HAPP)app, (int)maxCalls);
app->hChannels=cmiInitChannels((HAPP)app, (int)maxCalls, maxChannels);
proposed=maxChannels*5;
accepted=maxChannels;
if (!fastStartInit(app, (int)maxCalls, proposed, accepted) || (status < 0))
{
cmiEndChannels(app->hChannels);
cmiEndCalls(app->hCalls);
RvH323TimerDestruct(app->hTimers);
ciDestruct(app->hCfg);
cmiAPIExit((HAPP)app,(char*)"cmInitialize()=liInit Failed");
RvMemoryFree(app);
RvMutexUnlock(&rvCmGlobalMutex);
return -10;
}
/* Make sure we allocated encode/decode buffers */
encodeDecodeBufferInit();
/* Initialize transport */
useAnnexE =
((pvtGetChild(app->hVal,app->q931Conf,__q931(useAnnexE),NULL))>=0);
if (!(app->hTransport= cmTransInit((HAPPATRANS)app, app->hVal, app->selectEngine,
(int)maxCalls, -1, maxPoolSizeInKB, maxBuffSize, useAnnexE, app->portRange)))
{
cmiAPIExit((HAPP)app, "cmInitialize()=cmTransInit failed");
ciDestruct(app->hCfg);
RvMemoryFree(app);
RvMutexUnlock(&rvCmGlobalMutex);
return RV_ERROR_UNKNOWN;
};
cmTransSetSessionEventHandler(app->hTransport, &tse,sizeof(TRANSSESSIONEVENTS));
cmTransSetHostEventHandler(app->hTransport, &the,sizeof(TRANSHOSTEVENTS));
/* Create CAT (Call Association Table) */
if ((app->hCat = catConstruct(maxCalls,
(RvBool)(ciGetValue(app->hCfg,"RAS.gatekeeper" ,NULL,NULL)>= 0),
(RvBool)(ciGetValue(app->hCfg,"RAS.compare15bitRasCrv" ,NULL,NULL)>= 0),
(RvBool)(app->cidAssociate!= RV_FALSE))) == NULL )
{
cmiAPIExit((HAPP)app,(char*)"cmInitialize()=catConstruct failed",app);
ciDestruct(app->hCfg);
RvMemoryFree(app);
RvMutexUnlock(&rvCmGlobalMutex);
return RV_ERROR_OUTOFRESOURCES;
}
/* Initialize the RAS module */
if ((status = rasInit(app)) < 0)
{
cmiAPIExit((HAPP)app,(char*)"cmInitialize()=rasInit failed",app);
rasStop(app);
ciDestruct(app->hCfg);
RvMemoryFree(app);
RvMutexUnlock(&rvCmGlobalMutex);
return status;
}
/* 2004.12.31. We show the memory info of the stack */
/* if (ciGetValue(app->hCfg, "system.printMemory", NULL, NULL) >= 0)*/
{
/* This piece of code allows us to use a performance test program with the release
mode compilation that will display on the standard output the amount of memory
allocated. */
RvMemoryInfo memInfo;
if (RvMemoryGetInfo(NULL, &memInfo) == RV_OK)
{
RvPrintf("Total stack allocation: %d bytes in %d blocks\n",
memInfo.bytes_requested_total, memInfo.allocs_requested);
}
}
/* Set watchdog resources for the CM */
status = emaAddWatchdogResource(app->hCalls, &app->watchdog, "CmCalls", "CM", "Call elements");
if (status < 0) { RvMutexUnlock(&rvCmGlobalMutex);return RV_ERROR_UNKNOWN;}
status = emaAddWatchdogResource(app->hChannels, &app->watchdog, "CmChannels", "CM", "Channel elements");
if (status < 0) { RvMutexUnlock(&rvCmGlobalMutex);return RV_ERROR_UNKNOWN;}
status = RvWatchdogAddResource(cmiGetWatchdogHandle((HAPP)app), "CmValTree", "CM", "PVT nodes",
(RvWatchdogResourceCallback_T)cmWatchdogResourceCallback,(void*) app, &app->cmValTreeResourceVal);
if (status < 0) { RvMutexUnlock(&rvCmGlobalMutex);return RV_ERROR_UNKNOWN;}
status = RvWatchdogAddResource(cmiGetWatchdogHandle((HAPP)app), "CmTimers", "CM", "Call Manager timers",
(RvWatchdogResourceCallback_T)cmWatchdogResourceCallback,(void*) app, &app->cmTimersResourceVal);
if (status < 0) { RvMutexUnlock(&rvCmGlobalMutex);return RV_ERROR_UNKNOWN;}
/* Initializing the watchdog */
status = RvWatchdogInit(&app->watchdog);
if (status<0)
{
RvMutexUnlock(&rvCmGlobalMutex);
return -10;
}
/* Set an interval timer for the watchdog */
app->watchdogTimer = NULL;
if (ciGetValue(app->hCfg, "system.watchdog.interval", NULL, &watchdogInterval) >= 0)
if (watchdogInterval > 0)
app->watchdogTimer = RvH323TimerStartPeriodic(app->hTimers, rvCmWakeWatchdog, app, (RvUint32)watchdogInterval*1000);
/* Make sure to print the first watchdog resources now */
RvLogDebug(&app->logWatchdog, (&app->logWatchdog,
"Resources before cmStart():"));
RvWatchdogPrint(&app->watchdog, &app->logWatchdog);
/* Start running the stack if we're supposed to */
if (name && ciGetValue(app->hCfg,"system.manualStart",NULL,NULL)<0)
if (cmStart((HAPP)app)<0)
{
cmiAPIExit((HAPP)app, "cmInitialize()=cmStart Failed");
ciDestruct(app->hCfg);
RvMemoryFree(app);
RvMutexUnlock(&rvCmGlobalMutex);
return RV_ERROR_UNKNOWN;
}
*lphApp=(HAPP)app;
/* We're done... */
cmiAPIExit((HAPP)app,(char*)"cmInitialize(*lphApp=0x%p)=0",app);
RvMutexUnlock(&rvCmGlobalMutex);
return 0;
}
/************************************************************************
* cmInit
* purpose: Initializes the Conference Manager instance.
* This function must be called before any other H.323 function
* except cmGetVersion().
* input : name - Configuration file name to use
* output : none
* return : Stack's application handle on success
* NULL on failure
************************************************************************/
RVAPI
HAPP RVCALLCONV cmInit(IN char * name)
{
HAPP hApp;
if (cmInitialize(name, &hApp) >= 0)
return hApp;
else
return NULL;
}
/************************************************************************
* cmStart
* purpose: Starts the stack's activity
*
* This function is only applicable when system.manualStart key
* is defined in the configuration. In manualStart mode cmInitialize()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -