decode.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /******************************************************************
  2. ** Copyright (c) 2009 Wuhan Mozit Technology Co., Ltd .
  3. ** FileName: decode.c
  4. ** Author: BigHead
  5. ** Mail: jsrenyw@sohu.com
  6. ** Date: 2007-5-31 下午07:17:32
  7. ** Editor: YellowBug
  8. ** Date: 2010-5-26 13:34
  9. ** Version: 2010-5-26
  10. ** File Description: 后台框架结构
  11. ******************************************************************/
  12. #include "../include/decode.h"
  13. #include "../core/core.h"
  14. /******************************************************************
  15. * Function Name: RepeatRun
  16. * Arguments:
  17. * Return Value: void
  18. * Editor: YellowBug
  19. * Date: 2010-5-26
  20. * Description: 负责监测用户状态,发送公告等
  21. ******************************************************************/
  22. void RepeatRun(void)
  23. {
  24. // 该线程关闭, 目前不在启动
  25. log("This is in RepeatRun! pid=%d tid=%ld lwpid=%lu\n", getpid(), pthread_self(), syscall(SYS_gettid));
  26. while (1)
  27. {
  28. sleep(10);
  29. }
  30. }
  31. /******************************************************************
  32. * Function Name: AlarmGateway
  33. * Arguments:
  34. * Return Value: void
  35. * Date: 2023-12-5
  36. * Editor: cc
  37. * Description: 扫描数据库,处理网关报警
  38. ******************************************************************/
  39. void AlarmGateway(void)
  40. {
  41. unsigned int nowTime;
  42. //static MYSQL *_db = NULL;
  43. int ret = 0;
  44. unsigned int lastHeartTime = 0;
  45. log("This is in AlarmGateway decode! pid=%d tid=%ld lwpid=%lu\n", getpid(), pthread_self(), syscall(SYS_gettid));
  46. while (1)
  47. {
  48. usleep(GAME_HEART_BEAT_g);
  49. nowTime = timeGloble_g;
  50. //每隔30s扫描数据库设备状态表
  51. if (nowTime-lastHeartTime >30 )
  52. {
  53. CoreAlarmGateway();
  54. lastHeartTime = nowTime;
  55. log("AlarmGateway used:%ds=(%d-%d)\n", timeGloble_g - nowTime, timeGloble_g, nowTime);
  56. fflush(stdout);
  57. }
  58. }
  59. log("AlarmGateway thread be closed!\n");
  60. exit(0);
  61. }
  62. /******************************************************************
  63. * Function Name: AlarmNode
  64. * Arguments:
  65. * Return Value: void
  66. * Date: 2023-12-8
  67. * Editor: cc
  68. * Description: 扫描数据库,处理节点告警
  69. ******************************************************************/
  70. void AlarmNode(void)
  71. {
  72. unsigned int nowTime;
  73. //static MYSQL *_db = NULL;
  74. int ret = 0;
  75. unsigned int lastHeartTime = 0;
  76. log("This is in AlarmNode decode! pid=%d tid=%ld lwpid=%lu\n", getpid(), pthread_self(), syscall(SYS_gettid));
  77. while (1)
  78. {
  79. usleep(GAME_HEART_BEAT_g);
  80. nowTime = timeGloble_g;
  81. //每隔30s扫描数据库设备状态表
  82. if (nowTime-lastHeartTime >30 )
  83. {
  84. CoreAlarmNode();
  85. lastHeartTime = nowTime;
  86. log("AlarmNode used:%ds=(%d-%d)\n", timeGloble_g - nowTime, timeGloble_g, nowTime);
  87. fflush(stdout);
  88. }
  89. }
  90. log("AlarmNode thread be closed!\n");
  91. exit(0);
  92. }
  93. /******************************************************************
  94. * Function Name: pthTime
  95. * Arguments: void
  96. * Return Value: void
  97. * Date: 2006-11-2
  98. * Description: 时间计数器,每秒一次心跳,每秒自加一次
  99. * 以单独线程方式运行
  100. ******************************************************************/
  101. void pthTime(void)
  102. {
  103. static struct timeval tv;
  104. timeGloble_g = timeBegin_g = time(NULL);
  105. srand(time(NULL) + getpid() + random() + timeGloble_g);
  106. sleep(1);
  107. log("在pthTime 中 初始化随机种子完毕,请勿再次初始化随机\n");
  108. srandom(time(NULL) + getpid() + random() + random());
  109. log("This is in pthTime 心跳计数现场! pid=%d tid=%ld lwpid=%lu\n", getpid(), pthread_self(), syscall(SYS_gettid));
  110. gettimeofday(&tv, NULL);
  111. timeGloble_g = tv.tv_sec;
  112. while (1)
  113. {
  114. //edit by liuqing 20181201 调整精度 从原来的1s调整到0.3s 5hz
  115. usleep(200000);
  116. gettimeofday(&tv, NULL);
  117. timeGloble_g = tv.tv_sec;
  118. }
  119. }