123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- //
- // Created by zx on 2020/6/18.
- //
- #include <fcntl.h>
- #include <iostream>
- #include <glog/logging.h>
- #include "TaskQueue/TQFactory.h"
- #include "./communication/communication_socket_base.h"
- #include "StoreProcessTask.h"
- #include "system_communicator.h"
- #include "Locate_communicator.h"
- #include "threadSafeQueue.h"
- #include "pathcreator.h"
- #include <glog/logging.h>
- #include <Parkspace_communicator.h>
- //using google::protobuf::io::FileInputStream;
- //using google::protobuf::io::FileOutputStream;
- using google::protobuf::io::ZeroCopyInputStream;
- using google::protobuf::io::CodedInputStream;
- using google::protobuf::io::ZeroCopyOutputStream;
- using google::protobuf::io::CodedOutputStream;
- using google::protobuf::Message;
- ///线程池
- tq::IQueue* g_pthread_queue = nullptr;
- GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size);
- void init_glog();
- Error_manager Init_communicators();
- int main(int argc,char* argv[])
- {
- init_glog();
- Error_manager code=Init_communicators();
- if(code!=SUCCESS)
- {
- LOG(ERROR)<<code.to_string();
- }
- g_pthread_queue= tq::TQFactory::CreateDefaultQueue();
- g_pthread_queue->Start(12);
- //std::thread* pthread=new std::thread(delete_thread);
- StoreProcessTask* task=new StoreProcessTask();
- int N=0;
- while(1)
- {
- StoreProcessTask* task=new StoreProcessTask();
- char license[255]={0};
- int rd=rand()%900000+100000;
- sprintf(license,"鄂A%d",rd);
- task->init_task(rand(),rand()%6,license);
- if(g_pthread_queue->TaskCount()<1000)
- {
- g_pthread_queue->AddTask(task);
- N++;
- printf("task size / pushed size : %04d / %08d license : %s\n",g_pthread_queue->TaskCount(),N,license);
- }
- else {
- delete task;
- }
- usleep(1);
- }
- g_pthread_queue->WaitForFinish();
- delete g_pthread_queue;
- return 0;
- }
- Error_manager Init_communicators()
- {
- Error_manager code;
- if(Locate_communicator::get_instance_pointer()== nullptr)
- return FAILED;
- code=Locate_communicator::get_instance_pointer()->communication_connect("tcp://127.0.0.1:4444");
- if(code!=SUCCESS)
- {
- return code;
- }
- Locate_communicator::get_instance_pointer()->communication_run();
- //
- if(Parkspace_communicator::get_instance_pointer()== nullptr)
- return FAILED;
- code=Parkspace_communicator::get_instance_pointer()->communication_connect("tcp://192.168.2.139:7001");
- if(code!=SUCCESS)
- {
- return code;
- }
- Parkspace_communicator::get_instance_pointer()->communication_run();
- ///最后初始化与终端通讯的对象
- if(System_communicator::get_instance_pointer()== nullptr)
- return FAILED;
- usleep(1000*3000);
- return SUCCESS;
- }
- GOOGLE_GLOG_DLL_DECL void shut_down_logging(const char* data, int size)
- {
- time_t tt;
- time( &tt );
- tt = tt + 8*3600; // transform the time zone
- tm* t= gmtime( &tt );
- char buf[255]={0};
- sprintf(buf,"./%d%02d%02d-%02d%02d%02d-dump.txt",
- t->tm_year + 1900,
- t->tm_mon + 1,
- t->tm_mday,
- t->tm_hour,
- t->tm_min,
- t->tm_sec);
- FILE* tp_file=fopen(buf,"w");
- fprintf(tp_file,data,strlen(data));
- fclose(tp_file);
- }
- void init_glog()
- {
- time_t tt = time(0);//时间cuo
- struct tm* t = localtime(&tt);
- char strYear[255]={0};
- char strMonth[255]={0};
- char strDay[255]={0};
- sprintf(strYear,"%04d", t->tm_year+1900);
- sprintf(strMonth,"%02d", t->tm_mon+1);
- sprintf(strDay,"%02d", t->tm_mday);
- char buf[255]={0};
- getcwd(buf,255);
- char strdir[255]={0};
- sprintf(strdir,"%s/log/%s/%s/%s", buf,strYear,strMonth,strDay);
- PathCreator creator;
- creator.Mkdir(strdir);
- char logPath[255] = { 0 };
- sprintf(logPath, "%s/", strdir);
- FLAGS_max_log_size = 100;
- FLAGS_logbufsecs = 0;
- google::InitGoogleLogging("LidarMeasurement");
- google::SetStderrLogging(google::INFO);
- google::SetLogDestination(0, logPath);
- google::SetLogFilenameExtension("zxlog");
- google::InstallFailureSignalHandler();
- google::InstallFailureWriter(&shut_down_logging);
- FLAGS_colorlogtostderr = true; // Set log color
- FLAGS_logbufsecs = 0; // Set log output speed(s)
- FLAGS_max_log_size = 1024; // Set max log file size(GB)
- FLAGS_stop_logging_if_full_disk = true;
- }
|