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.

153 lines
4.9 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
7 years ago
​
​
7 years ago
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
​
​
​
​
7 years ago
​
​
​
​
​
7 years ago
​
​
7 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. EVENT_CONTAINER *createBasicEvent(unsigned int SRC, basicEventClassID Class, basicEventTypeID Type, char *Msg, void *Data){
  93. EVENT_CONTAINER *tEvent;
  94. tEvent =(EVENT_CONTAINER *) malloc(sizeof(EVENT_CONTAINER));
  95. if( tEvent ){
  96. time_t t = time(NULL);
  97. tEvent->sTS = *localtime(&t);
  98. tEvent->m_UMSTS = getMilliseconds();
  99. tEvent->m_eClass = Class;
  100. CSTR tUUID = getUniqID_UUID();
  101. if( tUUID ) {
  102. sprintf( tEvent->m_UUID, "%s", tUUID );
  103. free( tUUID );
  104. } else {
  105. memset( tEvent->m_UUID, 0, 65 );
  106. };
  107. tEvent->m_eType = Type;
  108. tEvent->m_nDestinationUID = 0; // Broadcast
  109. tEvent->m_nSourceUID = SRC;
  110. tEvent->m_pEvtData = Data;
  111. if( Msg != NULL ) {
  112. tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg)+1);
  113. if( tEvent->m_pHumanReadableMsg ) {
  114. strcpy( tEvent->m_pHumanReadableMsg, Msg );
  115. };
  116. } else {
  117. tEvent->m_pHumanReadableMsg = NULL;
  118. };
  119. };
  120. return tEvent;
  121. };
  122. EVENT_CONTAINER *createBasicTargetedEvent(unsigned int SRC, unsigned int DST, basicEventClassID Class, basicEventTypeID Type, char *Msg, void *Data){
  123. EVENT_CONTAINER *tEvent;
  124. tEvent = (EVENT_CONTAINER *)malloc(sizeof(EVENT_CONTAINER));
  125. if (tEvent){
  126. time_t t = time(NULL);
  127. tEvent->sTS = *localtime(&t);
  128. tEvent->m_UMSTS = getMilliseconds();
  129. tEvent->m_eClass = Class;
  130. CSTR tUUID = getUniqID_UUID();
  131. if( tUUID ) {
  132. sprintf( tEvent->m_UUID, "%s", tUUID );
  133. free( tUUID );
  134. } else {
  135. memset( tEvent->m_UUID, 0, 65 );
  136. };
  137. tEvent->m_eType = Type;
  138. tEvent->m_nDestinationUID = DST;
  139. tEvent->m_nSourceUID = SRC;
  140. tEvent->m_pEvtData = Data;
  141. if( Msg != NULL ) {
  142. tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg)+1);
  143. if( tEvent->m_pHumanReadableMsg ) {
  144. strcpy( tEvent->m_pHumanReadableMsg, Msg );
  145. };
  146. } else {
  147. tEvent->m_pHumanReadableMsg = NULL;
  148. };
  149. };
  150. return tEvent;
  151. };