void judgeThread(){ while(true){ XMLHandler xmlh; if(rh->getNextXML(xmlh)){ xml_node xmlnd=xmlh.child("judge"); runid=atoi(xmlnd.child_value("runid")); jr.runid=runid; storepath=string(xmlnd.child_value("storepath")); fileprepath=string(xmlnd.child_value("fileprepath")); srcname=string(xmlnd.child_value("srcname")); string fullpath=storepath+fileprepath+srcname; #ifdef _DEBUG cout<<"dump the xml recved by judge thread"<<endl; xmlh.dump(); cout<<"compile src file parameters:"<<endl; cout<<"fullpath "<<fullpath<<endl; cout<<"runnablepath"<<runnablepath+"a.out"<<endl; #endif jr.compilecode=dm->compile("g++","-lm -DONLINE_JUDGE",fullpath,runnablepath+"a.out"); if(jr.compilecode==0){//succ dm->addRunnableLanucher(runnablepath+"a.out",inputpath+"1.in",runnablepath+"1.out"); jr.outputpath=runnablepath+"1.out"; dm->run(); jr.usg=dm->getRet(); jr.inputtype=1; //run NewJudger below if(jr.usg._re==0&&jr.usg._tle==0&&jr.usg._mle==0){ jer=shared_ptr<NewJudger>(new NewJudger(3,runnablepath+"1.out")); jer->run(); } } else jr.inputtype=0; XMLHandler xmlsend(getSendXML()); #if _DEBUG cout<<"but final got send xml is "<<endl; xmlsend.dump(); #endif jr.sendxmlpath=runnablepath+"ret"+to_string(runid)+".xml"; xmlsend.saveFile(jr.sendxmlpath.c_str()); rqh=shared_ptr<RequestHandler>(new RequestHandler()); rqh->sendFile(jr.sendxmlpath.c_str(),posturl.c_str()); } else{ nanosleep(&t100m,&tres); } } }
/* **From JudgeRet jr */ XMLHandler getSendXML(){ XMLHandler xmlh; xml_node nd=xmlh.addChild("result",NULL); nd.append_child("runid").append_child(node_pcdata).set_value(to_string(jr.runid).c_str()); nd.append_child("compilecode").append_child(node_pcdata).set_value(to_string(jr.compilecode).c_str()); nd.append_child("inputtype").append_child(node_pcdata).set_value(to_string(jr.inputtype).c_str()); nd.append_child("time").append_child(node_pcdata).set_value(to_string(jr.usg._timeUsage).c_str()); nd.append_child("mem").append_child(node_pcdata).set_value(to_string(jr.usg._memUsage).c_str()); nd.append_child("RE").append_child(node_pcdata).set_value(to_string(jr.usg._re).c_str()); nd.append_child("TLE").append_child(node_pcdata).set_value(to_string(jr.usg._tle).c_str()); nd.append_child("MLE").append_child(node_pcdata).set_value(to_string(jr.usg._mle).c_str()); nd.append_child("outpath").append_child(node_pcdata).set_value((runnablepath+"1.out").c_str()); JudgeInfo ji=jer->getRet(); nd.append_child("judgercorrect").append_child(node_pcdata).set_value(to_string(ji.correct).c_str()); nd.append_child("judgererrtype").append_child(node_pcdata).set_value(to_string(ji.err_type).c_str()); #if _DEBUG cout<<"getSendXML ret"<<endl; xmlh.dump(); #endif return xmlh; }