?? rvcbase.c
字號:
/***********************************************************************
Filename : rvcbase.c
Description: cbase initialization and shutdown
************************************************************************
Copyright (c) 2001 RADVISION Inc. and RADVISION Ltd.
************************************************************************
NOTICE:
This document contains information that is confidential and proprietary
to RADVISION Inc. and RADVISION Ltd.. No part of this document may be
reproduced in any form whatsoever without written prior approval by
RADVISION Inc. or RADVISION Ltd..
RADVISION Inc. and RADVISION Ltd. reserve the right to revise this
publication and make changes without obligation to notify any person of
such revisions or changes.
***********************************************************************/
#include "rvcbase.h"
static const RvChar *RvCBaseVersionString = "0.1";
/* Most modules in cbase require their init and end function to be called. */
/* Module include files for every module that requires init and end be called */
#include "rvqueue.h"
#include "rvtimer.h"
/*#include "rvtimerengine.h"*/
/*#include "rvnethost.h"*/
/*#include "rviolayer.h"*/
/*#include "rvdefaultnetdrv.h"*/
/* Structure containing definitions for module calls */
typedef struct {
RvStatus (*init)(void);
RvStatus (*end)(void);
} RvCBaseModuleFuncs;
/* Array of Init and End functions that core will execute. The Init */
/* functions will be called in the order of this array and the End */
/* functions will be called in reverse order. */
static RvCBaseModuleFuncs RvCBaseModules[] = {
{ RvQueueInit, RvQueueEnd },
{ RvTimerInit, RvTimerEnd },
/* { RvTimerEngineInit, RvTimerEngineEnd },
{ RvNethostInit, RvNethostEnd },
{ RvIoLayerInit, RvIoLayerEnd },
{ RvDefaultNetDrvInit, RvDefaultNetDrvEnd },*/
{ NULL, NULL } /* List must end with NULLs */
};
/* Lets make error codes a little easier to type */
#define RvCBaseErrorCode(_e) RvErrorCode(RV_ERROR_LIBCODE_CBASE, RV_CBASE_MODULE_CBASE, (_e))
static RvInt RvCBaseInitCount = 0; /* Use to make sure we only run once */
static RvInt RvCBaseNumModules;
/* Must be called before any other calls to any cbase modules. It is not */
/* reentrant so simultaneous calls to it (and RvCBaseEnd) MUST NOT be made. */
/* CCore must be initialzed before this call since CCore services are required. */
RVCOREAPI RvStatus RVCALLCONV RvCBaseInit(void)
{
RvStatus result;
if(RvCBaseInitCount != 0) { /* We're already running */
RvCBaseInitCount++;
return RV_OK;
}
/* CCore is requred for CBase so initialize it. */
result = RvCCoreInit();
if(result != RV_OK)
return result;
RvCBaseNumModules = 0;
for(;;) {
if(RvCBaseModules[RvCBaseNumModules].init == NULL)
break;
result = RvCBaseModules[RvCBaseNumModules].init();
if(result != RV_OK) {
/* Something failed, call end for modules that have already had init called. */
for(RvCBaseNumModules = RvCBaseNumModules - 1; RvCBaseNumModules >= 0; RvCBaseNumModules--)
RvCBaseModules[RvCBaseNumModules].end();
return result;
}
RvCBaseNumModules++;
}
RvCBaseInitCount++;
return RV_OK;
}
/* Must be called before system exit to clean up. It is not reentrant so */
/* simultaneous calls to it (and RvCBaseInit) MUST NOT be made. */
RVCOREAPI RvStatus RVCALLCONV RvCBaseEnd(void)
{
RvStatus result, lastresult, coreresult;
#if defined(RV_OTHERCHECK)
if(RvCBaseInitCount <= 0)
return RvCBaseErrorCode(RV_ERROR_UNKNOWN);
#endif
if(RvCBaseInitCount > 1) { /* We're not at the last end yet */
RvCBaseInitCount--;
return RV_OK;
}
result = RV_OK;
/* Go backwards for end. Don't stop for errors but save the first one we get. */
for(RvCBaseNumModules = (RvCBaseNumModules - 1); RvCBaseNumModules >= 0; RvCBaseNumModules--) {
lastresult = RvCBaseModules[RvCBaseNumModules].end();
if(result == RV_OK)
result = lastresult;
}
RvCBaseInitCount = 0;
coreresult = RvCCoreEnd();
if(result == RV_OK)
result = coreresult;
return result;
}
RVCOREAPI const RvChar * RVCALLCONV RvCBaseVersion(void)
{
return RvCBaseVersionString;
}
#if defined(RV_TEST_CODE)
#include "rvstdio.h"
void RvCBaseTest(void) {
RvStatus result;
RvPrintf("Starting test of rvcbase.\n");
RvPrintf("RvCBaseVersion = %s\n", RvCBaseVersion());
RvPrintf("RvCBaseInit(): ");
result = RvCBaseInit();
if(result == RV_OK) {
RvPrintf("OK\n");
} else RvPrintf("ERROR! Code = %d\n",result);
RvPrintf("RvCBaseEnd(): ");
result = RvCBaseEnd();
if(result == RV_OK) {
RvPrintf("OK\n");
} else RvPrintf("ERROR! Code = %d\n",result);
}
#endif /* RV_TEST_CODE */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -