|
|
//----------------------------------------------------------------------------
// Dr.Frucht Systems Ltd.
// Copyright © 2000-2016. All Rights Reserved.
// Version 2.0 3/30/2016
// Last modification: 3/30/2016
// PROJECT:
// SUBSYSTEM:
// FILE: basicEvent.cpp
// AUTHOR: gagua
// OVERVIEW
// ~~~~~~~~
// Header file of basicEvent.cpp
//----------------------------------------------------------------------------
//
#include "basicEvent.h"
#include "basicFunctionality.h"
void utilizeBasicEvent( EVENT_CONTAINER &Evt ){ if( Evt.m_pHumanReadableMsg != NULL ) { delete( Evt.m_pHumanReadableMsg ); }; Evt.m_pHumanReadableMsg = NULL; if( Evt.m_pEvtData != NULL ){ switch (Evt.m_eType){ case EVT_FH_MISSION_BEGIN: case EVT_FH_BUSY: case EVT_FH_CANCEL_ACTION: delete((FH_CTRL_DATA*)Evt.m_pEvtData); break; case EVT_FH_FLY_TO: case EVT_FH_WAYPOINT: case EVT_FH_DEST_REACHED: case EVT_FH_JAMER_ON: case EVT_FH_JAMER_OFF: case EVT_FH_TARGET_LOCKED: case EVT_FH_INTERCEPT_BEGIN: case EVT_FH_INTERCEPT_OK: case EVT_FH_INTERCEPT_NOK: case EVT_FH_MISSION_END: delete((FH_MISSION_DATA*)Evt.m_pEvtData); break; case EVT_TARGET_1D: case EVT_TARGET_2D_WHITE: case EVT_TARGET_2D_BLACK: case EVT_TARGET_3D_WHITE: case EVT_TARGET_3D_BLACK: { delete((CLIENT_EVENT*)Evt.m_pEvtData); break; }; default: free(Evt.m_pEvtData); }; }; Evt.m_pEvtData = NULL; Evt.m_eType = EVT_NOINIT;};
void utilizeBasicEvent( EVENT_CONTAINER *&Evt ){ if( Evt == NULL ) return; if( Evt->m_pHumanReadableMsg != NULL ) { delete( Evt->m_pHumanReadableMsg ); }; if( Evt->m_pEvtData != NULL ){ switch( Evt->m_eType ){ case EVT_FH_MISSION_BEGIN: case EVT_FH_BUSY: case EVT_FH_CANCEL_ACTION: delete((FH_CTRL_DATA*)Evt->m_pEvtData); break; case EVT_FH_FLY_TO: case EVT_FH_WAYPOINT: case EVT_FH_DEST_REACHED: case EVT_FH_JAMER_ON: case EVT_FH_JAMER_OFF: case EVT_FH_TARGET_LOCKED: case EVT_FH_INTERCEPT_BEGIN: case EVT_FH_INTERCEPT_OK: case EVT_FH_INTERCEPT_NOK: case EVT_FH_MISSION_END: delete((FH_MISSION_DATA*)Evt->m_pEvtData); break; case EVT_TARGET_1D: case EVT_TARGET_2D_WHITE: case EVT_TARGET_2D_BLACK: case EVT_TARGET_3D_WHITE: case EVT_TARGET_3D_BLACK: { delete((CLIENT_EVENT*)Evt->m_pEvtData); break; }; default: free(Evt->m_pEvtData); }; }; free( Evt ); Evt = NULL;};
static uint32_t EventSeed_Counter = 0;
EVENT_CONTAINER *createBasicEvent( uint64_t SRC, basicEventClassID Class, basicEventTypeID Type, char *RefUUID, char *Msg, void *Data, uint32_t tss, uint16_t tms ){ EVENT_CONTAINER *tEvent; tEvent =(EVENT_CONTAINER *) malloc(sizeof(EVENT_CONTAINER)); if( tEvent ){ if( tss == 0 ) { time_t t = time(NULL); tEvent->sTS = *localtime(&t); tEvent->m_UMSTS = getMilliseconds(); } else { time_t t = (time_t)tss; tEvent->sTS = *localtime(&t); tEvent->m_UMSTS = tss; tEvent->m_UMSTS = tEvent->m_UMSTS *1000 + tms; }; tEvent->m_eClass = Class; CSTR tUUID = getUniqID_UUID( EventSeed_Counter++ ); if( tUUID ) { sprintf( tEvent->m_UUID, "%s", tUUID ); free( tUUID ); } else { memset( tEvent->m_UUID, 0, 65 ); }; if( RefUUID ) { sprintf( tEvent->m_ref_UUID, "%s", RefUUID ); }; tEvent->m_eType = Type; tEvent->m_nDestinationNodeID = 0; // Broadcast
tEvent->m_nSourceNodeID = SRC; tEvent->m_pEvtData = Data; if( Msg != NULL ) { tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg)+1); if( tEvent->m_pHumanReadableMsg ) { strcpy( tEvent->m_pHumanReadableMsg, Msg ); }; } else { tEvent->m_pHumanReadableMsg = NULL; }; }; return tEvent;};
EVENT_CONTAINER *createBasicTargetedEvent( uint64_t SRC, uint64_t DST, basicEventClassID Class, basicEventTypeID Type, char *RefUUID, char *Msg, void *Data, uint32_t tss, uint16_t tms){ EVENT_CONTAINER *tEvent; tEvent = (EVENT_CONTAINER *)malloc(sizeof(EVENT_CONTAINER)); if (tEvent){ if( tss == 0 ) { time_t t = time(NULL); tEvent->sTS = *localtime(&t); tEvent->m_UMSTS = getMilliseconds(); } else { time_t t = (time_t)tss; tEvent->sTS = *localtime(&t); tEvent->m_UMSTS = tss; tEvent->m_UMSTS = tEvent->m_UMSTS *1000 + tms; }; tEvent->m_eClass = Class; CSTR tUUID = getUniqID_UUID(); if( tUUID ) { sprintf( tEvent->m_UUID, "%s", tUUID ); free( tUUID ); } else { memset( tEvent->m_UUID, 0, 65 ); }; if( RefUUID ) { sprintf( tEvent->m_ref_UUID, "%s", RefUUID ); }; tEvent->m_eType = Type; tEvent->m_nDestinationNodeID = DST; tEvent->m_nSourceNodeID = SRC; tEvent->m_pEvtData = Data; if( Msg != NULL ) { tEvent->m_pHumanReadableMsg = (char *) malloc(strlen(Msg)+1); if( tEvent->m_pHumanReadableMsg ) { strcpy( tEvent->m_pHumanReadableMsg, Msg ); }; } else { tEvent->m_pHumanReadableMsg = NULL; }; }; return tEvent;};
|