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.

90 lines
2.6 KiB

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