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.

119 lines
3.6 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_TARGET_1D:
  25. case EVT_TARGET_2D_WHITE:
  26. case EVT_TARGET_2D_BLACK:
  27. case EVT_TARGET_3D_WHITE:
  28. case EVT_TARGET_3D_BLACK: {
  29. delete((CLIENT_EVENT*)Evt.m_pEvtData);
  30. break;
  31. };
  32. default: free(Evt.m_pEvtData);
  33. };
  34. };
  35. Evt.m_pEvtData = NULL;
  36. Evt.m_eType = EVT_NOINIT;
  37. };
  38. void utilizeBasicEvent( EVENT_CONTAINER *Evt ){
  39. if( Evt == NULL ) return;
  40. if( Evt->m_pHumanReadableMsg != NULL ) {
  41. delete( Evt->m_pHumanReadableMsg );
  42. };
  43. if( Evt->m_pEvtData != NULL ){
  44. switch (Evt->m_eType){
  45. case EVT_TARGET_1D:
  46. case EVT_TARGET_2D_WHITE:
  47. case EVT_TARGET_2D_BLACK:
  48. case EVT_TARGET_3D_WHITE:
  49. case EVT_TARGET_3D_BLACK: {
  50. delete((CLIENT_EVENT*)Evt->m_pEvtData);
  51. break;
  52. };
  53. default: free(Evt->m_pEvtData);
  54. };
  55. };
  56. delete( Evt );
  57. };
  58. EVENT_CONTAINER *createBasicEvent(unsigned int SRC, basicEventClassID Class, basicEventTypeID Type, char *Msg, void *Data){
  59. EVENT_CONTAINER *tEvent;
  60. tEvent =(EVENT_CONTAINER *) malloc(sizeof(EVENT_CONTAINER));
  61. if( tEvent ){
  62. time_t t = time(NULL);
  63. tEvent->sTS = *localtime(&t);
  64. tEvent->m_UMSTS = getMilliseconds();
  65. tEvent->m_eClass = Class;
  66. CSTR tUUID = getUniqID_UUID();
  67. if( tUUID ) {
  68. sprintf( tEvent->m_UUID, "%s", tUUID );
  69. free( tUUID );
  70. } else {
  71. memset( tEvent->m_UUID, 0, 65 );
  72. };
  73. tEvent->m_eType = Type;
  74. tEvent->m_nDestinationUID = 0; // Broadcast
  75. tEvent->m_nSourceUID = SRC;
  76. tEvent->m_pEvtData = Data;
  77. if( Msg != NULL ) {
  78. tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg)+1);
  79. if( tEvent->m_pHumanReadableMsg ) {
  80. strcpy( tEvent->m_pHumanReadableMsg, Msg );
  81. };
  82. } else {
  83. tEvent->m_pHumanReadableMsg = NULL;
  84. };
  85. };
  86. return tEvent;
  87. };
  88. EVENT_CONTAINER *createBasicTargetedEvent(unsigned int SRC, unsigned int DST, basicEventClassID Class, basicEventTypeID Type, char *Msg, void *Data){
  89. EVENT_CONTAINER *tEvent;
  90. tEvent = (EVENT_CONTAINER *)malloc(sizeof(EVENT_CONTAINER));
  91. if (tEvent){
  92. time_t t = time(NULL);
  93. tEvent->sTS = *localtime(&t);
  94. tEvent->m_UMSTS = getMilliseconds();
  95. tEvent->m_eClass = Class;
  96. CSTR tUUID = getUniqID_UUID();
  97. if( tUUID ) {
  98. sprintf( tEvent->m_UUID, "%s", tUUID );
  99. free( tUUID );
  100. } else {
  101. memset( tEvent->m_UUID, 0, 65 );
  102. };
  103. tEvent->m_eType = Type;
  104. tEvent->m_nDestinationUID = DST;
  105. tEvent->m_nSourceUID = SRC;
  106. tEvent->m_pEvtData = Data;
  107. if( Msg != NULL ) {
  108. tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg)+1);
  109. if( tEvent->m_pHumanReadableMsg ) {
  110. strcpy( tEvent->m_pHumanReadableMsg, Msg );
  111. };
  112. } else {
  113. tEvent->m_pHumanReadableMsg = NULL;
  114. };
  115. };
  116. return tEvent;
  117. };