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.

94 lines
2.7 KiB

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. void utilizeBasicEvent( basicEvent &Evt ){
  17. if( Evt.m_pHumanReadableMsg != NULL ) {
  18. delete( Evt.m_pHumanReadableMsg );
  19. };
  20. Evt.m_pHumanReadableMsg = NULL;
  21. if( Evt.m_pEvtData != NULL ){
  22. switch (Evt.m_eType){
  23. case EVT_TARGET_1D:
  24. case EVT_TARGET_2D_WHITE:
  25. case EVT_TARGET_2D_BLACK:
  26. case EVT_TARGET_3D_WHITE:
  27. case EVT_TARGET_3D_BLACK: {
  28. delete((CLIENT_EVENT*)Evt.m_pEvtData);
  29. break;
  30. };
  31. default: free(Evt.m_pEvtData);
  32. };
  33. };
  34. Evt.m_pEvtData = NULL;
  35. Evt.m_eType = EVT_NOINIT;
  36. };
  37. void utilizeBasicEvent( basicEvent *Evt ){
  38. if( Evt == NULL ) return;
  39. if( Evt->m_pHumanReadableMsg != NULL ) {
  40. delete( Evt->m_pHumanReadableMsg );
  41. };
  42. if( Evt->m_pEvtData != NULL ){
  43. switch (Evt->m_eType){
  44. case EVT_TARGET_1D:
  45. case EVT_TARGET_2D_WHITE:
  46. case EVT_TARGET_2D_BLACK:
  47. case EVT_TARGET_3D_WHITE:
  48. case EVT_TARGET_3D_BLACK: {
  49. delete((CLIENT_EVENT*)Evt->m_pEvtData);
  50. break;
  51. };
  52. default: free(Evt->m_pEvtData);
  53. };
  54. };
  55. delete( Evt );
  56. };
  57. basicEvent *createBasicEvent(unsigned int SRC, basicEventClassID Class, basicEventTypeID Type, char *Msg, void *Data){
  58. basicEvent *tEvent;
  59. tEvent =(basicEvent *) malloc( sizeof( basicEvent));
  60. if( tEvent ){
  61. time_t t = time(NULL);
  62. tEvent->sTS = *localtime(&t);
  63. tEvent->m_eClass = Class;
  64. tEvent->m_eType = Type;
  65. tEvent->m_nDestinationUID = 0; // Broadcast
  66. tEvent->m_nSourceUID = SRC;
  67. tEvent->m_pEvtData = Data;
  68. tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg)+1);
  69. if( tEvent->m_pHumanReadableMsg ) {
  70. strcpy( tEvent->m_pHumanReadableMsg, Msg );
  71. };
  72. };
  73. return tEvent;
  74. };
  75. basicEvent *createBasicTargetedEvent(unsigned int SRC, unsigned int DST, basicEventClassID Class, basicEventTypeID Type, char *Msg, void *Data){
  76. basicEvent *tEvent;
  77. tEvent = (basicEvent *)malloc(sizeof(basicEvent));
  78. if (tEvent){
  79. time_t t = time(NULL);
  80. tEvent->sTS = *localtime(&t);
  81. tEvent->m_eClass = Class;
  82. tEvent->m_eType = Type;
  83. tEvent->m_nDestinationUID = DST;
  84. tEvent->m_nSourceUID = SRC;
  85. tEvent->m_pEvtData = Data;
  86. tEvent->m_pHumanReadableMsg = (char *)malloc(strlen(Msg) + 1);
  87. if (tEvent->m_pHumanReadableMsg) {
  88. strcpy(tEvent->m_pHumanReadableMsg, Msg);
  89. };
  90. };
  91. return tEvent;
  92. };