Important Update:

- Implement Handle Address renaming:
- Restructure JSON config, with address list and rename list
- SelectableCore:
  - Add method GetHandleAddress() - lookup renamed handle
  - Add init values to all struct and classes declarations
- Replace malloc()/strcpy() sequences with strdup()
This commit is contained in:
Charl Wentzel
2019-01-08 08:35:21 +02:00
parent c5da842ac1
commit 3e40f7a86d
7 changed files with 128 additions and 232 deletions

View File

@@ -73,58 +73,18 @@ TEventEntry * CreateEvent( const char * EventType, const char * Parent, const
// Create Blank Event Entry
Event = CreateEvent();
// Set Event type
Event->EventType = (char*)malloc( sizeof(char)*(strlen(EventType)+1) );
strcpy( Event->EventType, EventType );
// Set Parent Name
if (Parent && Parent[0])
{
Event->Parent = (char*)malloc( sizeof(char)*(strlen(Parent)+1) );
strcpy( Event->Parent, Parent );
}
else
{
Event->Parent = (char*)malloc(1);
Event->Parent[0] = 0;
}
// Set Device name
Event->DeviceName = (char*)malloc( sizeof(char)*(strlen(DeviceName)+1) );
strcpy( Event->DeviceName, DeviceName );
// Set Param name
if ((!ParamName || !ParamName[0]))
{
Event->ParamName = (char*)malloc(1);
Event->ParamName[0] = 0;
}
else
{
Event->ParamName = (char*)malloc( sizeof(char)*(strlen(ParamName)+1) );
strcpy( Event->ParamName, ParamName );
}
// Set Value
if ((!Value || !Value[0]))
{
Event->Value = (char*)malloc(1);
Event->Value[0] = 0;
}
else
{
Event->Value = (char*)malloc( sizeof(char)*(strlen(Value)+1) );
strcpy( Event->Value, Value );
}
// Set Event params
Event->EventType = (EventType)? strdup( EventType ) : strdup( "" );
Event->Parent = (Parent)? strdup( Parent ) : strdup( "" );
Event->DeviceName = (DeviceName)? strdup( DeviceName ) : strdup( "" );
Event->ParamName = (ParamName)? strdup( ParamName ) : strdup( "" );
Event->Value = (Value)? strdup( Value ) : strdup( "" );
Event->SourceName = (SourceName)? strdup( SourceName ) : strdup( "" );
// Set Date and time
strncpy( Event->DateTime, DateTimeStr, 19);
Event->DateTime[19] = 0;
// Set source
Event->SourceName = (char*)malloc( sizeof(char)*(strlen(SourceName)+1) );
strcpy( Event->SourceName, SourceName );
// Return Event
return Event;
}
@@ -144,57 +104,15 @@ TEventEntry * CopyEvent( TEventEntry * Event )
// Copy event no
EventCopy->EventNo = Event->EventNo;
// Copy pointer content
if (Event->EventType)
{
EventCopy->EventType = (char*)malloc( strlen(Event->EventType)+1 );
strcpy( EventCopy->EventType, Event->EventType );
}
else
EventCopy->EventType = NULL;
if (Event->Parent)
{
EventCopy->Parent = (char*)malloc( strlen(Event->Parent)+1 );
strcpy( EventCopy->Parent, Event->Parent );
}
else
EventCopy->Parent = NULL;
if (Event->DeviceName)
{
EventCopy->DeviceName = (char*)malloc( strlen(Event->DeviceName)+1 );
strcpy( EventCopy->DeviceName, Event->DeviceName );
}
else
EventCopy->DeviceName = NULL;
if (Event->ParamName)
{
EventCopy->ParamName = (char*)malloc( strlen(Event->ParamName)+1 );
strcpy( EventCopy->ParamName, Event->ParamName );
}
else
EventCopy->ParamName = NULL;
if (Event->Value)
{
EventCopy->Value = (char*)malloc( strlen(Event->Value)+1 );
strcpy( EventCopy->Value, Event->Value );
}
else
EventCopy->Value = NULL;
EventCopy->EventType = (Event->EventType)? strdup( Event->EventType ) : NULL;
EventCopy->Parent = (Event->Parent)? strdup( Event->Parent ) : NULL;
EventCopy->DeviceName = (Event->DeviceName)? strdup( Event->DeviceName ) : NULL;
EventCopy->ParamName = (Event->ParamName)? strdup( Event->ParamName ) : NULL;
EventCopy->Value = (Event->Value)? strdup( Event->Value ) : NULL;
EventCopy->SourceName = (Event->SourceName)? strdup( Event->SourceName ) : NULL;
strcpy( EventCopy->DateTime, Event->DateTime );
if (Event->SourceName)
{
EventCopy->SourceName = (char*)malloc( strlen(Event->SourceName)+1 );
strcpy( EventCopy->SourceName, Event->SourceName );
}
else
EventCopy->SourceName = NULL;
// Return copy
return EventCopy;
}
@@ -290,8 +208,7 @@ bool CEventBuffer::SetEventFilter( int n, ... )
// Copy name
EventName = va_arg(EventList, char*);
(*EventType)->Name = (char*)malloc( strlen(EventName)+1 );
strcpy( (*EventType)->Name, EventName );
(*EventType)->Name = strdup( EventName );
// Next
(*EventType)->Next = NULL;