Important Update:

- Switch from malloc/free -> new/delete for structures
- Bug fix: Move Parameter groups to Device (not class)
- Update Parameter groups:
  - Update Read/Write indicators as params are added
This commit is contained in:
Charl Wentzel
2018-12-13 12:41:37 +02:00
parent dc76d99b58
commit f1be4e9540
3 changed files with 59 additions and 34 deletions

View File

@@ -259,6 +259,24 @@ bool CDeviceCore::InitParamGroups( TDevice * Device, CDataMember * DeviceConfig
CDataMember * GroupData;
CDataMember * ItemData;
TDeviceParamGroup * Group;
TDeviceParamGroup * GroupTemplate;
TDeviceParamItem * ItemTemplate;
// Copy Template
GroupTemplate = (Device->Template)? Device->Template->FirstParamGroup : NULL;
while (GroupTemplate)
{
if ((Group = AddParamGroup( Device, GroupTemplate->Name )))
{
ItemTemplate = GroupTemplate->FirstParam;
while (ItemTemplate)
{
AddParamItem( Group, ItemTemplate->Param->Name );
ItemTemplate = ItemTemplate->NextItem;
}
}
GroupTemplate = GroupTemplate->NextGroup;
}
// Add Parameters
GroupData = DeviceConfig->GetChFirstChild( "ParamGroups", true );
@@ -374,7 +392,7 @@ TDevice * CDeviceCore::AddDeviceType( const char * DeviceTypeName )
ProcessName, Name, DeviceTypeName );
}
else {
*DeviceType = (TDevice*)calloc( 1, sizeof(TDevice) );
*DeviceType = new TDevice;
(*DeviceType)->Type = (char *)malloc( strlen( DeviceTypeName )+1 );
strcpy( (*DeviceType)->Type, DeviceTypeName );
@@ -400,8 +418,7 @@ TDevice * CDeviceCore::AddDevice( const char * DeviceName, const char * Type )
DeviceName, (((*Device)->Type)? (*Device)->Type : "no type") );
}
else {
*Device = (TDevice*)malloc( sizeof(TDevice) );
memset( *Device, 0x0, sizeof(TDevice) );
*Device = new TDevice;
(*Device)->Name = (char *)malloc( strlen( DeviceName )+1 );
strcpy( (*Device)->Name, DeviceName );
@@ -437,13 +454,16 @@ bool CDeviceCore::DestroyDevice( TDevice ** Device )
if ((*Device)->Type)
free( (*Device)->Type );
// Destroy paramters
// Destroy parameters & groups
while ((*Device)->FirstParam) {
DestroyDeviceParam( &((*Device)->FirstParam) );
}
while ((*Device)->FirstParamGroup) {
DestroyParamGroup( &((*Device)->FirstParamGroup) );
}
// Destroy Device
free( *Device );
delete *Device;
// Remove from list
*Device = NextDevice;
@@ -471,8 +491,7 @@ TDeviceParam * CDeviceCore::AddDeviceParam( TDevice * Device, const char * Param
}
else {
// Create register
*Param = (TDeviceParam*)malloc( sizeof(TDeviceParam) );
memset( *Param, 0x0, sizeof(TDeviceParam) );
*Param = new TDeviceParam;
// Set Name
(*Param)->Name = (char *)malloc( strlen( ParamName )+1 );
@@ -587,7 +606,7 @@ bool CDeviceCore::DestroyDeviceParam( TDeviceParam ** Param )
free( (*Param)->SetValue );
// Destroy Param
free( *Param );
delete *Param;
// Remove from list
*Param = NextParam;
@@ -599,7 +618,7 @@ bool CDeviceCore::DestroyDeviceParam( TDeviceParam ** Param )
TDeviceParamGroup * CDeviceCore::AddParamGroup( TDevice * Device, const char * GroupName )
{
TDeviceParamGroup ** ParamGroup = GetParamGroupPtr( GroupName );
TDeviceParamGroup ** ParamGroup = GetParamGroupPtr( Device, GroupName );
if (!ParamGroup) {
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Could not add param group '%s'", ProcessName, Name,
@@ -612,7 +631,7 @@ TDeviceParamGroup * CDeviceCore::AddParamGroup( TDevice * Device, const char * G
ProcessName, Name, ((Device->Name)? Device->Name : Device->Type), GroupName );
}
else {
*ParamGroup = (TDeviceParamGroup*)calloc( 1, sizeof(TDeviceParamGroup) );
*ParamGroup = new TDeviceParamGroup;
(*ParamGroup)->Name = (char *)malloc( strlen( GroupName )+1 );
strcpy( (*ParamGroup)->Name, GroupName );
@@ -647,7 +666,7 @@ bool CDeviceCore::DestroyParamGroup( TDeviceParamGroup ** ParamGroup )
}
// Destroy ParamGroup
free( *ParamGroup );
delete *ParamGroup;
// Remove from list
*ParamGroup = NextGroup;
@@ -679,11 +698,15 @@ TDeviceParamItem * CDeviceCore::AddParamItem( TDeviceParamGroup * Group, const c
((Group->Device->Name)? Group->Device->Name : Group->Device->Type), ParamName, Group->Name );
}
else {
*Item = (TDeviceParamItem*)malloc( sizeof(TDeviceParamItem) );
memset( *Item, 0x0, sizeof(TDeviceParamItem) );
*Item = new TDeviceParamItem;
(*Item)->Param = Param;
if (Param->Read)
Group->Read = true;
if (Param->Write)
Group->Write = true;
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Added param group item '%s/%s/%s'", ProcessName, Name,
((Group->Device->Name)? Group->Device->Name : Group->Device->Type), Group->Name, ParamName );
}
@@ -699,7 +722,7 @@ bool CDeviceCore::DestroyParamItem( TDeviceParamItem ** Item )
return false;
NextParam = (*Item)->NextItem;
free( *Item );
delete *Item;
*Item = NextParam;
return true;