guy 981f57a971 Aggiunta gestione del comando rpc DongleYear per l'anno di assistenza
git-svn-id: svn://10.65.10.50/trunk@6062 c028cbd2-c16b-5b4b-a496-9718f37d4682
1998-01-29 09:43:10 +00:00

108 lines
1.9 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()
{
}
BOOL TPrassiConnection::Trace(int level, const char* str) const
{
if (TracingEnabled())
{
LPCSTR user;
try
{
user = User();
}
catch(...)
{
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 = 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;
}