cardMgr.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "cardMgr.h"
  2. #include "bindmorecard.h"
  3. #include "common.h"
  4. #include "common_tool.h"
  5. cardMgr::cardMgr()
  6. :m_queue(2048)
  7. ,m_bstop(false)
  8. {
  9. m_pThread.reset(new std::thread(std::bind(&cardMgr::run,this)));
  10. m_cf[0] = std::make_shared<CloserCardFactory>(this);
  11. m_cf[1] = std::make_shared<RemoteCardFactory>(this);
  12. }
  13. void cardMgr::run()
  14. {
  15. while(!m_bstop)
  16. {
  17. Msg m;
  18. m_queue.get(m);
  19. onMessage(m);
  20. }
  21. }
  22. void cardMgr::onMessage(const Msg &m)
  23. {
  24. switch(m.cmd)
  25. {
  26. case CMD_CLEAR:
  27. clear(m.cardid);
  28. break;
  29. case CMD_HANDLE:
  30. handleMessage(m);
  31. break;
  32. default:
  33. break;
  34. }
  35. }
  36. void cardMgr::clear(uint64_t cardid)
  37. {
  38. auto v = getcard(cardid);
  39. for(const auto & cid:v)
  40. {
  41. log_info("LemonHash_up_mine:%lu&%lu",cardid,cid);
  42. uint64_t id = MyHash{}(cardid,cid);
  43. erase(id);
  44. m_cgraph.remove_edge(cardid,cid);
  45. }
  46. }
  47. void cardMgr::handleMessage(const Msg &m)
  48. {
  49. //更新卡位置信息
  50. m_glist.update(m.x,m.y,m.cardid);
  51. //排除车卡 目前车卡不会进来
  52. //if(tool_other::is_vehicle( m.type) ) return;
  53. //查找该卡1个像素点内得卡号信息(有车卡)
  54. std::vector<uint64_t> rc=m_glist.find_near(m.cardid,1);
  55. //打印找到得卡数据信息
  56. log_info("Hash+..%d,size:%d,(%d,%d)",m.cardid,rc.size(),m.x,m.y);
  57. std::map<uint64_t,std::string> map1;
  58. std::map<uint64_t,std::string> map2;
  59. for(int i = m_cf.size()-1;i>=0;i--)
  60. {
  61. map1.clear();map2.clear();
  62. map1=m_cf[i]->selectcard(rc,m.cardid);
  63. map2=m_cf[i]->setCT(m.cardid);
  64. std::copy(map1.begin(),map1.end(),std::inserter(map2,map2.end()));
  65. if (i == 1 && !map2.empty())
  66. erase(map2);
  67. if (!map2.empty())
  68. {
  69. for(const auto x:map2)
  70. log_info("---LemonHash_call_event--[%s]%s",i?"Remote":"Closer",x.second.c_str());
  71. }
  72. if (!rc.empty())
  73. {
  74. std::string s ;
  75. s = m_cf[i]->InfoMessage();
  76. log_info("---LemonHash----[%s]%s",i?"Remote":"Closer",s.c_str());
  77. }
  78. }
  79. }
  80. void cardMgr::erase(const std::map<uint64_t,std::string> &m)
  81. {
  82. for(auto &p:m)
  83. erase(p.first);
  84. }
  85. void cardMgr::erase(uint64_t id)
  86. {
  87. for(const auto & t:m_cf)
  88. t->erase(id);
  89. }
  90. cardMgr::~cardMgr()
  91. {
  92. m_bstop = true;
  93. m_pThread->join();
  94. }
  95. cardMgr* cardMgr::instance()
  96. {
  97. static cardMgr cd;
  98. return &cd;
  99. }