107 lines
1.9 KiB
C++
Raw Normal View History

#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 = 5;
static TFunctionName ftable[MAX_FUNC] =
{
{ "DongleHasModule", f_DongleHasModule, 1 },
{ "DongleModules", f_DongleModules, 1 },
{ "DongleNumber", f_DongleNumber, 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;
}