1
0

module_mgr.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include"module_other_alarm.h"
  17. class module_mgr: public singleton_base<module_mgr>
  18. {
  19. private:
  20. friend class singleton_base<module_mgr>;
  21. module_mgr()
  22. {
  23. }
  24. public:
  25. /**
  26. * @brief 注册web回调函数,读配置文件,启动向web发送线程
  27. */
  28. static void init(config_file& config, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
  29. {
  30. module_web::instance()->init(config, MsgFuncList);
  31. module_call::instance()->init(config);
  32. }
  33. /**
  34. * @brief 启动线程start:向web发送事件
  35. */
  36. static void start()
  37. {
  38. module_over_speed_vehicle::instance()->init_vehicle_category_from_db();
  39. //init_attendance_from_db();
  40. module_attendance_vehicle::instance()->init_attendance_area_from_db();
  41. module_web::instance()->start();
  42. module_call::instance()->start();
  43. }
  44. /**
  45. * @brief 结束线程stop
  46. */
  47. static void stop()
  48. {
  49. module_web::instance()->stop();
  50. module_call::instance()->stop();
  51. }
  52. static void do_status(STATUS_CARD st, uint32_t card_id, int32_t type)
  53. {
  54. auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
  55. if(!card_ptr)
  56. {
  57. log_error("卡不存在card_id=%d", card_id);
  58. return;
  59. }
  60. if(STATUS_HELP == st)
  61. {
  62. module_call_help::instance()->rev_from_card_help(card_ptr);
  63. }
  64. if(STATUS_CALL == st)
  65. {
  66. module_call::instance()->rev_from_card_resp(card_ptr);
  67. }
  68. if(STATUS_POWER_LOWER_SERIOUS == st)
  69. {
  70. module_other_alarm::power_lower_serious(card_ptr);
  71. }
  72. if(STATUS_POWER_NOMARL == st)
  73. {
  74. module_other_alarm::power_nomarl(card_ptr);
  75. }
  76. }
  77. //private:
  78. // static void init_attendance_from_db()
  79. // {
  80. // const char *sql = "select card_id, start_time, end_time from rt_att_staff;";
  81. // std::string Error;
  82. // YADB::CDBResultSet DBRes;
  83. // sDBConnPool.Query(sql,DBRes,Error);
  84. // uint64_t nCount = DBRes.GetRecordCount( Error );
  85. // if (nCount > 0)
  86. // {
  87. // log_info( "init_attendance. The record count=%d\n", nCount );
  88. // while ( DBRes.GetNextRecod(Error) )
  89. // {
  90. // std::string card_id;
  91. // DBRes.GetField( "card_id",card_id, Error );
  92. // std::string end_time;
  93. // DBRes.GetField( "end_time",end_time, Error );
  94. // if(end_time.empty())
  95. // {
  96. // uint32_t id = tool_other::id64_to_id(card_id);
  97. // int32_t type = tool_other::id64_to_type(card_id);
  98. // auto card_ptr = card_list::instance()->get(card_list::to_id64(type, id));
  99. // if(card_ptr)
  100. // {
  101. // std::string start_time;
  102. // DBRes.GetField( "start_time",start_time, Error );
  103. // auto mine_tool_ptr = card_ptr->get_mine_tool();
  104. // mine_tool_ptr->m_attendance_start_time = tool_time::to_time_ex(start_time);
  105. // mine_tool_ptr->m_stat_attendance = AS_ATTENDANCE;
  106. // //std_debug("%s",
  107. // // tool_time::to_str_ex(tool_time::to_ms(site_area_ptr->m_attendance_start_time)).c_str());
  108. // }
  109. // }
  110. // }
  111. // }
  112. // }
  113. };
  114. #endif // MODULE_MGR_H