Files correlati : Ricompilazione Demo : [ ] Commento : Migliorie varie sul frontend git-svn-id: svn://10.65.10.50/trunk@7679 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			108 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			108 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include "StdAfx.h"
 | |
| 
 | |
| #include "connect.h"
 | |
| #include "tracing.h"
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TPrassiConnection 
 | |
| 
 | |
| TPrassiConnection::TPrassiConnection(TLanManager* lm, DWORD id, const char* name)
 | |
|                  : TConnection(lm, id), m_strPeer(name), m_nFirm(0)
 | |
| {
 | |
| }
 | |
| 
 | |
| TPrassiConnection::~TPrassiConnection()
 | |
| {
 | |
| }
 | |
| 
 | |
| BOOL TPrassiConnection::Trace(int level, const char* str) const
 | |
| {
 | |
| 	if (TracingEnabled())
 | |
| 	{
 | |
| 		LPCSTR user;
 | |
| 		try
 | |
| 		{
 | |
| 			user = User();
 | |
| 		}
 | |
| 		catch(...)
 | |
| 		{
 | |
| 			user = "GUEST";
 | |
| 		}
 | |
| 		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 = 6;
 | |
| static TFunctionName ftable[MAX_FUNC] =
 | |
| {
 | |
| 	{ "DongleHasModule", f_DongleHasModule, 1 },
 | |
| 	{ "DongleModules",   f_DongleModules,   1 },
 | |
| 	{ "DongleNumber",    f_DongleNumber,    1 },
 | |
| 	{ "DongleYear",      f_DongleYear,      1 },
 | |
| 	{ "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;
 | |
| }
 | |
| 
 |