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

📄 _piclsdb.cpp

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		const char *pSymbolString = PIConfigDB::LookupValue( (PIConfigDB *)pDB, pKey,
			0, 0 );
		if ( !pSymbolString )
			{
			bOK=false;
			PIOStrStream os;
			os << "Missing function '" << pKey << "' in specification \
 of class '" << pClassName << "'." << ends;
			Error( pDB, os.str() );
			break;
			};

		/* --- this common function does logging on error --- */
		void *pSymbolAddress = 0;
		pSymbolAddress = LoadSymbol( pLib, pDB, pSymbolString,
			pClassName );
		if ( !pSymbolAddress ) 
			{
			bOK=false;
			break;
			};
		pFunctionFrame[i]=(_PIClass::PfnFunction)pSymbolAddress;
		};
	if ( bOK )
		{
		assert( i==iNumFns );
		return pFunctionFrame;
		};

	PI_DELETE( [] pFunctionFrame );
	return 0;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
/* --- structures and externs to reference internal functions --- */
struct FunctionRecord {
	const char *pName;
	void (* fn)(void);
};
/*
** Statically link to extern with function record structures
*/
#if defined(CONFIG_STATICLINK)
	extern void *__pPiInternalFunctions[];
#else
	void **__pPiInternalFunctions = 0;
