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.

162 lines
5.2 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
5 years ago
​
​
​
7 years ago
​
​
7 years ago
5 years ago
​
​
​
​
​
​
​
5 years ago
​
7 years ago
​
​
​
​
​
​
​
7 years ago
​
​
​
​
7 years ago
​
​
7 years ago
​
​
​
​
​
​
​
7 years ago
5 years ago
​
7 years ago
​
​
​
​
​
​
​
7 years ago
​
​
  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. if( Evt.m_pHumanReadableMsg != NULL ) {
  19. delete( Evt.m_pHumanReadableMsg );
  20. };
  21. Evt.m_pHumanReadableMsg = NULL;
  22. if( Evt.m_pEvtData != NULL ){
  23. switch (Evt.m_eType){
  24. case EVT_FH_MISSION_BEGIN:
  25. case EVT_FH_BUSY:
  26. case EVT_FH_CANCEL_ACTION:
  27. delete((FH_CTRL_DATA*)Evt.m_pEvtData);
  28. break;
  29. case EVT_FH_FLY_TO:
  30. case EVT_FH_WAYPOINT:
  31. case EVT_FH_DEST_REACHED:
  32. case EVT_FH_JAMER_ON:
  33. case EVT_FH_JAMER_OFF:
  34. case EVT_FH_TARGET_LOCKED:
  35. case EVT_FH_INTERCEPT_BEGIN:
  36. case EVT_FH_INTERCEPT_OK:
  37. case EVT_FH_INTERCEPT_NOK:
  38. case EVT_FH_MISSION_END:
  39. delete((FH_MISSION_DATA*)Evt.m_pEvtData);
  40. 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. delete((CLIENT_EVENT*)Evt.m_pEvtData);
  47. break;
  48. };
  49. default: free(Evt.m_pEvtData);
  50. };
  51. };
  52. Evt.m_pEvtData = NULL;
  53. Evt.m_eType = EVT_NOINIT;
  54. };
  55. void utilizeBasicEvent( EVENT_CONTAINER *Evt ){
  56. if( Evt == NULL ) return;
  57. if( Evt->m_pHumanReadableMsg != NULL ) {
  58. delete( Evt->m_pHumanReadableMsg );
  59. };
  60. if( Evt->m_pEvtData != NULL ){
  61. switch (Evt->m_eType){
  62. case EVT_FH_MISSION_BEGIN:
  63. case EVT_FH_BUSY:
  64. case EVT_FH_CANCEL_ACTION:
  65. delete((FH_CTRL_DATA*)Evt->m_pEvtData);
  66. break;
  67. case EVT_FH_FLY_TO:
  68. case EVT_FH_WAYPOINT:
  69. case EVT_FH_DEST_REACHED:
  70. case EVT_FH_JAMER_ON:
  71. case EVT_FH_JAMER_OFF:
  72. case EVT_FH_TARGET_LOCKED:
  73. case EVT_FH_INTERCEPT_BEGIN:
  74. case EVT_FH_INTERCEPT_OK:
  75. case EVT_FH_INTERCEPT_NOK:
  76. case EVT_FH_MISSION_END:
  77. delete((FH_MISSION_DATA*)Evt->m_pEvtData);
  78. break;
  79. case EVT_TARGET_1D:
  80. case EVT_TARGET_2D_WHITE:
  81. case EVT_TARGET_2D_BLACK:
  82. case EVT_TARGET_3D_WHITE:
  83. case EVT_TARGET_3D_BLACK: {
  84. delete((CLIENT_EVENT*)Evt->m_pEvtData);
  85. break;
  86. };
  87. default: free(Evt->m_pEvtData);
  88. };
  89. };
  90. delete( Evt );
  91. };
  92. static uint32_t EventSeed_Counter = 0;
  93. EVENT_CONTAINER *createBasicEvent(unsigned int SRC, basicEventClassID Class, basicEventTypeID Type, char *RefUUID, char *Msg, void *Data){
  94. EVENT_CONTAINER *tEvent;
  95. tEvent =(EVENT_CONTAINER *) malloc(sizeof(EVENT_CONTAINER));
  96. if( tEvent ){
  97. time_t t = time(NULL);
  98. tEvent->sTS = *localtime(&t);
  99. tEvent->m_UMSTS = getMilliseconds();
  100. tEvent->m_eClass = Class;
  101. CSTR tUUID = getUniqID_UUID( EventSeed_Counter++ );
  102. if( tUUID ) {
  103. sprintf( tEvent->m_UUID, "%s", tUUID );
  104. free( tUUID );
  105. } else {
  106. memset( tEvent->m_UUID, 0, 65 );
  107. };
  108. if( RefUUID ) {
  109. sprintf( tEvent->m_ref_UUID, "%s", RefUUID );
  110. };
  111. tEvent->m_eType = Type;
  112. tEvent->m_nDestinationNodeID = 0; // Broadcast
  113. tEvent->m_nSourceNodeID = SRC;
  114. tEvent->m_pEvtData = Data;
  115. if( Msg != NULL ) {
  116. tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg)+1);
  117. if( tEvent->m_pHumanReadableMsg ) {
  118. strcpy( tEvent->m_pHumanReadableMsg, Msg );
  119. };
  120. } else {
  121. tEvent->m_pHumanReadableMsg = NULL;
  122. };
  123. };
  124. return tEvent;
  125. };
  126. EVENT_CONTAINER *createBasicTargetedEvent(unsigned int SRC, unsigned int DST, basicEventClassID Class, basicEventTypeID Type, char *RefUUID, char *Msg, void *Data){
  127. EVENT_CONTAINER *tEvent;
  128. tEvent = (EVENT_CONTAINER *)malloc(sizeof(EVENT_CONTAINER));
  129. if (tEvent){
  130. time_t t = time(NULL);
  131. tEvent->sTS = *localtime(&t);
  132. tEvent->m_UMSTS = getMilliseconds();
  133. tEvent->m_eClass = Class;
  134. CSTR tUUID = getUniqID_UUID();
  135. if( tUUID ) {
  136. sprintf( tEvent->m_UUID, "%s", tUUID );
  137. free( tUUID );
  138. } else {
  139. memset( tEvent->m_UUID, 0, 65 );
  140. };
  141. if( RefUUID ) {
  142. sprintf( tEvent->m_ref_UUID, "%s", RefUUID );
  143. };
  144. tEvent->m_eType = Type;
  145. tEvent->m_nDestinationNodeID = DST;
  146. tEvent->m_nSourceNodeID = SRC;
  147. tEvent->m_pEvtData = Data;
  148. if( Msg != NULL ) {
  149. tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg)+1);
  150. if( tEvent->m_pHumanReadableMsg ) {
  151. strcpy( tEvent->m_pHumanReadableMsg, Msg );
  152. };
  153. } else {
  154. tEvent->m_pHumanReadableMsg = NULL;
  155. };
  156. };
  157. return tEvent;
  158. };