three_rates_impl.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #ifndef THREE_RATES_IMPL_H
  2. #define THREE_RATES_IMPL_H
  3. #include "db_api/CDBSingletonDefine.h"
  4. #include "struct_def.h"
  5. #include "three_rates.h"
  6. #include "worktime_rate.h"
  7. #include "tr_queue.h"
  8. #include "trm_drivingface_module.h"
  9. #include "vehicle_driver_alarm.h"
  10. #include "drivingface_alarm.h"
  11. #include <mutex>
  12. #include <memory>
  13. #include <thread>
  14. #include <iostream>
  15. #include <boost/lockfree/queue.hpp>
  16. using namespace std;
  17. class operating_rate;
  18. class regularcycle_rate;
  19. class common_data;
  20. class three_rates_impl : public three_rates
  21. {
  22. private:
  23. three_rates_impl() {};
  24. three_rates_impl(const three_rates_impl &);
  25. three_rates_impl& operator = (const three_rates_impl &);
  26. protected:
  27. class proxy_creator
  28. {
  29. public:
  30. proxy_creator()
  31. {
  32. three_rates_impl::_instance();
  33. }
  34. };
  35. static proxy_creator m_proxy;
  36. public:
  37. static three_rates_impl* _instance();
  38. protected:
  39. bool m_bstop;
  40. std::mutex m_thread_mutex;
  41. std::unique_ptr<std::thread> m_pthree_rates_thread;
  42. YADB::_DB_POOL_SETTING_ m_db_setting;
  43. std::shared_ptr<operating_rate> m_poperating_rate;
  44. std::shared_ptr<regularcycle_rate> m_pregularcycle_rate;
  45. std::shared_ptr<vehicle_driver_alarm> m_pvehicle_driver_alarm;
  46. std::shared_ptr<DrivingFaceAlarm> m_drivingface_alarm;
  47. long long m_time;
  48. tr_queue *p_tr_queue ;
  49. boost::lockfree::queue<card_pos,boost::lockfree::capacity<40000>> m_boost_queue;
  50. std::vector<ChangedDBDate> m_DB_Changed_list;
  51. std::mutex m_mutex;
  52. // 工作面数据
  53. std::shared_ptr<common_data> m_common_data;
  54. // 作为SO运行
  55. bool m_runSo = true;
  56. public:
  57. std::shared_ptr<common_data> &get_common_data() {
  58. return m_common_data;
  59. }
  60. void setRunSoFile(bool bRun) { m_runSo = bRun;}
  61. public:
  62. /*
  63. * Functon: Init the three_rates module
  64. * Parameters:
  65. * init_param& para - in&out, three_rates parameters
  66. * Returns: void
  67. * Throws: void
  68. */
  69. virtual void init(const init_para& para, const db_para& dpara );
  70. /*
  71. * Functon: Start the three_rates module
  72. * Parameters: void
  73. * Returns: void
  74. * Throws: void
  75. */
  76. virtual void start();
  77. /*
  78. * Functon: Stop the three_rates module
  79. * Parameters: void
  80. * Returns: void
  81. * Throws: void
  82. */
  83. virtual void stop();
  84. /*
  85. * Functon: Input the located datas
  86. * Parameters:
  87. * card_pos& pos - in, position informations
  88. * Returns: void
  89. * Throws: void
  90. */
  91. virtual void put(const card_pos& pos);
  92. /*
  93. * Functon: Enter one area
  94. * Parameters:
  95. * card_pos& pos - in, the located datas
  96. * area_data& area - in, the area informations
  97. * Returns: void
  98. * Throws: void
  99. */
  100. virtual void enter_area(std::shared_ptr<card_pos> &card_ptr, std::shared_ptr<area_data> &area_ptr);
  101. /*
  102. * Functon: Leave one area
  103. * Parameters:
  104. * card_pos& pos - in, the located datas
  105. * area_data& area - in, the area informations
  106. * Returns: void
  107. * Throws: void
  108. */
  109. virtual void leave_area(std::shared_ptr<card_pos> &card_ptr, std::shared_ptr<area_data> &area_ptr);
  110. /*
  111. * 获取掘进机或者采煤机的开机状态
  112. */
  113. virtual bool GetVehicleState(int vehicleId);
  114. /*
  115. * Functon: thread function
  116. * Parameters: void
  117. * Returns: void
  118. * Throws: void
  119. */
  120. void run();
  121. /*
  122. * Functon: Init database settings
  123. * Parameters: void
  124. * Returns: int, returns 0 normally, otherwise it returns 1
  125. * Throws: void
  126. */
  127. int init_db(const db_para& dpara);
  128. /*
  129. * Functon: WEB通知数据有更新
  130. * Parameters:
  131. * std::string webname, - in, 更新表名
  132. * std::string param - in, 更新表内容(id)
  133. * edit_type_id,0 新增,1 修改,2 删除
  134. * Returns: void
  135. * Throws: void
  136. */
  137. virtual void update_db_data(const std::string& webname, const std::string& param,int edit_type_id);
  138. void deal_db_data_changed(const ChangedDBDate& Db);
  139. private:
  140. worktime m_worktime;
  141. trm_drivingface_module m_drivingface_module;
  142. public:
  143. //超时关机时间阈值
  144. int m_shutdown_timeout_threshold;
  145. //卡同步的次数
  146. std::map<int,int> m_card_sync_num;
  147. //添加次数-id对应的消息处理次数
  148. void add_cardsyncNum(int id);
  149. public:
  150. // 输入日志ID==log.ini中对应的日志属性(日志文件等)
  151. static int g_three_rates_log_id;
  152. // 更新数据的日志ID
  153. static int g_three_rates_sql_log_id;
  154. };
  155. #define G_CommonData three_rates_impl::_instance()->get_common_data()
  156. #endif