135 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			135 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include "StdAfx.h"
 | |
| 
 | |
| #include "connect.h"
 | |
| #include "tracing.h"
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TPrassiConnection 
 | |
| 
 | |
| TPrassiConnection::TPrassiConnection(TLanManager* lm, DWORD id)
 | |
|                  : TConnection(lm, id), m_nFirm(0)
 | |
| {
 | |
| }
 | |
| 
 | |
| TPrassiConnection::~TPrassiConnection()
 | |
| {
 | |
| 	for (POSITION pos = m_sqlFiles.GetStartPosition(); pos; )
 | |
| 	{
 | |
| 		long nHandle;
 | |
| 		TSqlFile* pFile;
 | |
| 		m_sqlFiles.GetNextAssoc(pos, nHandle, pFile);
 | |
| 		delete pFile;
 | |
| 	}
 | |
| 	m_sqlFiles.RemoveAll();
 | |
| }
 | |
| 
 | |
| BOOL TPrassiConnection::Trace(int level, const char* str) const
 | |
| {
 | |
| 	if (level <= 0 || TracingEnabled())
 | |
| 	{
 | |
| 		LPCSTR user = User();
 | |
| 		CString trc;
 | |
| 		trc.Format("%-8s %s", user, str);
 | |
| 		return ::Trace(level, trc);
 | |
| 	}
 | |
| 	return FALSE;
 | |
| }
 | |
| 
 | |
| struct TFunctionName
 | |
| {
 | |
| 	const char* name;
 | |
| 	ConnectionFunction pFunc;
 | |
| 	int level;
 | |
| };
 | |
| 
 | |
| const int MAX_FUNC = 33;
 | |
| static TFunctionName ftable[MAX_FUNC] =
 | |
| {
 | |
| 	{ "DongleHasModule",    f_DongleHasModule,   2 },
 | |
| 	{ "DongleModules",      f_DongleModules,     2 },
 | |
| 	{ "DongleNumber",       f_DongleNumber,      2 },
 | |
| 	{ "FileClearFields",	f_FileClearFields,   2 },
 | |
| 	{ "FileClose",			f_FileClose,		 1 },
 | |
| 	{ "FileFirst",			f_FileFirst,		 1 },
 | |
| 	{ "FileGetField",		f_FileGetField,		 1 },
 | |
| 	{ "FileGetFieldInfo",	f_FileGetFieldInfo,  2 },
 | |
| 	{ "FileGetItems",		f_FileGetItems,		 1 },
 | |
| 	{ "FileGetKey",			f_FileGetKey,		 1 },
 | |
| 	{ "FileGetKeyExpr",		f_FileGetKeyExpr,	 2 },
 | |
| 	{ "FileGetPosition",	f_FileGetPosition,	 1 },
 | |
| 	{ "FileLast",			f_FileLast,			 1 },
 | |
| 	{ "FileLock",			f_FileLock,			 1 },
 | |
| 	{ "FileMove",			f_FileMove,			 1 },
 | |
| 	{ "FileNext",			f_FileNext,			 1 },
 | |
| 	{ "FileOpen",			f_FileOpen,			 1 },
 | |
| 	{ "FileOpenTable",		f_FileOpenTable,	 1 },
 | |
| 	{ "FilePrev",			f_FilePrev,			 1 },
 | |
| 	{ "FileRead",			f_FileRead,          1 },
 | |
| 	{ "FileRemove",			f_FileRemove,        1 },
 | |
| 	{ "FileRewrite",		f_FileRewrite,       1 },
 | |
| 	{ "FileSetField",		f_FileSetField,		 1 },
 | |
| 	{ "FileSetKey",			f_FileSetKey,		 1 },
 | |
| 	{ "FileSkip",			f_FileSkip,			 1 },
 | |
| 	{ "FileUnlock",			f_FileUnlock,		 1 },
 | |
| 	{ "FileWrite",			f_FileWrite,		 1 },
 | |
| 	{ "FirmGet",			f_FirmGet,		     2 },
 | |
| 	{ "FirmSet",			f_FirmSet,		     1 },
 | |
| 	{ "FirmTest",			f_FirmTest,		     2 },
 | |
| 	{ "FtpGetFile",			f_FtpGetFile,		 2 },
 | |
| 	{ "UserLogin",			f_UserLogin,		 0 },
 | |
| 	{ "UserLogout",			f_UserLogout,		 0 },
 | |
| };
 | |
| 
 | |
| BOOL TPrassiConnection::Request(const char* str)
 | |
| {
 | |
| 	CStringArray argv;
 | |
| 	BOOL ok = ParseCommand(str, argv) > 0;
 | |
| 	if (ok) 
 | |
| 	{   
 | |
| 		const CString cmd = argv[0];
 | |
| 		int fmin = 0;
 | |
| 		int fmax = MAX_FUNC-1;
 | |
| 
 | |
| 		ok = FALSE;
 | |
| 		int cmp = 0;
 | |
| 		while (fmin <= fmax)
 | |
| 		{
 | |
| 			const int fcur = (fmax + fmin) / 2;
 | |
|             const TFunctionName& fn = ftable[fcur];
 | |
| 			cmp = cmd.CompareNoCase(fn.name);
 | |
| 			if (cmp == 0)
 | |
| 			{
 | |
| 				Trace(fn.level, str);
 | |
| 				
 | |
| 				const clock_t tempo = clock();
 | |
| 				
 | |
| 				ok = fn.pFunc(*this, &argv);
 | |
| 				
 | |
| 				if (TracingEnabled())
 | |
| 				{
 | |
| 					const double time = double(clock() - tempo) / CLOCKS_PER_SEC;
 | |
| 					if (time > 0.05)
 | |
| 					{
 | |
| 						CString str;
 | |
| 						str.Format("Time: %.2lf s", time);
 | |
| 						Trace(fn.level, str);
 | |
| 					}
 | |
| 				}
 | |
| 				break;
 | |
| 			}
 | |
| 			if (cmp < 0)
 | |
| 				fmax = fcur-1;
 | |
| 			else
 | |
| 				fmin = fcur+1;
 | |
| 	    }
 | |
| 		if (cmp)
 | |
| 		{
 | |
| 			CString strError = "ERROR: ";
 | |
| 			strError += str;
 | |
| 			Trace(-1, strError);
 | |
| 		}
 | |
| 	}
 | |
| 	return ok;
 | |
| }
 | |
| 
 |