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

📄 rvccore.c

📁 基于h323协议的软phone
💻 C
字号:
/***********************************************************************
Filename   : rvccore.c
Description: ccore 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 "rvccore.h"

static const RvChar *RvCCoreVersionString = "0.1";

/* Most modules in ccore require their init and end function to be called. */
/* The exceptions to this are drivers, whose init function are manage by */
/* the appropriate driver manager. */

/* Module include files for every module that requires init and end be called */
#include "rvtm.h"
#include "rvclock.h"
#include "rvtimestamp.h"
#include "rv64ascii.h"
#include "rvsemaphore.h"
#include "rvmutex.h"
#include "rvthread.h"
#include "rvlock.h"
#include "rvmemory.h"
#include "rvloglistener.h"
#include "rvlog.h"
#include "rvselect.h"
#include "rvsocket.h"
#include "rvhost.h"
#include "rvstdio.h"

/* Structure containing definitions for module calls */
typedef struct {
	RvStatus (*init)(void);
	RvStatus (*end)(void);
} RvCCoreModuleFuncs;

/* 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 RvCCoreModuleFuncs RvCCoreModules[] = {
	{ RvSemaphoreInit, RvSemaphoreEnd },
	{ RvMutexInit, RvMutexEnd },
	{ RvLockInit, RvLockEnd },
	{ Rv64AsciiInit, Rv64AsciiEnd },
	{ RvTmInit, RvTmEnd },
	{ RvClockInit, RvClockEnd },
	{ RvTimestampInit, RvTimestampEnd },
	{ RvMemoryInit, RvMemoryEnd },
	{ RvThreadInit, RvThreadEnd },
	{ RvLogListenerInit, RvLogListenerEnd },
    { RvLogInit, RvLogEnd },
	{ RvSelectInit, RvSelectEnd },
    { RvSocketInit, RvSocketEnd },
    { RvHostInit, RvHostEnd },
	{ RvStdioInit, RvStdioEnd },
	{ NULL, NULL } /* List must end with NULLs */
};

/* Lets make error codes a little easier to type */
#define RvCCoreErrorCode(_e) RvErrorCode(RV_ERROR_LIBCODE_CCORE, RV_CCORE_MODULE_CCORE, (_e))

static RvInt RvCCoreInitCount = 0; /* Use to make sure we only run once */
static RvInt RvCCoreNumModules;

/* Must be called before any other calls to any ccore modules. It is not */
/* reentrant so simultaneous calls to it (and RvCCoreEnd) MUST NOT be made. */
RvStatus RvCCoreInit(void)
{
	RvStatus result;

	if(RvCCoreInitCount != 0) {  /* We're already running */
		RvCCoreInitCount++;
		return RV_OK;
	}

	RvCCoreNumModules = 0;
	for(;;) {
		if(RvCCoreModules[RvCCoreNumModules].init == NULL)
			break;
		result = RvCCoreModules[RvCCoreNumModules].init();
		if(result != RV_OK) {
			/* Something failed, call end for modules that have already had init called. */
			for(RvCCoreNumModules = RvCCoreNumModules - 1; RvCCoreNumModules >= 0; RvCCoreNumModules--)
				RvCCoreModules[RvCCoreNumModules].end();
			return result;
		}
		RvCCoreNumModules++;
	}

	RvCCoreInitCount++;
	return RV_OK;
}

/* Must be called before system exit to clean up. It is not reentrant so */
/* simultaneous calls to it (and RvCCoreInit) MUST NOT be made. */
RvStatus RvCCoreEnd(void)
{
	RvStatus result, lastresult;

#if defined(RV_OTHERCHECK)
	if(RvCCoreInitCount <= 0)
		return RvCCoreErrorCode(RV_ERROR_UNKNOWN);
#endif

	if(RvCCoreInitCount > 1) { /* We're not at the last end yet */
		RvCCoreInitCount--;
		return RV_OK;
	}

	result = RV_OK;
	
	/* Go backwards for end. Don't stop for errors but save the first one we get. */
	for(RvCCoreNumModules = (RvCCoreNumModules - 1); RvCCoreNumModules >= 0; RvCCoreNumModules--) {
		lastresult = RvCCoreModules[RvCCoreNumModules].end();
		if(result == RV_OK)
			result = lastresult;
	}

	RvCCoreInitCount = 0;
	return result;
}

RVCOREAPI const RvChar * RVCALLCONV RvCCoreVersion(void)
{
	return RvCCoreVersionString;
}

#if defined(RV_TEST_CODE)
void RvCCoreTest(void) {
	RvStatus result;
	
	RvPrintf("Starting test of rvccore.\n");
	RvPrintf("RvCCoreVersion = %s\n", RvCCoreVersion());

	RvPrintf("RvCCoreInit(): ");
	result = RvCCoreInit();
	if(result == RV_OK) {
		RvPrintf("OK\n");
	} else RvPrintf("ERROR! Code = %d\n",result);

	RvPrintf("RvCCoreEnd(): ");
	result = RvCCoreEnd();
	if(result == RV_OK) {
		RvPrintf("OK\n");
	} else RvPrintf("ERROR! Code = %d\n",result);

}
#endif /* RV_TEST_CODE */

⌨️ 快捷键说明

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