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:
@@ -259,6 +259,24 @@ bool CDeviceCore::InitParamGroups( TDevice * Device, CDataMember * DeviceConfig
|
|||||||
CDataMember * GroupData;
|
CDataMember * GroupData;
|
||||||
CDataMember * ItemData;
|
CDataMember * ItemData;
|
||||||
TDeviceParamGroup * Group;
|
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
|
// Add Parameters
|
||||||
GroupData = DeviceConfig->GetChFirstChild( "ParamGroups", true );
|
GroupData = DeviceConfig->GetChFirstChild( "ParamGroups", true );
|
||||||
@@ -374,7 +392,7 @@ TDevice * CDeviceCore::AddDeviceType( const char * DeviceTypeName )
|
|||||||
ProcessName, Name, DeviceTypeName );
|
ProcessName, Name, DeviceTypeName );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*DeviceType = (TDevice*)calloc( 1, sizeof(TDevice) );
|
*DeviceType = new TDevice;
|
||||||
|
|
||||||
(*DeviceType)->Type = (char *)malloc( strlen( DeviceTypeName )+1 );
|
(*DeviceType)->Type = (char *)malloc( strlen( DeviceTypeName )+1 );
|
||||||
strcpy( (*DeviceType)->Type, DeviceTypeName );
|
strcpy( (*DeviceType)->Type, DeviceTypeName );
|
||||||
@@ -400,8 +418,7 @@ TDevice * CDeviceCore::AddDevice( const char * DeviceName, const char * Type )
|
|||||||
DeviceName, (((*Device)->Type)? (*Device)->Type : "no type") );
|
DeviceName, (((*Device)->Type)? (*Device)->Type : "no type") );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*Device = (TDevice*)malloc( sizeof(TDevice) );
|
*Device = new TDevice;
|
||||||
memset( *Device, 0x0, sizeof(TDevice) );
|
|
||||||
|
|
||||||
(*Device)->Name = (char *)malloc( strlen( DeviceName )+1 );
|
(*Device)->Name = (char *)malloc( strlen( DeviceName )+1 );
|
||||||
strcpy( (*Device)->Name, DeviceName );
|
strcpy( (*Device)->Name, DeviceName );
|
||||||
@@ -437,13 +454,16 @@ bool CDeviceCore::DestroyDevice( TDevice ** Device )
|
|||||||
if ((*Device)->Type)
|
if ((*Device)->Type)
|
||||||
free( (*Device)->Type );
|
free( (*Device)->Type );
|
||||||
|
|
||||||
// Destroy paramters
|
// Destroy parameters & groups
|
||||||
while ((*Device)->FirstParam) {
|
while ((*Device)->FirstParam) {
|
||||||
DestroyDeviceParam( &((*Device)->FirstParam) );
|
DestroyDeviceParam( &((*Device)->FirstParam) );
|
||||||
}
|
}
|
||||||
|
while ((*Device)->FirstParamGroup) {
|
||||||
|
DestroyParamGroup( &((*Device)->FirstParamGroup) );
|
||||||
|
}
|
||||||
|
|
||||||
// Destroy Device
|
// Destroy Device
|
||||||
free( *Device );
|
delete *Device;
|
||||||
|
|
||||||
// Remove from list
|
// Remove from list
|
||||||
*Device = NextDevice;
|
*Device = NextDevice;
|
||||||
@@ -471,8 +491,7 @@ TDeviceParam * CDeviceCore::AddDeviceParam( TDevice * Device, const char * Param
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Create register
|
// Create register
|
||||||
*Param = (TDeviceParam*)malloc( sizeof(TDeviceParam) );
|
*Param = new TDeviceParam;
|
||||||
memset( *Param, 0x0, sizeof(TDeviceParam) );
|
|
||||||
|
|
||||||
// Set Name
|
// Set Name
|
||||||
(*Param)->Name = (char *)malloc( strlen( ParamName )+1 );
|
(*Param)->Name = (char *)malloc( strlen( ParamName )+1 );
|
||||||
@@ -587,7 +606,7 @@ bool CDeviceCore::DestroyDeviceParam( TDeviceParam ** Param )
|
|||||||
free( (*Param)->SetValue );
|
free( (*Param)->SetValue );
|
||||||
|
|
||||||
// Destroy Param
|
// Destroy Param
|
||||||
free( *Param );
|
delete *Param;
|
||||||
|
|
||||||
// Remove from list
|
// Remove from list
|
||||||
*Param = NextParam;
|
*Param = NextParam;
|
||||||
@@ -599,7 +618,7 @@ bool CDeviceCore::DestroyDeviceParam( TDeviceParam ** Param )
|
|||||||
|
|
||||||
TDeviceParamGroup * CDeviceCore::AddParamGroup( TDevice * Device, const char * GroupName )
|
TDeviceParamGroup * CDeviceCore::AddParamGroup( TDevice * Device, const char * GroupName )
|
||||||
{
|
{
|
||||||
TDeviceParamGroup ** ParamGroup = GetParamGroupPtr( GroupName );
|
TDeviceParamGroup ** ParamGroup = GetParamGroupPtr( Device, GroupName );
|
||||||
|
|
||||||
if (!ParamGroup) {
|
if (!ParamGroup) {
|
||||||
if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Could not add param group '%s'", ProcessName, Name,
|
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 );
|
ProcessName, Name, ((Device->Name)? Device->Name : Device->Type), GroupName );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*ParamGroup = (TDeviceParamGroup*)calloc( 1, sizeof(TDeviceParamGroup) );
|
*ParamGroup = new TDeviceParamGroup;
|
||||||
|
|
||||||
(*ParamGroup)->Name = (char *)malloc( strlen( GroupName )+1 );
|
(*ParamGroup)->Name = (char *)malloc( strlen( GroupName )+1 );
|
||||||
strcpy( (*ParamGroup)->Name, GroupName );
|
strcpy( (*ParamGroup)->Name, GroupName );
|
||||||
@@ -647,7 +666,7 @@ bool CDeviceCore::DestroyParamGroup( TDeviceParamGroup ** ParamGroup )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Destroy ParamGroup
|
// Destroy ParamGroup
|
||||||
free( *ParamGroup );
|
delete *ParamGroup;
|
||||||
|
|
||||||
// Remove from list
|
// Remove from list
|
||||||
*ParamGroup = NextGroup;
|
*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 );
|
((Group->Device->Name)? Group->Device->Name : Group->Device->Type), ParamName, Group->Name );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*Item = (TDeviceParamItem*)malloc( sizeof(TDeviceParamItem) );
|
*Item = new TDeviceParamItem;
|
||||||
memset( *Item, 0x0, sizeof(TDeviceParamItem) );
|
|
||||||
|
|
||||||
(*Item)->Param = Param;
|
(*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,
|
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 );
|
((Group->Device->Name)? Group->Device->Name : Group->Device->Type), Group->Name, ParamName );
|
||||||
}
|
}
|
||||||
@@ -699,7 +722,7 @@ bool CDeviceCore::DestroyParamItem( TDeviceParamItem ** Item )
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
NextParam = (*Item)->NextItem;
|
NextParam = (*Item)->NextItem;
|
||||||
free( *Item );
|
delete *Item;
|
||||||
*Item = NextParam;
|
*Item = NextParam;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
25
DeviceCore.h
25
DeviceCore.h
@@ -32,6 +32,8 @@ typedef struct SDeviceParam TDeviceParam;
|
|||||||
typedef struct SDeviceParamGroup TDeviceParamGroup;
|
typedef struct SDeviceParamGroup TDeviceParamGroup;
|
||||||
typedef struct SDeviceParamItem TDeviceParamItem;
|
typedef struct SDeviceParamItem TDeviceParamItem;
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Devices with are polled
|
// Devices with are polled
|
||||||
struct SDevice {
|
struct SDevice {
|
||||||
// Device definition
|
// Device definition
|
||||||
@@ -44,6 +46,7 @@ struct SDevice {
|
|||||||
|
|
||||||
// Device parameters
|
// Device parameters
|
||||||
TDeviceParam * FirstParam = NULL;
|
TDeviceParam * FirstParam = NULL;
|
||||||
|
TDeviceParamGroup * FirstParamGroup = NULL;
|
||||||
|
|
||||||
// Device peer list
|
// Device peer list
|
||||||
TDevice * Next = NULL;
|
TDevice * Next = NULL;
|
||||||
@@ -82,6 +85,10 @@ struct SDeviceParamGroup {
|
|||||||
char * Name = NULL;
|
char * Name = NULL;
|
||||||
TDevice * Device = NULL;
|
TDevice * Device = NULL;
|
||||||
TDeviceParamItem * FirstParam = NULL;
|
TDeviceParamItem * FirstParam = NULL;
|
||||||
|
|
||||||
|
bool Read = false;
|
||||||
|
bool Write = false;
|
||||||
|
|
||||||
TDeviceParamGroup * NextGroup = NULL;
|
TDeviceParamGroup * NextGroup = NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -112,8 +119,6 @@ protected:
|
|||||||
TDevice * FirstDevice = NULL;
|
TDevice * FirstDevice = NULL;
|
||||||
TDevice * ActiveDevice = NULL;
|
TDevice * ActiveDevice = NULL;
|
||||||
|
|
||||||
TDeviceParamGroup * FirstParamGroup = NULL;
|
|
||||||
|
|
||||||
// Standard channels
|
// Standard channels
|
||||||
TChannel * DeviceChannel = NULL;
|
TChannel * DeviceChannel = NULL;
|
||||||
TChannel * CmdChannel = NULL;
|
TChannel * CmdChannel = NULL;
|
||||||
@@ -215,13 +220,13 @@ protected:
|
|||||||
bool DestroyParamItem( TDeviceParamItem ** Item );
|
bool DestroyParamItem( TDeviceParamItem ** Item );
|
||||||
|
|
||||||
// Find Param Groups
|
// Find Param Groups
|
||||||
inline TDeviceParamGroup * GetParamGroup( const char * GroupName ) {
|
inline TDeviceParamGroup * GetParamGroup( TDevice * Device, const char * GroupName ) {
|
||||||
TDeviceParamGroup ** Group = GetParamGroupPtr( GroupName );
|
TDeviceParamGroup ** Group = GetParamGroupPtr( Device, GroupName );
|
||||||
return (Group)? *Group : NULL;
|
return (Group)? *Group : NULL;
|
||||||
}
|
}
|
||||||
inline TDeviceParamGroup ** GetParamGroupPtr( const char * GroupName ) {
|
inline TDeviceParamGroup ** GetParamGroupPtr( TDevice * Device, const char * GroupName ) {
|
||||||
if (!GroupName || !*GroupName) return NULL;
|
if (!Device || !GroupName || !*GroupName) return NULL;
|
||||||
TDeviceParamGroup ** Group = &FirstParamGroup;
|
TDeviceParamGroup ** Group = &(Device->FirstParamGroup);
|
||||||
while (*Group && strcasecmp( (*Group)->Name, GroupName ))
|
while (*Group && strcasecmp( (*Group)->Name, GroupName ))
|
||||||
Group = &((*Group)->NextGroup);
|
Group = &((*Group)->NextGroup);
|
||||||
return Group;
|
return Group;
|
||||||
@@ -302,12 +307,12 @@ public:
|
|||||||
|
|
||||||
// Manage Param Groups
|
// Manage Param Groups
|
||||||
TDeviceParamGroup * AddParamGroup( TDevice * Device, const char * GroupName );
|
TDeviceParamGroup * AddParamGroup( TDevice * Device, const char * GroupName );
|
||||||
inline bool DestroyParamGroup( const char * GroupName ) {
|
inline bool DestroyParamGroup( TDevice * Device, const char * GroupName ) {
|
||||||
TDeviceParamGroup ** Group = GetParamGroupPtr( GroupName );
|
TDeviceParamGroup ** Group = GetParamGroupPtr( Device, GroupName );
|
||||||
return (Group)? DestroyParamGroup( Group ) : false;
|
return (Group)? DestroyParamGroup( Group ) : false;
|
||||||
};
|
};
|
||||||
TDeviceParamItem * AddParamItem( TDeviceParamGroup * Group, const char * ParamName );
|
TDeviceParamItem * AddParamItem( TDeviceParamGroup * Group, const char * ParamName );
|
||||||
inline bool DestroyParamItem( TDeviceParamGroup * Group, const char * ParamName ) {
|
inline bool DestroyParamItem( TDevice * Device, TDeviceParamGroup * Group, const char * ParamName ) {
|
||||||
TDeviceParamItem ** Item = GetParamItemPtr( Group, ParamName );
|
TDeviceParamItem ** Item = GetParamItemPtr( Group, ParamName );
|
||||||
return (Item)? DestroyParamItem( Item ) : false;
|
return (Item)? DestroyParamItem( Item ) : false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ CFunctionCore::~CFunctionCore()
|
|||||||
free( FirstChannel->FirstInput->Name );
|
free( FirstChannel->FirstInput->Name );
|
||||||
}
|
}
|
||||||
NextLinkedChannel = FirstChannel->FirstInput->Next;
|
NextLinkedChannel = FirstChannel->FirstInput->Next;
|
||||||
free( FirstChannel->FirstInput );
|
delete FirstChannel->FirstInput;
|
||||||
FirstChannel->FirstInput = NextLinkedChannel;
|
FirstChannel->FirstInput = NextLinkedChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,13 +71,13 @@ CFunctionCore::~CFunctionCore()
|
|||||||
free( FirstChannel->FirstOutput->Name );
|
free( FirstChannel->FirstOutput->Name );
|
||||||
}
|
}
|
||||||
NextLinkedChannel = FirstChannel->FirstOutput->Next;
|
NextLinkedChannel = FirstChannel->FirstOutput->Next;
|
||||||
free( FirstChannel->FirstOutput );
|
delete FirstChannel->FirstOutput;
|
||||||
FirstChannel->FirstOutput = NextLinkedChannel;
|
FirstChannel->FirstOutput = NextLinkedChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy Channel
|
// Destroy Channel
|
||||||
NextChannel = FirstChannel->Next;
|
NextChannel = FirstChannel->Next;
|
||||||
free( FirstChannel );
|
delete FirstChannel;
|
||||||
FirstChannel = NextChannel;
|
FirstChannel = NextChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,8 +192,7 @@ TChannel * CFunctionCore::AddChannel( const char * ChannelName, const bool pInpu
|
|||||||
// Create if not exist
|
// Create if not exist
|
||||||
if (!*Channel) {
|
if (!*Channel) {
|
||||||
// Create
|
// Create
|
||||||
*Channel = (TChannel*)malloc( sizeof(TChannel) );
|
*Channel = new TChannel;
|
||||||
memset( *Channel, 0, sizeof(TChannel) );
|
|
||||||
|
|
||||||
// Set Name
|
// Set Name
|
||||||
(*Channel)->Name = (char*)malloc( strlen(ChannelName)+1 );
|
(*Channel)->Name = (char*)malloc( strlen(ChannelName)+1 );
|
||||||
@@ -234,8 +233,7 @@ bool CFunctionCore::LinkInputChannel( const char * ChannelName, const char * Out
|
|||||||
if (!*LinkedChannel)
|
if (!*LinkedChannel)
|
||||||
{
|
{
|
||||||
// Create
|
// Create
|
||||||
*LinkedChannel = (TChannelLink*)malloc( sizeof(TChannelLink) );
|
*LinkedChannel = new TChannelLink;
|
||||||
memset( *LinkedChannel, 0, sizeof( TChannelLink ));
|
|
||||||
|
|
||||||
// Set Parameters
|
// Set Parameters
|
||||||
(*LinkedChannel)->Function = OutFunction;
|
(*LinkedChannel)->Function = OutFunction;
|
||||||
@@ -280,8 +278,7 @@ bool CFunctionCore::LinkOutputChannel( const char * ChannelName, const char * In
|
|||||||
if (!*LinkedChannel)
|
if (!*LinkedChannel)
|
||||||
{
|
{
|
||||||
// Create
|
// Create
|
||||||
*LinkedChannel = (TChannelLink*)malloc( sizeof(TChannelLink) );
|
*LinkedChannel = new TChannelLink;
|
||||||
memset( *LinkedChannel, 0, sizeof( TChannelLink ));
|
|
||||||
|
|
||||||
// Set Parameters
|
// Set Parameters
|
||||||
(*LinkedChannel)->Function = InFunction;
|
(*LinkedChannel)->Function = InFunction;
|
||||||
|
|||||||
Reference in New Issue
Block a user