Example #1
0
void JudgeThread::operator()()
{
    ILogger *logger = LoggerFactory::getLogger(LoggerId::AppInitLoggerId);

    OJString infoBuffer;
    FormatString(infoBuffer, OJStr("work/%d"), id_);
    FileTool::MakeDir(infoBuffer);

    FormatString(infoBuffer, OJStr("[JudgeThread][%d]start..."), id_);
    logger->logTrace(infoBuffer);

    while (!g_sigExit)
    {

        IMUST::TaskPtr pTask;

        //从任务队列取任务
        workingTaskMgr_->lock();
        if(workingTaskMgr_->hasTask())
        {
            pTask = workingTaskMgr_->popTask();
        }
        workingTaskMgr_->unlock();

        if(!pTask)//没有任务
        {
            OJSleep(1000);
            continue;
        }

        pTask->init(id_);
        if(!pTask->run())
        {
            FormatString(infoBuffer, 
                OJStr("[JudgeThread][%d]System Error!Judge thread will exit!"), id_);
            logger->logError(infoBuffer);
            break;
        }

        //添加到完成队列
        finisheTaskMgr_->lock();
        finisheTaskMgr_->addTask(pTask);
        finisheTaskMgr_->unlock();

        OJSleep(10);//防止线程过度繁忙
    }

    FormatString(infoBuffer, OJStr("[JudgeThread][%d]end."), id_);
    logger->logTrace(infoBuffer);

}
Example #2
0
bool JudgeTask::match()
{
    ILogger *logger = LoggerFactory::getLogger(LoggerId::AppInitLoggerId);
    logger->logTrace(OJStr("[JudgeTask] start match..."));

    MatcherPtr matcher = MatcherFactory::create(false, OJStr(""));
    matcher->run(answerOutputFile_, userOutputFile_);

    if(matcher->isAccept())
    {
        output_.Result = AppConfig::JudgeCode::Accept;
    }
    else if(matcher->isPresentError())
    {
        output_.Result = AppConfig::JudgeCode::PresentError;
    }
    else if(matcher->isWrongAnswer())
    {
        output_.Result = AppConfig::JudgeCode::WrongAnswer;
    }
    else if(matcher->isSystemError())
    {
        output_.Result = AppConfig::JudgeCode::SystemError;
    }

    return matcher->isAccept();
}
Example #3
0
bool JudgeTask::compile()
{
    ILogger *logger = LoggerFactory::getLogger(LoggerId::AppInitLoggerId);
    logger->logTrace(OJStr("[JudgeTask] start compile..."));
    
    CompilerPtr compiler = CompilerFactory::create(Input.Language);
    compiler->run(codeFile_, exeFile_, compileFile_);

    if(compiler->isAccept())
    {
        output_.Result = AppConfig::JudgeCode::Accept;
    }
    else if(compiler->isSystemError())
    {
        output_.Result = AppConfig::JudgeCode::SystemError;
    }
    else if(compiler->isCompileError())
    {
        output_.Result = AppConfig::JudgeCode::CompileError;
        
        std::vector<OJChar_t> buffer;
        if(FileTool::ReadFile(buffer, compileFile_) && !buffer.empty())
        {
            output_.CompileError = &buffer[0];
        }
    }

    return compiler->isAccept();
}
Example #4
0
bool JudgeTask::excute()
{
    ILogger *logger = LoggerFactory::getLogger(LoggerId::AppInitLoggerId);
    logger->logTrace(OJStr("[JudgeTask] start excute..."));
    
    OJString infoBuffer;

    if(!FileTool::IsFileExist(exeFile_))
    {
        FormatString(infoBuffer, OJStr("[JudgeTask] not found exe file! %s."), exeFile_);
        logger->logError(infoBuffer);
        output_.Result = AppConfig::JudgeCode::SystemError;
        return false;
    }

    ExcuterPtr excuter = ExcuterFactory::create(Input.Language);
    excuter->run(exeFile_, answerInputFile_, userOutputFile_, Input.LimitTime, Input.LimitMemory);
    
    if(excuter->isAccept())
    {
        output_.Result = AppConfig::JudgeCode::Accept;
    }
    else if(excuter->isSystemError())
    {
        output_.Result = AppConfig::JudgeCode::SystemError;
    }
    else if(excuter->isOutputOutOfLimited())
    {
        output_.Result = AppConfig::JudgeCode::OutputLimited;
    }
    else if(excuter->isTimeOutOfLimited())
    {
        output_.Result = AppConfig::JudgeCode::TimeLimitExceed;
    }
    else if(excuter->isMemoryOutOfLimited())
    {
        output_.Result = AppConfig::JudgeCode::MemoryLimitExceed;
    }
    else if(excuter->isRuntimeError())
    {
        output_.Result = AppConfig::JudgeCode::RuntimeError;
    }

    output_.RunTime = excuter->getRunTime();
    output_.RunMemory = excuter->getRunMemory();

    return excuter->isAccept();
}
Example #5
0
bool InitAppConfig()
{
#define READ_APP_CONFIG(fun, tag, value)     \
    if(!root->fun(OJStr(tag), value))        \
    {   \
        logger->logError(OJStr("[config] - IMUST::AppConfig::InitAppConfig: read tag faild! ")##OJStr(tag));   \
        return false; \
    }

    ILogger *logger = LoggerFactory::getLogger(LoggerId::AppInitLoggerId);
    logger->logTrace(GetOJString("[config] - IMUST::AppConfig::InitAppConfig"));

    XmlPtr root = XmlFactory::getXml(GetOJString("RapidXml"));
    if(!root->load(OJStr("config.xml")))
    {
        logger->logError(OJStr("[config] - load config file faild! "));
        return false;
    }

    root = root->read(OJStr("AppConfig"));
    if(!root)
    {
        logger->logError(OJStr("[config] - read tag 'AppConfig' faild! "));
        return false;
    }

    READ_APP_CONFIG(readInt32, "CpuInfo/NumberOfCore", CpuInfo::NumberOfCore);

    READ_APP_CONFIG(readString, "MySql/Ip", MySql::Ip);
    READ_APP_CONFIG(readInt32,  "MySql/Port", MySql::Port);
    READ_APP_CONFIG(readString, "MySql/User", MySql::User);
    READ_APP_CONFIG(readString, "MySql/Password", MySql::Password);
    READ_APP_CONFIG(readString, "MySql/DBName", MySql::DBName);

    READ_APP_CONFIG(readBool, "Compiler/HasMsC", Compiler::HasMsC);
    READ_APP_CONFIG(readBool, "Compiler/HasMsCxx", Compiler::HasMsCxx);
    READ_APP_CONFIG(readBool, "Compiler/HasGcc", Compiler::HasGcc);
    READ_APP_CONFIG(readBool, "Compiler/HasGxx", Compiler::HasGxx);
    READ_APP_CONFIG(readBool, "Compiler/HasPascal", Compiler::HasPascal);
    READ_APP_CONFIG(readBool, "Compiler/HasJava", Compiler::HasJava);
	READ_APP_CONFIG(readBool, "Compiler/HasCs", Compiler::HasCs);
    READ_APP_CONFIG(readBool, "Compiler/HasPython", Compiler::HasPython);

    READ_APP_CONFIG(readInt32, "JudgeCode/Pending", JudgeCode::Pending);
    READ_APP_CONFIG(readInt32, "JudgeCode/Rejudge", JudgeCode::Rejudge);
    READ_APP_CONFIG(readInt32, "JudgeCode/Compiling", JudgeCode::Compiling);
    READ_APP_CONFIG(readInt32, "JudgeCode/Accept", JudgeCode::Accept);
    READ_APP_CONFIG(readInt32, "JudgeCode/PresentError", JudgeCode::PresentError);
    READ_APP_CONFIG(readInt32, "JudgeCode/WrongAnswer", JudgeCode::WrongAnswer);
    READ_APP_CONFIG(readInt32, "JudgeCode/TimeLimitExceed", JudgeCode::TimeLimitExceed);
    READ_APP_CONFIG(readInt32, "JudgeCode/MemoryLimitExceed", JudgeCode::MemoryLimitExceed);
    READ_APP_CONFIG(readInt32, "JudgeCode/OutputLimited", JudgeCode::OutputLimited);
    READ_APP_CONFIG(readInt32, "JudgeCode/RuntimeError", JudgeCode::RuntimeError);
    READ_APP_CONFIG(readInt32, "JudgeCode/CompileError", JudgeCode::CompileError);
    READ_APP_CONFIG(readInt32, "JudgeCode/CompileTimeError", JudgeCode::CompileTimeError);
    READ_APP_CONFIG(readInt32, "JudgeCode/CompileOK", JudgeCode::CompileOK);
    READ_APP_CONFIG(readInt32, "JudgeCode/SystemError", JudgeCode::SystemError);
    READ_APP_CONFIG(readInt32, "JudgeCode/UnknownError", JudgeCode::UnknownError);

    READ_APP_CONFIG(readString, "Path/TestDataPath", Path::TestDataPath);

    READ_APP_CONFIG(readBool, "WindowsUser/Enable", WindowsUser::Enable);
    READ_APP_CONFIG(readString, "WindowsUser/Name", WindowsUser::Name);
    READ_APP_CONFIG(readString, "WindowsUser/Password", WindowsUser::Password);
   
#undef READ_APP_CONFIG

    return true;
}