#endif
void *_PIClassDB::LoadSymbol( PIDLL *pLib, _PIDB *pDB, const char *pSymbol,
		const char *pClassName )
{
	assert( pSymbol );

	void *pSymbolAddress = 0;
	if ( !pLib )
		{
		/* --- 
		Load the symbol internally
		--- */
		if ( __pPiInternalFunctions )
			{
			for( int i=0; !pSymbolAddress && __pPiInternalFunctions[i]; i++ )
				{
				void *pData = __pPiInternalFunctions[i];
				struct FunctionRecord *pRecords = (FunctionRecord *)pData;
				for( int j=0; pRecords[j].pName; j++ )
					{
					if ( !strcmp( pRecords[j].pName, pSymbol ) )
						{
						pSymbolAddress = (void *)pRecords[j].fn;
						break;
						};
					};
				};
			};
		if ( !pSymbolAddress )
			{
			PIOStrStream os;
			os << "Internal function '" << pSymbol << "' not found." << ends;
			Error( pDB, os.str() );
			};
		}
	else
		{
		/* ---
		Load the symbol from a DLL
		--- */
		pSymbolAddress = PIDLL_getAddress( pLib, pSymbol );
		if ( !pSymbolAddress )
			{
			PIOStrStream os;
			const char *pError = PIDLL_getErrorDescription( pLib );
			os << "Error loading function '" << pSymbol
				<< "' in class '" << pClassName << "', error description is <" 
				<< (pError?pError:"") << ">." << ends;
			Error( pDB, os.str() );
			};
		};
	return pSymbolAddress;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
const char *pLogicFunctionNames[]=
{
	PIDBKEY_FN_ONCLASSLOAD,
	PIDBKEY_FN_CONSTRUCTOR,
	PIDBKEY_FN_COPYCONSTRUCTOR,
	PIDBKEY_FN_DESTRUCTOR,
	PIDBKEY_FN_EXECUTE,
		
	/* --- leave this last --- */
	0
};
_PIClass *_PIClassDB::CreateLogicClass( _PIDB *pDB, PIDLL *pLib,
	const char *pClassName )
{
	_PIClass::PfnFunction *pFrame = 0;
	AutoDeleteArray<_PIClass::PfnFunction> tA( pFrame = CreateFunctionFrame(
		pDB, pLib, pClassName,
		pLogicFunctionNames,
		_PIClass::LAST_FUNCTION + _PILogicClass::LAST_FUNCTION ) );	
	if ( !pFrame ) 
		{ return 0; };
	_PIClass *pClass = PI_NEW( _PILogicClass(
        pLib,
		PIString( (const char *)pClassName ),
		PIString( (const char *)pClassName ),
		pFrame, this ) );

	Add( PIDBTYPE_CLASS, pClassName, pClass, 0 ); 
	return pClass;
}

#if 0

/* support for SLL removed */

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
const char *pSLLFunctionNames[]=
{
	PIDBKEY_FN_ONCLASSLOAD,
	PIDBKEY_FN_CONSTRUCTOR,
	PIDBKEY_FN_COPYCONSTRUCTOR,
	PIDBKEY_FN_DESTRUCTOR,
		
	/* --- leave this last --- */
	0
};
_PIClass *_PIClassDB::CreateSLLClass( _PIDB *pDB, PIDLL *pLib,
	const char *pClassName )
{
	_PIClass::PfnFunction *pFrame = 0;
	AutoDeleteArray<_PIClass::PfnFunction> tA( pFrame = CreateFunctionFrame(
		pDB, pLib, pClassName,
		pSLLFunctionNames,
		_PIClass::LAST_FUNCTION + _PISLLClass::LAST_FUNCTION ) );	
	if ( !pFrame ) 
		{ return 0; };
	_PIClass *pClass = PI_NEW( _PISLLClass(
		PIString( (const char *)pClassName ),
		PIString( (const char *)pClassName ),
		pFrame, this ) );

	/* ---
	attempt to get SLL filename 
	--- */
	const char *pConfigLine = PIConfigDB::LookupValue( (PIConfigDB *)pDB,
		PIDBKEY_SLLFILE, 0, 0 );
	if ( !pConfigLine )
		{
		PI_DELETE( pClass );
		PIOStrStream os;
		os << "Path to SLL file not specified in class '" << pClassName <<
			"'" << ends;
		Error( pDB, os.str() );
		return 0;
		};

	/* ---
	Find or create the SLL tree under this parent's tree and load the
	SLL configuration and structures into it
	--- */
	_PIDB *pTheParent = GetParent();
	assert( pTheParent );	
	_PIDB *pSLL = (_PIDB *)pTheParent->Lookup( PIDBTYPE_TREE, PIDBKEY_SLL, 0 ); 
	if ( !pSLL )	/* if main SLL tree doesn't exist use parent */
		{ pSLL = pTheParent; };
	_PIDB *pSLLTree = PI_NEW( PIDBTree( pSLL, PIDBKEY_SLL ) );

	/* ---
	Load in all of this classes functions.
	--- */
	_PIDBIterator *pIter = 0;
	AutoDelete<_PIDBIterator> tI( pIter = pDB->GetIterator(
		PIDBTYPE_USER, PIDBKEY_FUNCTION, 0 ) );
	for( ; pIter && pIter->AtValidElement(); pIter->Next() )
		{
		UserDBType *pUser = (UserDBType *)pIter->Current( 0 );
		const char *pSymbol = 0;
		PIConfigDBString *pSymbolString = 0;
		if ( pUser )
			{ pSymbolString = (PIConfigDBString *)pUser->GetValue(); };
		if ( !pSymbolString )
			{ continue; };
		pSymbol = pSymbolString->GetString();

		/* --- this common function does logging on error --- */
		void *pSymbolAddress = LoadSymbol( pLib, pDB,
			pSymbol, pClassName );
		if ( !pSymbolAddress ) 
			{ break; };
		pSLLTree->Add( PIDBTYPE_OPAQUE, pSymbol, pSymbolAddress,
			0 ); 
		};

	/* ---
	attempt to load up the SLL file
	--- */
	PIConfigDB *pConfDB = PI_NEW( SLLDB( pSLLTree ) );
	pConfDB->Load( pConfigLine );
	Add( PIDBTYPE_CLASS, pClassName, pClass, 0 ); 
	return pClass;
}
#endif

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
	Load an I/O class.
\*____________________________________________________________________________*/
const char *pIOFunctionNames[]=
{
	PIDBKEY_FN_ONCLASSLOAD,
	PIDBKEY_FN_CONSTRUCTOR,
	PIDBKEY_FN_COPYCONSTRUCTOR,
	PIDBKEY_FN_DESTRUCTOR,
	PIDBKEY_FN_IN,
	PIDBKEY_FN_OUT,
		
	/* --- leave this last --- */
	0
};
_PIClass *_PIClassDB::CreateIOClass( _PIDB *pDB, PIDLL *pLib,
	const char *pClassName )
{
	_PIClass::PfnFunction *pFrame = 0;
	AutoDeleteArray<_PIClass::PfnFunction> tA( pFrame = CreateFunctionFrame(
		pDB, pLib, pClassName,
		pIOFunctionNames,
		_PIClass::LAST_FUNCTION + _PIIOClass::LAST_FUNCTION ) );	
	if ( !pFrame ) 
		{ return 0; };
	_PIClass *pClass = PI_NEW( _PIIOClass(
        pLib,
		PIString( (const char *)pClassName ),
		PIString( (const char *)pClassName ),
		pFrame, this ) );
	Add( PIDBTYPE_CLASS, pClassName, pClass, 0 ); 
	return pClass;
}

/*____________________________________________________________________________*\
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
const _PIClass *_PIClass::Lookup( _PIDB *pDB, const char *pClassName )
{
	assert( pDB && pClassName );
	_PIDB *pClsDB = Internal_LookupClassDB( pDB );
	if ( !pClsDB ) 
		{ return 0; };
	return (_PIClass *)pClsDB->Lookup( PIDBTYPE_CLASS, pClassName, 0 );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
const _PIClass *_PIClass::Load( _PIDB *pDB, PIConfigDB *pConfigDB,
	const char *pClassName )
{
	assert( pDB && pClassName );
	_PIClassDB *pClsDB = Internal_LookupClassDB( pDB );
	assert( pClsDB );
	return pClsDB->LoadClass( pConfigDB, pClassName );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
const _PIClass *_PIClass::LookupOrLoad( _PIDB *pDB, PIConfigDB *pConfigDB,
	const char *pClassName )
{
	assert( pDB && pClassName );
	const _PIClass *pClass = _PIClass::Lookup( pDB, pClassName );
	if ( !pClass )
		{
		_PIClassDB *pClsDB = Internal_LookupClassDB( pDB );
		assert( pClsDB );
		pClass = pClsDB->LoadClass( pConfigDB, pClassName );
		};
	return pClass;
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI const _PIClass *PIClass_lookup( _PIDB *pDB,
	const char *pClassName )
{
	if ( !pDB || !pClassName )
		{ return 0; };
	return _PIClass::Lookup( pDB, pClassName );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI const _PIClass *PIClass_load( _PIDB *pDB, PIConfigDB *pConfigDB,
	const char *pClassName )
{
	if ( !pDB || !pClassName )
		{ return 0; };
	return _PIClass::Load( pDB, pConfigDB, pClassName );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI const _PIClass *PIClass_lookupOrLoad( _PIDB *pDB,
	PIConfigDB *pConfigDB, const char *pClassName )
{
	if ( !pDB || !pClassName )
		{ return 0; };

	return _PIClass::LookupOrLoad( pDB, pConfigDB, pClassName );
}

/*____________________________________________________________________________*\
 *
 Function:
 Synopsis:
 Description:
\*____________________________________________________________________________*/
PUBLIC_PIAPI const PIDLL *PIClass_getLibrary( const _PIClass *pClass )
{
    if ( !pClass )
        { return 0; };

    return pClass->GetLibrary();
}

⌨️ 快捷键说明

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