#include "cardMgr.h" #include "bindmorecard.h" #include "common.h" #include "common_tool.h" cardMgr::cardMgr() :m_queue(2048) ,m_bstop(false) { m_pThread.reset(new std::thread(std::bind(&cardMgr::run,this))); m_cf[0] = std::make_shared(this); m_cf[1] = std::make_shared(this); } void cardMgr::run() { while(!m_bstop) { Msg m; m_queue.get(m); onMessage(m); } } void cardMgr::onMessage(const Msg &m) { switch(m.cmd) { case CMD_CLEAR: clear(m.cardid); break; case CMD_HANDLE: handleMessage(m); break; default: break; } } void cardMgr::clear(uint64_t cardid) { auto v = getcard(cardid); for(const auto & cid:v) { log_info("LemonHash_up_mine:%lu&%lu",cardid,cid); uint64_t id = MyHash{}(cardid,cid); erase(id); m_cgraph.remove_edge(cardid,cid); } } void cardMgr::handleMessage(const Msg &m) { //更新卡位置信息 m_glist.update(m.x,m.y,m.cardid); //排除车卡 目前车卡不会进来 //if(tool_other::is_vehicle( m.type) ) return; //查找该卡1个像素点内得卡号信息(有车卡) std::vector rc=m_glist.find_near(m.cardid,1); //打印找到得卡数据信息 log_info("Hash+..%d,size:%d,(%d,%d)",m.cardid,rc.size(),m.x,m.y); std::map map1; std::map map2; for(int i = m_cf.size()-1;i>=0;i--) { map1.clear();map2.clear(); map1=m_cf[i]->selectcard(rc,m.cardid); map2=m_cf[i]->setCT(m.cardid); std::copy(map1.begin(),map1.end(),std::inserter(map2,map2.end())); if (i == 1 && !map2.empty()) erase(map2); if (!map2.empty()) { for(const auto x:map2) log_info("---LemonHash_call_event--[%s]%s",i?"Remote":"Closer",x.second.c_str()); } if (!rc.empty()) { std::string s ; s = m_cf[i]->InfoMessage(); log_info("---LemonHash----[%s]%s",i?"Remote":"Closer",s.c_str()); } } } void cardMgr::erase(const std::map &m) { for(auto &p:m) erase(p.first); } void cardMgr::erase(uint64_t id) { for(const auto & t:m_cf) t->erase(id); } cardMgr::~cardMgr() { m_bstop = true; m_pThread->join(); } cardMgr* cardMgr::instance() { static cardMgr cd; return &cd; }