EventManager.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. #include "stdafx.h"
  2. #include "kernel.h"
  3. #include "sharedefine.h"
  4. CAlarmEvent::CAlarmEvent()
  5. {
  6. GetLocalTime(&time);
  7. }
  8. /////////////////////////////////////////////////////////////////////////////
  9. CEventServer::CEventServer()
  10. {
  11. InitializeCriticalSection( &m_cs );
  12. }
  13. CEventServer::~CEventServer()
  14. {
  15. DeleteCriticalSection( &m_cs );
  16. }
  17. void CEventServer::AddNewEvent(CAlarmEvent* event)
  18. {
  19. EnterCriticalSection( &m_cs );
  20. eventList.AddHead(event);
  21. LeaveCriticalSection( &m_cs );
  22. }
  23. CAlarmEvent* CEventServer::GetUnconfirmEvent()
  24. {
  25. //POSITION pos = eventList.GetTailPosition();
  26. //while( pos != NULL )
  27. //{
  28. // CAlarmEvent* event= eventList.GetPrev(pos);
  29. // //SYSTEMTIME st;
  30. // //GetLocalTime( &st );
  31. // //CTime time1(st);
  32. // //CTime time2(event->time);
  33. // //CTimeSpan spantime = time1 - time2;
  34. // //int nSecNum = spantime.GetSeconds() + spantime.GetMinutes()*60 + spantime.GetHours()*60*60;
  35. // if( (0==event->nConfirm || 2==event->nConfirm) )//&& nSecNum >= event->nIdentifyTime )
  36. // {
  37. // return event;
  38. // }
  39. // //if( 0==event->nConfirm || 2==event->nConfirm)
  40. // //{
  41. // // return event;
  42. // //}
  43. //}
  44. return NULL;
  45. }
  46. CAlarmEvent* CEventServer::GetUnconfirmEventForLoopPlaySound( CAlarmEvent *pEvent )
  47. {
  48. //bool bFirst=false;
  49. //POSITION pos = eventList.GetTailPosition();
  50. //while( pos != NULL )
  51. //{
  52. // CAlarmEvent* event= eventList.GetPrev(pos);
  53. // //SYSTEMTIME st;
  54. // //GetLocalTime( &st );
  55. // //CTime time1(st);
  56. // //CTime time2(event->time);
  57. // //CTimeSpan spantime = time1 - time2;
  58. // //int nSecNum = spantime.GetSeconds() + spantime.GetMinutes()*60 + spantime.GetHours()*60*60;
  59. // if( pEvent )
  60. // {
  61. // if( pEvent->nVarID==event->nVarID )
  62. // {
  63. // bFirst = true;
  64. // }
  65. // else if( bFirst )//&& (0==event->nConfirm || 2==event->nConfirm) && nSecNum >= event->nIdentifyTime )
  66. // {
  67. // return event;
  68. // }
  69. // }
  70. // else
  71. // {
  72. // if( (0==event->nConfirm || 2==event->nConfirm) )//&& nSecNum >= event->nIdentifyTime )
  73. // {
  74. // return event;
  75. // }
  76. // }
  77. // Sleep( 200 );
  78. //}
  79. ////下面是找到了pEvent这个事件,但后面的没有满足条件的,所以要从头开始找
  80. //if( bFirst )
  81. //{
  82. // pos = eventList.GetTailPosition();
  83. // while( pos != NULL )
  84. // {
  85. // CAlarmEvent* event= eventList.GetPrev(pos);
  86. // //SYSTEMTIME st;
  87. // //GetLocalTime( &st );
  88. // //CTime time1(st);
  89. // //CTime time2(event->time);
  90. // //CTimeSpan spantime = time1 - time2;
  91. // //int nSecNum = spantime.GetSeconds() + spantime.GetMinutes()*60 + spantime.GetHours()*60*60;
  92. // if( (0==event->nConfirm || 2==event->nConfirm) )//&& nSecNum >= event->nIdentifyTime )
  93. // {
  94. // return event;
  95. // }
  96. // Sleep( 200 );
  97. // }
  98. //}
  99. return NULL;
  100. }
  101. CAlarmEvent* CEventServer::GetNewEvent()
  102. {
  103. POSITION pos = eventList.GetTailPosition();
  104. while( pos != NULL )
  105. {
  106. CAlarmEvent* event= eventList.GetPrev(pos);
  107. //SYSTEMTIME st;
  108. //GetLocalTime( &st );
  109. //CTime time1(st);
  110. //CTime time2(event->time);
  111. //CTimeSpan spantime = time1 - time2;
  112. //int nSecNum = spantime.GetSeconds() + spantime.GetMinutes()*60 + spantime.GetHours()*60*60;
  113. //if( nSecNum >= event->nIdentifyTime &&
  114. if( 0==event->nGet )
  115. {
  116. //LOG4C((LOG_NOTICE, "报警内容:%s 辨识时间:%d", event->strContent,event->nIdentifyTime));
  117. //GetLocalTime( &event->time );
  118. event->nGet = true;
  119. return event;
  120. }
  121. //LOG4C((LOG_NOTICE, "%s %d %d ", event->strContent,nSecNum,event->nIdentifyTime ));
  122. //if( !event->bGet )
  123. //{
  124. // event->bGet = true;
  125. // return event;
  126. //}
  127. }
  128. return NULL;
  129. }
  130. void CEventServer::DeleteOneEvent( CString strUid, int nVarID, int nStatus )
  131. {
  132. EnterCriticalSection( &m_cs );
  133. POSITION pos = eventList.GetHeadPosition();
  134. while( pos != NULL )
  135. {
  136. POSITION pos1 = pos;
  137. CAlarmEvent* event= eventList.GetNext(pos);
  138. if( !event->strUid.Compare(strUid) && event->nVarID == nVarID && event->nStatus == nStatus )
  139. {
  140. delete event;
  141. eventList.RemoveAt(pos1);
  142. break;
  143. }
  144. }
  145. LeaveCriticalSection( &m_cs );
  146. }
  147. void CEventServer::DeleteOneEvent( int iIndex )
  148. {
  149. EnterCriticalSection( &m_cs );
  150. int nIndex=0;
  151. POSITION pos = eventList.GetTailPosition();
  152. while( pos != NULL )
  153. {
  154. POSITION pos1 = pos;
  155. CAlarmEvent* event= eventList.GetPrev(pos);
  156. if( iIndex==nIndex )
  157. {
  158. delete event;
  159. eventList.RemoveAt(pos1);
  160. break;
  161. }
  162. nIndex++;
  163. }
  164. LeaveCriticalSection( &m_cs );
  165. }
  166. void CEventServer::ClearAllEvent()
  167. {
  168. EnterCriticalSection( &m_cs );
  169. POSITION pos = eventList.GetHeadPosition();
  170. while(pos!=NULL)
  171. {
  172. POSITION pos1 = pos;
  173. CAlarmEvent* pEvent = eventList.GetNext(pos);
  174. if (pEvent)
  175. {
  176. delete pEvent;
  177. eventList.RemoveAt(pos1);
  178. }
  179. }
  180. LeaveCriticalSection( &m_cs );
  181. }
  182. void CEventServer::GetOneEventInfo( int iIndex,CString &strUid, int &nVarID, int &nStatus,int &nAlarmIndex,int &nIsSound,int &nColor )
  183. {
  184. EnterCriticalSection( &m_cs );
  185. int nIndex=0;
  186. POSITION pos = eventList.GetTailPosition();
  187. while( pos != NULL )
  188. {
  189. CAlarmEvent* event= eventList.GetPrev(pos);
  190. if( iIndex==nIndex )
  191. {
  192. strUid.Format( "%s",event->strUid );
  193. nVarID = event->nVarID;
  194. nStatus = event->nStatus;
  195. nAlarmIndex = event->nAlarmIndex;
  196. nIsSound = event->nIsSound;
  197. nColor = event->nColor;
  198. break;
  199. }
  200. nIndex++;
  201. }
  202. LeaveCriticalSection( &m_cs );
  203. }
  204. void CEventServer::SetOneEventInfo( int iIndex,int nIsSound,int nColor )
  205. {
  206. EnterCriticalSection( &m_cs );
  207. int nIndex=0;
  208. POSITION pos = eventList.GetTailPosition();
  209. while( pos != NULL )
  210. {
  211. CAlarmEvent* event= eventList.GetPrev(pos);
  212. if( iIndex==nIndex )
  213. {
  214. event->nIsSound = nIsSound;
  215. event->nColor = nColor;
  216. break;
  217. }
  218. nIndex++;
  219. }
  220. LeaveCriticalSection( &m_cs );
  221. }
  222. void CEventServer::AddAlarmEvent( CString strDevUid, int nVarID,int nStatus,CString strContent
  223. ,double dbParaValue, int nUpperLimit,int nLowerLimit, int nNormalState,int nAlarmState,int nAlarmIndex )
  224. {
  225. //LOG4C((LOG_NOTICE, "AddAlarmEvent %s",strContent));
  226. CAlarmEvent* event=NULL;
  227. if( NULL == event )
  228. {
  229. event = new CAlarmEvent();
  230. GetLocalTime( &event->time );
  231. event->nStatus = nStatus;
  232. event->strUid = strDevUid;
  233. event->nVarID = nVarID;
  234. event->dbParaValue = dbParaValue;
  235. event->nUpperLimit = nUpperLimit;
  236. event->nLowerLimit = nLowerLimit;
  237. event->nNormalState = nNormalState;
  238. event->nAlarmState = nAlarmState;
  239. event->strContent = strContent;
  240. event->nAlarmIndex = nAlarmIndex;
  241. event->nGet = 0;
  242. event->nDealStatus = 0;
  243. event->nIsSound = 0;
  244. event->nColor = 0;
  245. AddNewEvent(event);
  246. }
  247. //else
  248. //{
  249. // if( true == event->bGet )//已经显示在列表中
  250. // {
  251. // if( strContent.Find(pVariantsManager->m_strReturnNormal) != -1 )// 恢复正常
  252. // {
  253. // event->nIdentifyTime = nIdentifyTime;
  254. // event->strContent = strContent;
  255. // //GetLocalTime( &event->time );
  256. // event->bGet = false;//恢复正常马上显示到列表中
  257. // event->nConfirm = 2;//2:恢复正常
  258. // }
  259. // else
  260. // {
  261. // if( 2==event->nConfirm || 3==event->nConfirm || 4==event->nConfirm )//
  262. // {
  263. // event->nIdentifyTime = nIdentifyTime;
  264. // event->strContent = strContent;
  265. // GetLocalTime( &event->time );
  266. // event->bGet = false;
  267. // event->nConfirm = 0;
  268. // }
  269. // }
  270. // }
  271. // else//还未显示在列表中
  272. // {
  273. // if( strContent.Find(pVariantsManager->m_strReturnNormal) != -1 )// 恢复正常
  274. // {
  275. // event->nIdentifyTime = nIdentifyTime;
  276. // event->strContent = strContent;
  277. // //GetLocalTime( &event->time );
  278. // event->bGet = true;//未到辨别时间恢复则假设已经显示在列表中
  279. // event->nConfirm = 4;//4:未到辨别时间恢复正常
  280. // }
  281. // else
  282. // {
  283. // if( 2==event->nConfirm || 3==event->nConfirm || 4==event->nConfirm )//
  284. // {
  285. // event->nIdentifyTime = nIdentifyTime;
  286. // event->strContent = strContent;
  287. // GetLocalTime( &event->time );
  288. // event->bGet = false;
  289. // event->nConfirm = 0;
  290. // }
  291. // }
  292. // }
  293. //}
  294. }
  295. void CEventServer::Validate(bool valid)
  296. {
  297. m_bValid = valid;
  298. }