|
@@ -9,14 +9,37 @@ carmakerwork::carmakerwork(std::string strserver)
|
|
|
mstrserver = strserver;
|
|
|
mbRun = true;
|
|
|
mpthread = new std::thread(&carmakerwork::threadwork,this);
|
|
|
+
|
|
|
+ if(mbLog)
|
|
|
+ {
|
|
|
+ int64_t nNow = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
+ char strlogname[256];
|
|
|
+ snprintf(strlogname,256,"log%lld.txt",nNow);
|
|
|
+ mFileLog.setFileName(strlogname);
|
|
|
+ if(mFileLog.open(QIODevice::ReadWrite))
|
|
|
+ {
|
|
|
+ mbLogAvail = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
carmakerwork::~carmakerwork()
|
|
|
{
|
|
|
+ mbLogAvail = false;
|
|
|
+ mFileLog.close();
|
|
|
mbRun = false;
|
|
|
mpthread->join();
|
|
|
}
|
|
|
|
|
|
+void carmakerwork::Log(const char *str)
|
|
|
+{
|
|
|
+ if(mbLogAvail == false)return;
|
|
|
+ QString strTime = QDateTime::currentDateTime().toString("yyyy-MM-dd:hh:mm:ss:zzz ");
|
|
|
+ char strline[1000];
|
|
|
+ snprintf(strline,1000,"%s %s\n",strTime.toLatin1().data(),str);
|
|
|
+ mFileLog.write(strline);
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
void carmakerwork::threadwork()
|
|
|
{
|
|
@@ -43,10 +66,12 @@ void carmakerwork::threadwork()
|
|
|
|
|
|
int nRes = 0;
|
|
|
std::shared_ptr<char> pout_ptr = nullptr;
|
|
|
- int64_t nWorkID;
|
|
|
- int nOutSize;
|
|
|
+ int64_t nWorkID = -1;
|
|
|
+ int nOutSize = 0;
|
|
|
int nnowork = 0;
|
|
|
|
|
|
+ char strlog[256];
|
|
|
+
|
|
|
while(mbRun)
|
|
|
{
|
|
|
|
|
@@ -65,16 +90,22 @@ void carmakerwork::threadwork()
|
|
|
iv::ipg::workReply reply;
|
|
|
|
|
|
request.set_mnres(nRes);
|
|
|
+ if(nRes != 0)
|
|
|
+ {
|
|
|
+ request.set_workid(nWorkID);
|
|
|
+ }
|
|
|
if(nRes == 1)
|
|
|
{
|
|
|
if(pout_ptr != nullptr)
|
|
|
{
|
|
|
- request.set_workid(nWorkID);
|
|
|
+
|
|
|
request.set_xdata(pout_ptr.get(),static_cast<size_t>(nOutSize));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
std::cout<<" carmaker work. nres is 1, but no data. please check."<<std::endl;
|
|
|
+ snprintf(strlog,256,"carmaker work. nres is 1, but no data. please check.");
|
|
|
+ Log(strlog);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -88,14 +119,24 @@ void carmakerwork::threadwork()
|
|
|
Status status = stub_->convertwork(&context, request, &reply);
|
|
|
if (status.ok()) {
|
|
|
|
|
|
+ if(request.mnres() != 0)
|
|
|
+ {
|
|
|
+ snprintf(strlog,256,"Complete workid:%d nres:%lld. uploaded to server.",request.workid(),request.mnres());
|
|
|
+ Log(strlog);
|
|
|
+ }
|
|
|
+
|
|
|
if(reply.mnres() == 1)
|
|
|
{
|
|
|
+ snprintf(strlog,256,"Get A request workid:%d InputName:%s OutputName:%s CMD:%s InputSize:%d",reply.workid(),
|
|
|
+ reply.strinputname().data(),reply.stroutputname().data(),reply.strcmd().data(),reply.data_input().size());
|
|
|
+ Log(strlog);
|
|
|
+
|
|
|
nnowork = 0;
|
|
|
nWorkID = reply.workid();
|
|
|
std::shared_ptr<char> pinput_ptr = nullptr;
|
|
|
int ninputsize = static_cast<int>(reply.data_input().size()) ;
|
|
|
pinput_ptr = std::shared_ptr<char>(new char[ninputsize]);
|
|
|
- memcpy(pinput_ptr.get(),reply.data_input().data(),ninputsize);
|
|
|
+ memcpy(pinput_ptr.get(),reply.data_input().data(),static_cast<size_t>(ninputsize) );
|
|
|
nRes = ExecCarmakerWork(nWorkID,reply.strinputname(),reply.stroutputname(),reply.strcmd(),
|
|
|
pinput_ptr,ninputsize,pout_ptr,nOutSize);
|
|
|
}
|
|
@@ -114,6 +155,21 @@ void carmakerwork::threadwork()
|
|
|
<< std::endl;
|
|
|
std::cout<<"RPC failed"<<std::endl;
|
|
|
|
|
|
+ snprintf(strlog,256,"RPC Fail. status code: %d error msg:%s",status.error_code(),status.error_message().data());
|
|
|
+ Log(strlog);
|
|
|
+
|
|
|
+ if(status.error_code() == 4)
|
|
|
+ {
|
|
|
+ std::cout<<" RPC Exceed Time. Create New Stub_"<<std::endl;
|
|
|
+ channel = grpc::CreateCustomChannel(
|
|
|
+ mstrserver, grpc::InsecureChannelCredentials(),cargs);
|
|
|
+
|
|
|
+ stub_ = iv::ipg::Carmaker::NewStub(channel);
|
|
|
+
|
|
|
+ snprintf(strlog,256," RPC Exceed Time. Create New Stub_");
|
|
|
+ Log(strlog);
|
|
|
+ }
|
|
|
+
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
|
|
|
|
|
|
|