Example #1
0
/*
 *REG /DATA=表名 参数设置  位置未确定 
 *调用各个算法
 */
bool TCManager::algorithmic(TCPacket &inP,string strName,AnaWord &aw, TCPacket &outP)
{
	CTString spath;
	TCSystem::GetTempPath(spath);
	spath = spath + "Sys.dat";
	//--UNIX PORT
	
	SYSTEMTIME st;
	GetLocalTime(&st);
	if ( GTime(st) >= Expire )
	{
		if(_access(spath.GetData(),0))//-- file not existed
		{ 
			return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));
		}
	}
/*	
#ifdef WINPLAT 
	WIN32_FIND_DATA wfd;
	if (FindFirstFile(spath.GetData(),&wfd) != INVALID_HANDLE_VALUE)
	{
		return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));
	}
			
#else

#endif
*/

	int nUserID = GetUserID(inP);
	if (nUserID==0)
		return SetResultState(false,outP,GetLanguage(UserIDIsNotFound));
	
	bool bMeOpenTable = false;  //是否为c++自己打开的
	string sTableName = "";
	int nCount = aw.GetWordCount();
	for (int i=0;i<nCount;i++)
	{
		if (aw.GetAt(i) == "/DATA" &&  i< nCount-2 )
		{
			sTableName = aw.GetAt(i+2);
		}
	}
	if (sTableName.size()==0)
		return SetResultState(false,outP,GetLanguage(FormatIsError));

	
	CDataInterface *pDI = g_system.GetCurData(nUserID,sTableName);
	if (pDI ==NULL)
	{		
		if (g_system.OpenTable(nUserID,sTableName,sTableName)==false)
			return SetResultState(false,outP,GetLanguage(OperationFail)); 
		
		pDI = g_system.GetCurData(nUserID,sTableName);
		if (pDI ==NULL)
			return SetResultState(false,outP,GetLanguage(UserTableIsNotFound));
		bMeOpenTable = true;
	}
	CTString str = aw.GetAt(0);			
	CTString sDllName, sProcName;
	int nProcType;
	if (TCSystem::GetModuleInfo(str,sDllName, sProcName,nProcType)==true)
	{
	//--UNIX PORT
//#ifdef WINPLAT
		HINSTANCE hmod = LoadLibrary(sDllName.GetData());
		if (hmod==NULL)       //没有找到对应的DLL
		{
			if (bMeOpenTable) //自己释放
				g_system.CloseTable(nUserID, sTableName); 
			SetResultState(false,outP,GetLanguage(DLLFileNotFind));//"没有找到对应的DLL"
			return false;
		}
				
		if (nProcType ==2)
		{
			typedef int (*pTrain)(CDataInterface *pData, CEnvParam *pEnv, Interaction *itt, string VO, string &ppOutStruct,CResult **ppRst);
			pTrain proc;
			proc = (pTrain)GetProcAddress(hmod,sProcName.GetData());
			if (proc==NULL)       //"没有找到对应的过程名"
			{
				if (bMeOpenTable) //自己释放
					g_system.CloseTable(nUserID, sTableName); 
				SetResultState(false,outP,GetLanguage(ProcNameNotFind));
				return false;
			}
			Interaction itTemp;
			string VO = strName;
			string ppOutStruct;
			CResult *pRst = NULL;
			int rst =(*proc)(pDI,g_system.GetCurEnv(0),&itTemp,VO,ppOutStruct,&pRst);
			if (pRst)
			{
				int nBuflen = pRst->GetBufLen();
				BYTE *pOut = new BYTE[nBuflen];
				BYTE *pTemp = pOut;
				pRst->Serialize(pTemp);
				outP.SetPacketName("Result");
				delete pRst;
				outP.AddItem("Out",( char*)pOut,nBuflen);
				delete []pOut;
			}
			//////////////////释放资源///////////////////
			if (bMeOpenTable)
				g_system.CloseTable(nUserID, sTableName); 
			::FreeLibrary((HMODULE)hmod);
			//////////////////释放资源///////////////////
			if (rst != 0)
				return SetResultState(false,outP,"");
			else
				return SetResultState(true,outP);
			
		}
		else
		{//===temp
		}
					
//#else
//	int rc; /* return codes */
//	void *FunctionLib =NULL; /* Handle to shared lib file */
//	//int (*Function)(int a); /* Pointer to loaded routine */
//	//typedef int (*FunctionA)(int a);
//	typedef int (*pTrain)(CDataInterface *pData, CEnvParam *pEnv, Interaction *itt, string VO, string &ppOutStruct,CResult **ppRst);
//	const char *dlError; /* Pointer to error string */
//
//	//FunctionLib = dlopen("/share/b/low.so",RTLD_LAZY);
//	FunctionLib = dlopen(sDllName.GetData(),RTLD_LAZY);
//	dlError = dlerror();
//	if( dlError )
//	{
//		printf(" AAA 3-Open Library with absolute path return-%s- \r\n", dlError);
//		exit(1);
//	}

//	Function = (pTrain)dlsym( FunctionLib, sProcName.GetData());// 
//	dlError = dlerror();
//	if( dlError ) 
//	{
//		printf(" AAA 4-Find symbol printUPPERCASE 返回-%s- \r\n", dlError);
//		exit(1);
//	}
//
//	Interaction itTemp;
//	string VO = strName;
//	string ppOutStruct;
//	CResult *pRst = NULL;
//	int rst = (*Function)(pDI,g_system.GetCurEnv(0),&itTemp,VO,ppOutStruct,&pRst);
//	if (pRst)
//	{
//		int nBuflen = pRst->GetBufLen();
//		BYTE *pOut = new BYTE[nBuflen];
//		BYTE *pTemp = pOut;
//		pRst->Serialize(pTemp);
//		outP.SetPacketName("Result");
//		delete pRst;
//		outP.AddItem("Out",( char*)pOut,nBuflen);
//		delete []pOut;
//	}
//	if (rst != 0)
//		return SetResultState(false,outP,"");
//	else
//		return SetResultState(true,outP);
//
//	printf(" AAA 5-printUPPERCASE return-%s- value :%d\r\n", dlError,rc);
//
//
	/* 6-Close the shared library handle */
	/* Note: after the dlclose, "printUPPERCASE" is not loaded */
//	rc = dlclose(FunctionLib);
//	if( rc )
//	{
//		dlError = dlerror();
//		printf(" AAA 6-Close handle return-%s- \r\n",dlError); 
//		exit(1);
//	}
//#endif
	} //-- end with GetModuleInfo
	else
	{//===temp 暂时不处理
	}
	return true;
}