329 lines
8.5 KiB
C++
329 lines
8.5 KiB
C++
#include "ExamService.h"
|
|
#include "HFactory.h"
|
|
|
|
ExamService::ExamService()
|
|
{
|
|
logInit(LOG_LV_WARNING);
|
|
}
|
|
|
|
ExamService::~ExamService()
|
|
{
|
|
__DELETE__(m_car);
|
|
logUninit(); //yhy 2023-08-22 add
|
|
}
|
|
|
|
const char* ExamService::examJudgeVersion()
|
|
{
|
|
logdebug("call examJudgeVersion.");
|
|
return JUDGE_VERSION_INFO;
|
|
}
|
|
|
|
int ExamService::examJudgeSetLogCallback(int level, examJudgeCallbackLog callback)
|
|
{
|
|
logdebug("call examJudgeSetLogCallback.");
|
|
logSetLevel(level);
|
|
if(nullptr != callback)
|
|
{
|
|
m_cbLog = callback;
|
|
std::string s = "set log callback success";
|
|
callback(level, s.data(), s.length());
|
|
}
|
|
return QE(codeSuccess);
|
|
}
|
|
|
|
const char* ExamService::examJudgeErrorInfo(int errorCode)
|
|
{
|
|
logdebug("call examJudgeErrorInfo.");
|
|
return errorCode2Name((ErrorCode)errorCode);
|
|
}
|
|
|
|
int ExamService::examJudgeInit(const char* data, int len)
|
|
{
|
|
HELP_COST_TIME("");
|
|
//SpaceStorage space;
|
|
//Tools::getSpaceMemory(space, MB);
|
|
//logdebug("MemorySpace [spaceTotal=%lld MB] [spaceFree=%lld MB], [spaceAvailable=%lld MB], [spaceSelf=%lld MB]",
|
|
// space.spaceTotal, space.spaceFree, space.spaceAvailable, space.spaceSelf);
|
|
|
|
//logdebug("call examJudgeInit.");
|
|
logtrace("exam-init version=%s.", JUDGE_VERSION_INFO);
|
|
if(m_init)
|
|
{
|
|
//已经初始化过了,不能重复初始化
|
|
logerror("call examJudgeInit errorInitAlready.");
|
|
return QE(errorInitAlready);
|
|
}
|
|
|
|
if(m_initInfo != NULL)
|
|
{
|
|
__DELETE__(m_initInfo);
|
|
}
|
|
m_initInfo = __NEW__(TInitInfo);
|
|
m_initData = std::string(data, len);
|
|
XParser parser;
|
|
if(!parser.parseInitExam(m_initData, m_initInfo))
|
|
{
|
|
logerror("call examJudgeInit errorInitParser.");
|
|
return QE(errorInitParser);
|
|
}
|
|
|
|
#define CHECK_PARAM_INIT(exp) if(!(exp)) { logerror("init param [%s] error.", #exp); return QE(errorInitParam); }
|
|
CHECK_PARAM_INIT(!m_initInfo->carmodel.empty());
|
|
CHECK_PARAM_INIT(!m_initInfo->kscx.empty());
|
|
//CHECK_PARAM_INIT(!info.allitems.empty()); //KM2
|
|
//CHECK_PARAM_INIT(info.kchm > 0);
|
|
|
|
//加载数据库数据
|
|
ErrorCode errCode = TableDB->load(m_initInfo);
|
|
if(errCode != codeSuccess)
|
|
{
|
|
logerror("call examJudgeInit errCode=%d.", errCode);
|
|
return QE(errCode);
|
|
}
|
|
|
|
ExamSubject subject = ExamSubject(m_initInfo->kskm);
|
|
//加载测绘模型数据
|
|
switch(subject)
|
|
{
|
|
case ExamSubject2: errCode = FactorySub2Survey->load(m_initInfo); break;
|
|
case ExamSubject3: errCode = FactorySub3Survey->load(m_initInfo); break;
|
|
default: errCode = errorInitSubject; break;
|
|
}
|
|
if(errCode != codeSuccess)
|
|
{
|
|
logerror("call examJudgeInit error.");
|
|
return QE(errCode);
|
|
}
|
|
|
|
TASSERT(m_car == nullptr, "");
|
|
IExamCar::destroy(m_car);
|
|
m_car = IExamCar::create(subject); //yhy 2023-08-21 remove
|
|
TASSERT(m_car != nullptr, "");
|
|
ErrorCode code = m_car->examCarInitInfo(m_initInfo);
|
|
if(code != codeSuccess)
|
|
{
|
|
logerror("examCarInitInfo error");
|
|
return QE(code);
|
|
}
|
|
m_init = true;
|
|
logtrace("exam-init success kchp=%s,kchm=%d,kscx=%s.", m_initInfo->kchp.c_str(), m_initInfo->kchm, m_initInfo->kscx.c_str());
|
|
return QE(codeSuccess);
|
|
}
|
|
|
|
int ExamService::examJudgeDestroy()
|
|
{
|
|
logdebug("call examJudgeDestroy.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
//logUninit(); //yhy 2023-08-22 remove
|
|
//__DELETE__(m_car);
|
|
IExamCar::destroy(m_car);
|
|
FactorySub2Survey->unload();
|
|
FactorySub3Survey->unload();
|
|
TableDB->unload();
|
|
__DELETE__(m_initInfo);
|
|
m_initData = "";
|
|
m_init = false;
|
|
loginfo("exam-destroy success.");
|
|
|
|
__LOOK__("");
|
|
return QE(codeSuccess);
|
|
}
|
|
|
|
int ExamService::examJudgeBeginExam(const char* data, int len)
|
|
{
|
|
logdebug("call examJudgeBeginExam. data=%s", data);
|
|
if(!m_init) return QE(errorInitNot);
|
|
return m_car->examJudgeBeginExam(data, len);
|
|
}
|
|
|
|
int ExamService::examJudgeEndExam()
|
|
{
|
|
logdebug("call examJudgeEndExam.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
int code = m_car->examJudgeEndExam();
|
|
__LOOK__("");
|
|
return code;
|
|
}
|
|
|
|
int ExamService::examJudgeRealExam(const char* data, int len)
|
|
{
|
|
//logdebug("call examJudgeRealExam. data=%s", data);
|
|
if(!m_init) return QE(errorInitNot);
|
|
return m_car->examJudgeRealExam(data, len);
|
|
}
|
|
|
|
int ExamService::examJudgeRealExam2(const char* data, int len)
|
|
{
|
|
logdebug("call examJudgeRealExam2.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
return m_car->examJudgeRealExam2(data, len);
|
|
}
|
|
|
|
int ExamService::examJudgeSetRealExamCallback(examJudgeCallbackRealExam callback)
|
|
{
|
|
logdebug("call examJudgeSetRealExamCallback.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
if(nullptr != callback)
|
|
{
|
|
m_cbRealExam = callback;
|
|
return QE(codeSuccess);
|
|
}
|
|
return QE(codeSuccess);
|
|
}
|
|
|
|
int ExamService::examJudgeSetPerformCallback(examJudgeCallbackPerform callback)
|
|
{
|
|
logdebug("call examJudgeSetPerformCallback.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
if(nullptr != callback)
|
|
{
|
|
m_cbPerform = callback;
|
|
return QE(codeSuccess);
|
|
}
|
|
return QE(codeSuccess);
|
|
}
|
|
|
|
int ExamService::examJudgeArtificialMark(int itemno, const char* serial, int type)
|
|
{
|
|
logdebug("call examJudgeArtificialMark.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
return m_car->examJudgeArtificialMark(itemno, serial, type);
|
|
}
|
|
|
|
int ExamService::examJudgeArtificialItem(int itemno, int type)
|
|
{
|
|
logdebug("call examJudgeArtificialItem.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
return m_car->examJudgeArtificialItem(itemno, type);
|
|
}
|
|
|
|
int ExamService::examJudgeSoundEnd(int itemno, const char* code, int type)
|
|
{
|
|
logdebug("call examJudgeSoundEnd.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
return m_car->examJudgeSoundEnd(itemno, code, type);
|
|
}
|
|
|
|
const char* ExamService::examJudgeTrackFile()
|
|
{
|
|
logdebug("call examJudgeTrackFile.");
|
|
if(!m_init) return "";
|
|
return m_car->examJudgeTrackFile();
|
|
}
|
|
|
|
int ExamService::examJudgeMapSetParam(int width, int height)
|
|
{
|
|
logdebug("call examJudgeMapSetParam.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
if(!m_car) return QE(errorInitNot);
|
|
return m_car->examJudgeMapSetParam(width, height);
|
|
}
|
|
|
|
int ExamService::examJudgeMapSetScaling(int scaling)
|
|
{
|
|
logdebug("call examJudgeMapSetScaling.");
|
|
//if(!m_init) return QE(errorInitNot);
|
|
if(!m_car) return QE(errorInitNot);
|
|
return m_car->examJudgeMapSetScaling(scaling);
|
|
}
|
|
|
|
int ExamService::examJudgeMapSetDrawing(bool drawing)
|
|
{
|
|
logdebug("call examJudgeMapSetDrawing.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
if(!m_car) return QE(errorInitNot);
|
|
return m_car->examJudgeMapSetDrawing(drawing);
|
|
}
|
|
|
|
const char* ExamService::examJudgeMapImage()
|
|
{
|
|
logdebug("call examJudgeMapImage.");
|
|
if(!m_init) return "";
|
|
if(!m_car) return "";
|
|
return m_car->examJudgeMapImage();
|
|
}
|
|
|
|
int ExamService::examJudgeMapImageSetCallback(examJudgeCallbackMapImage callback)
|
|
{
|
|
logdebug("call examJudgeMapImageSetCallback.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
if(nullptr != callback)
|
|
{
|
|
m_cbMapImage = callback;
|
|
return QE(codeSuccess);
|
|
}
|
|
return QE(codeSuccess);
|
|
}
|
|
|
|
int ExamService::examJudgeMapWidth()
|
|
{
|
|
logdebug("call examJudgeMapWidth.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
return m_car->examJudgeMapWidth();
|
|
}
|
|
|
|
int ExamService::examJudgeMapHeight()
|
|
{
|
|
logdebug("call examJudgeMapHeight.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
return m_car->examJudgeMapHeight();
|
|
}
|
|
|
|
int ExamService::examJudgeMapSize()
|
|
{
|
|
logdebug("call examJudgeMapSize.");
|
|
if(!m_init) return QE(errorInitNot);
|
|
return m_car->examJudgeMapSize();
|
|
}
|
|
|
|
void ExamService::examJudgeCallbackLogToCaller(int level, const char* info, int len)
|
|
{
|
|
if(nullptr != m_cbLog)
|
|
{
|
|
m_cbLog(level, info, len);
|
|
}
|
|
}
|
|
|
|
void ExamService::examJudgeCallbackRealExamToCaller(const char* data, int len)
|
|
{
|
|
if(nullptr != m_cbRealExam)
|
|
{
|
|
m_cbRealExam(data, len);
|
|
//logwarning("event-data=%s", data);
|
|
}
|
|
}
|
|
|
|
void ExamService::examJudgeCallbackPerformToCaller(const char* data, int len)
|
|
{
|
|
if(nullptr != m_cbPerform)
|
|
{
|
|
m_cbPerform(data, len);
|
|
//logdebug("%s", data);
|
|
}
|
|
}
|
|
|
|
void ExamService::examJudgeCallbackMapImageToCaller(const char* data, int len)
|
|
{
|
|
if(nullptr != m_cbMapImage)
|
|
{
|
|
m_cbMapImage(data, len);
|
|
//logdebug("%s", data);
|
|
}
|
|
}
|
|
|
|
IExamCar* ExamService::getExamCar() const
|
|
{
|
|
TASSERT(m_car != nullptr, "");
|
|
return m_car;
|
|
}
|
|
|
|
const std::string& ExamService::getInitData() const
|
|
{
|
|
return m_initData;
|
|
}
|
|
|
|
const TInitInfo* ExamService::getInitInfo() const
|
|
{
|
|
return m_initInfo;
|
|
}
|