module_mgr.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #ifndef MODULE_MGR_H
  2. #define MODULE_MGR_H
  3. /**
  4. * @brief 业务模块的管理类,包括:
  5. * 1、初始化(init:注册web回调函数,读数据库初始化事件列表)
  6. * 2、启动线程start:向web发送事件
  7. * 3、结束线程stop
  8. * @author 戴月腾
  9. * @date 2018-08-25
  10. */
  11. #include"module_web.h"
  12. #include"module_area.h"
  13. #include"module_call_help.h"
  14. #include"module_call.h"
  15. #include"module_over_speed_vehicle.h"
  16. class module_mgr: public singleton_base<module_mgr>
  17. {
  18. private:
  19. friend class singleton_base<module_mgr>;
  20. module_mgr()
  21. {
  22. }
  23. public:
  24. /**
  25. * @brief 注册web回调函数,读配置文件,启动向web发送线程
  26. */
  27. static void init(config_file& config, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
  28. {
  29. module_web::instance()->init(config, MsgFuncList);
  30. module_call::instance()->init(config);
  31. }
  32. /**
  33. * @brief 启动线程start:向web发送事件
  34. */
  35. static void start()
  36. {
  37. module_over_speed_vehicle::instance()->init_vehicle_category_from_db();
  38. //init_attendance_from_db();
  39. module_attendance_vehicle::instance()->init_attendance_area_from_db();
  40. module_web::instance()->start();
  41. module_call::instance()->start();
  42. }
  43. /**
  44. * @brief 结束线程stop
  45. */
  46. static void stop()
  47. {
  48. module_web::instance()->stop();
  49. module_call::instance()->stop();
  50. }
  51. static void do_status(STATUS_CARD st, uint32_t card_id, int32_t type)
  52. {
  53. auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
  54. if(!card_ptr)
  55. {
  56. log_error("卡不存在card_id=%d", card_id);
  57. return;
  58. }
  59. if(STATUS_HELP == st)
  60. {
  61. module_call_help::instance()->rev_from_card_help(card_ptr);
  62. }
  63. else if(STATUS_CALL == st)
  64. {
  65. module_call::instance()->rev_from_card_resp(card_ptr);
  66. }
  67. }
  68. //private:
  69. // static void init_attendance_from_db()
  70. // {
  71. // const char *sql = "select card_id, start_time, end_time from rt_att_staff;";
  72. // std::string Error;
  73. // YADB::CDBResultSet DBRes;
  74. // sDBConnPool.Query(sql,DBRes,Error);
  75. // uint64_t nCount = DBRes.GetRecordCount( Error );
  76. // if (nCount > 0)
  77. // {
  78. // log_info( "init_attendance. The record count=%d\n", nCount );
  79. // while ( DBRes.GetNextRecod(Error) )
  80. // {
  81. // std::string card_id;
  82. // DBRes.GetField( "card_id",card_id, Error );
  83. // std::string end_time;
  84. // DBRes.GetField( "end_time",end_time, Error );
  85. // if(end_time.empty())
  86. // {
  87. // uint32_t id = tool_other::id64_to_id(card_id);
  88. // int32_t type = tool_other::id64_to_type(card_id);
  89. // auto card_ptr = card_list::instance()->get(card_list::to_id64(type, id));
  90. // if(card_ptr)
  91. // {
  92. // std::string start_time;
  93. // DBRes.GetField( "start_time",start_time, Error );
  94. // auto mine_tool_ptr = card_ptr->get_mine_tool();
  95. // mine_tool_ptr->m_attendance_start_time = tool_time::to_time_ex(start_time);
  96. // mine_tool_ptr->m_stat_attendance = AS_ATTENDANCE;
  97. // //std_debug("%s",
  98. // // tool_time::to_str_ex(tool_time::to_ms(site_area_ptr->m_attendance_start_time)).c_str());
  99. // }
  100. // }
  101. // }
  102. // }
  103. // }
  104. };
  105. #endif // MODULE_MGR_H