card.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef _CARD_HPP_
  2. #define _CARD_HPP_
  3. #include <thread>
  4. #include <ev++.h>
  5. #include "card_base.h"
  6. #include "write-copy.h"
  7. #define CARD_LOST_TIME_OUT (30*1000)
  8. struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_base>>
  9. {
  10. ///id64=-1为初始化所有卡, id格式为:10000001016
  11. void init_staffer(int64_t id64);
  12. ///id64=-1为初始化所有卡, id格式为:10000001016
  13. void init_vehicle(int64_t id64);
  14. //void init_staffer();
  15. //void init_vehicle();
  16. uint64_t getId(uint32_t cardid,uint64_t);
  17. void on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_history);
  18. void init_card_from_db();
  19. void load_his_card_postion_vehicle();
  20. void load_his_card_postion_staff();
  21. void load_his_card_postion_from_db();
  22. std::unique_ptr<std::thread> m_pThread;
  23. bool m_bflag=false;
  24. void run()
  25. {
  26. m_pThread.reset(new std::thread(std::bind(&card_list::onTimer,this)));
  27. }
  28. // TODO : 停止进程
  29. void onStopRun();
  30. void onTimer();
  31. /// (类型<<32)|卡号
  32. //公用函数最好不要使用成员函数,改成公共函数。
  33. static uint64_t to_id64(int32_t type, uint32_t id)
  34. {
  35. return (static_cast<uint64_t>(type)<<32)|id;
  36. }
  37. static std::string to_id64_str(int32_t type, uint32_t id)
  38. {
  39. char sql[15] = {'\0'};
  40. sprintf(sql, "%03d%010d", type, id);
  41. return std::string(sql);
  42. }
  43. ~card_list(){m_bflag=true;}
  44. };
  45. #endif