You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
5.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Dr.Frucht Systems Ltd.
  3. // Copyright © 2000-2016. All Rights Reserved.
  4. // Version 2.0 3/30/2016
  5. // Last modification: 3/30/2016
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: basicEvent.cpp
  9. // AUTHOR: gagua
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Header file of basicEvent.cpp
  13. //----------------------------------------------------------------------------
  14. //
  15. #include "basicEvent.h"
  16. #include "basicFunctionality.h"
  17. void utilizeBasicEvent(EVENT_CONTAINER & Evt)
  18. {
  19. if (Evt.m_pHumanReadableMsg != NULL)
  20. {
  21. free( Evt.m_pHumanReadableMsg ); // The mem is allocated by malloc!!
  22. Evt.m_pHumanReadableMsg = NULL;
  23. };
  24. if (Evt.m_pEvtData != NULL)
  25. {
  26. switch (Evt.m_eType)
  27. {
  28. case EVT_FH_MISSION_BEGIN:
  29. case EVT_FH_BUSY:
  30. case EVT_FH_CANCEL_ACTION : delete((FH_CTRL_DATA *) Evt.m_pEvtData); break;
  31. case EVT_FH_FLY_TO :
  32. case EVT_FH_WAYPOINT :
  33. case EVT_FH_DEST_REACHED :
  34. case EVT_FH_JAMER_ON :
  35. case EVT_FH_JAMER_OFF :
  36. case EVT_FH_TARGET_LOCKED :
  37. case EVT_FH_INTERCEPT_BEGIN:
  38. case EVT_FH_INTERCEPT_OK :
  39. case EVT_FH_INTERCEPT_NOK :
  40. case EVT_FH_MISSION_END : delete((FH_MISSION_DATA *) Evt.m_pEvtData); break;
  41. case EVT_TARGET_1D:
  42. case EVT_TARGET_2D_WHITE:
  43. case EVT_TARGET_2D_BLACK:
  44. case EVT_TARGET_3D_WHITE:
  45. case EVT_TARGET_3D_BLACK:
  46. case EVT_CAMERA_MOVE_TO:
  47. {
  48. delete((TARGET_DATA *) Evt.m_pEvtData);
  49. break;
  50. };
  51. default: free(Evt.m_pEvtData);
  52. };
  53. };
  54. Evt.m_pEvtData = NULL;
  55. Evt.m_eType = EVT_NOINIT;
  56. }
  57. void utilizeBasicEvent(EVENT_CONTAINER *& Evt)
  58. {
  59. if (Evt == NULL)
  60. {
  61. return;
  62. }
  63. if (Evt->m_pHumanReadableMsg != NULL)
  64. {
  65. free( Evt->m_pHumanReadableMsg ); // The mem is allocated by malloc!!
  66. Evt->m_pHumanReadableMsg = NULL;
  67. };
  68. if (Evt->m_pEvtData != NULL)
  69. {
  70. switch (Evt->m_eType)
  71. {
  72. case EVT_FH_MISSION_BEGIN:
  73. case EVT_FH_BUSY:
  74. case EVT_FH_CANCEL_ACTION : delete((FH_CTRL_DATA *) Evt->m_pEvtData); break;
  75. case EVT_FH_FLY_TO :
  76. case EVT_FH_WAYPOINT :
  77. case EVT_FH_DEST_REACHED :
  78. case EVT_FH_JAMER_ON :
  79. case EVT_FH_JAMER_OFF :
  80. case EVT_FH_TARGET_LOCKED :
  81. case EVT_FH_INTERCEPT_BEGIN:
  82. case EVT_FH_INTERCEPT_OK :
  83. case EVT_FH_INTERCEPT_NOK :
  84. case EVT_FH_MISSION_END : delete((FH_MISSION_DATA *) Evt->m_pEvtData); break;
  85. case EVT_TARGET_1D:
  86. case EVT_TARGET_2D_WHITE:
  87. case EVT_TARGET_2D_BLACK:
  88. case EVT_TARGET_3D_WHITE:
  89. case EVT_TARGET_3D_BLACK:
  90. case EVT_CAMERA_MOVE_TO:
  91. {
  92. delete((TARGET_DATA *) Evt->m_pEvtData);
  93. break;
  94. };
  95. default: free(Evt->m_pEvtData);
  96. };
  97. };
  98. free(Evt);
  99. Evt = NULL;
  100. }
  101. static uint32_t EventSeed_Counter = 0;
  102. EVENT_CONTAINER * createBasicEvent(uint64_t SRC, basicEventClassID Class, basicEventTypeID Type, char * RefUUID, char * Msg, void * Data, uint32_t tss, uint16_t tms)
  103. {
  104. EVENT_CONTAINER * tEvent;
  105. tEvent = (EVENT_CONTAINER *) malloc(sizeof(EVENT_CONTAINER));
  106. if (tEvent)
  107. {
  108. if (tss == 0)
  109. {
  110. time_t t = time(NULL);
  111. localtime_r( &t, &tEvent->sTS );// MT safe
  112. tEvent->m_UMSTS = getMilliseconds();
  113. }
  114. else
  115. {
  116. time_t t = (time_t) tss;
  117. localtime_r( &t, &tEvent->sTS );// MT safe
  118. tEvent->m_UMSTS = tss;
  119. tEvent->m_UMSTS = tEvent->m_UMSTS * 1000 + tms;
  120. };
  121. tEvent->m_eClass = Class;
  122. CSTR tUUID = getUniqID_UUID(EventSeed_Counter++);
  123. if (tUUID)
  124. {
  125. sprintf(tEvent->m_UUID, "%s", tUUID);
  126. free(tUUID);
  127. }
  128. else
  129. {
  130. memset(tEvent->m_UUID, 0, 65);
  131. };
  132. if (RefUUID)
  133. {
  134. sprintf(tEvent->m_ref_UUID, "%s", RefUUID);
  135. };
  136. tEvent->m_eType = Type;
  137. tEvent->m_nDestinationNodeID = 0; // Broadcast
  138. tEvent->m_nSourceNodeID = SRC;
  139. tEvent->m_pEvtData = Data;
  140. if (Msg != NULL)
  141. {
  142. tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg) + 1);
  143. if (tEvent->m_pHumanReadableMsg)
  144. {
  145. strcpy(tEvent->m_pHumanReadableMsg, Msg);
  146. };
  147. }
  148. else
  149. {
  150. tEvent->m_pHumanReadableMsg = NULL;
  151. };
  152. };
  153. return tEvent;
  154. }
  155. EVENT_CONTAINER * createBasicTargetedEvent(uint64_t SRC, uint64_t DST, basicEventClassID Class, basicEventTypeID Type, char * RefUUID, char * Msg, void * Data, uint32_t tss, uint16_t tms)
  156. {
  157. EVENT_CONTAINER * tEvent;
  158. tEvent = (EVENT_CONTAINER *) malloc(sizeof(EVENT_CONTAINER));
  159. if (tEvent)
  160. {
  161. if (tss == 0)
  162. {
  163. time_t t = time(NULL);
  164. localtime_r( &t, &tEvent->sTS );// MT safe
  165. tEvent->m_UMSTS = getMilliseconds();
  166. }
  167. else
  168. {
  169. time_t t = (time_t) tss;
  170. localtime_r( &t, &tEvent->sTS );// MT safe
  171. tEvent->m_UMSTS = tss;
  172. tEvent->m_UMSTS = tEvent->m_UMSTS * 1000 + tms;
  173. };
  174. tEvent->m_eClass = Class;
  175. CSTR tUUID = getUniqID_UUID();
  176. if (tUUID)
  177. {
  178. sprintf(tEvent->m_UUID, "%s", tUUID);
  179. free(tUUID);
  180. }
  181. else
  182. {
  183. memset(tEvent->m_UUID, 0, 65);
  184. };
  185. if (RefUUID)
  186. {
  187. sprintf(tEvent->m_ref_UUID, "%s", RefUUID);
  188. };
  189. tEvent->m_eType = Type;
  190. tEvent->m_nDestinationNodeID = DST;
  191. tEvent->m_nSourceNodeID = SRC;
  192. tEvent->m_pEvtData = Data;
  193. if (Msg != NULL)
  194. {
  195. tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg) + 1);
  196. if (tEvent->m_pHumanReadableMsg)
  197. {
  198. strcpy(tEvent->m_pHumanReadableMsg, Msg);
  199. };
  200. }
  201. else
  202. {
  203. tEvent->m_pHumanReadableMsg = NULL;
  204. };
  205. };
  206. return tEvent;
  207. }