From 2382ff45276a86871b3c18eb70f9b336f02fb476 Mon Sep 17 00:00:00 2001 From: Charl Wentzel Date: Sat, 17 Nov 2018 20:02:47 +0200 Subject: [PATCH] Important Update: - DataTreeCore: - Rename all Get/SetChild...() methods to Get/SetMem...() - Update all other objects with new methods --- ApplicationCore.cpp | 8 ++--- DataTreeCore.cpp | 28 +++++++++--------- DataTreeCore.h | 54 +++++++++++++++++----------------- FunctionCore.cpp | 14 ++++----- SelectableCore.cpp | 72 ++++++++++++++++++++++----------------------- WatchdogCore.cpp | 2 +- 6 files changed, 89 insertions(+), 89 deletions(-) diff --git a/ApplicationCore.cpp b/ApplicationCore.cpp index 964878c..76495e0 100644 --- a/ApplicationCore.cpp +++ b/ApplicationCore.cpp @@ -152,7 +152,7 @@ bool CApplication::LoadConfigData() // Get debug level pLogLevel = dlNone; - TempStr = (char*)ConfigMember->GetChildStr( "Log/Level", "Medium", true ); + TempStr = (char*)ConfigMember->GetMemStr( "Log/Level", "Medium", true ); if (TempStr) { if (!strcasecmp( TempStr, "Low" )) @@ -193,7 +193,7 @@ bool CApplication::LoadConfigData() SetLogParam( pLogLevel, pLogOutput ); // Load Address List - if ((AddressFile = (char*)ConfigMember->GetChildStr( "AddressList/Path", NULL ))) + if ((AddressFile = (char*)ConfigMember->GetMemStr( "AddressList/Path", NULL ))) { if (JSONparser->ReadFromFile( "address", AddressFile )) { if (Log) Log->Message( dlLow, dlLow, "%s: Address file loaded (%s)", ProcessName, AddressFile ); @@ -207,7 +207,7 @@ bool CApplication::LoadConfigData() if ((TempMember = ConfigMember->GetMember( "Selector" ))) { // Create Selector - Selector = new CSelect( (int)TempMember->GetChildInt( "Wait", 5, true ), LogLevel ); + Selector = new CSelect( (int)TempMember->GetMemInt( "Wait", 5, true ), LogLevel ); } return true; } @@ -262,7 +262,7 @@ bool CApplication::InitFunctions( const char * pConfigPath ) while (TempMember) { // Get function parameters - Type = (char*)TempMember->GetChildStr( "Type", "Custom", true ); + Type = (char*)TempMember->GetMemStr( "Type", "Custom", true ); // Get or create function if (!strcasecmp( Type, "WatchdogClient" )) { diff --git a/DataTreeCore.cpp b/DataTreeCore.cpp index 3c52474..de09523 100644 --- a/DataTreeCore.cpp +++ b/DataTreeCore.cpp @@ -269,7 +269,7 @@ CDataMember * CDataMember::GetMember( const char * Path, bool Create ) } //--------------------------------------------------------------------------- -CDataMember * CDataMember::GetFirstChild( const char * Path ) +CDataMember * CDataMember::GetMemFirstChild( const char * Path ) { CDataMember * Member = NULL; @@ -285,7 +285,7 @@ CDataMember * CDataMember::GetFirstChild( const char * Path ) } //--------------------------------------------------------------------------- -CDataMember * CDataMember::GetElement( const char * Path, const int Index ) +CDataMember * CDataMember::GetMemElement( const char * Path, const int Index ) { CDataMember * Member = NULL; CDataMember * Child = NULL; @@ -348,7 +348,7 @@ bool CDataMember::SetValue( EDataType pType, const char * pValue, int pLen ) } //--------------------------------------------------------------------------- -bool CDataMember::SetChildObject( const char * Path ) +bool CDataMember::SetMemObject( const char * Path ) { CDataMember * Member; @@ -363,7 +363,7 @@ bool CDataMember::SetChildObject( const char * Path ) } //--------------------------------------------------------------------------- -bool CDataMember::SetChildArray( const char * Path ) +bool CDataMember::SetMemArray( const char * Path ) { CDataMember * Member; @@ -378,7 +378,7 @@ bool CDataMember::SetChildArray( const char * Path ) } //--------------------------------------------------------------------------- -bool CDataMember::SetChildStr( const char * Path, const char * Value, const int Len ) +bool CDataMember::SetMemStr( const char * Path, const char * Value, const int Len ) { CDataMember * Member; @@ -398,7 +398,7 @@ bool CDataMember::SetChildStr( const char * Path, const char * Value, const int } //--------------------------------------------------------------------------- -bool CDataMember::SetChildInt( const char * Path, const long Value, const char * Mask ) +bool CDataMember::SetMemInt( const char * Path, const long Value, const char * Mask ) { CDataMember * Member; char ValueStr[20]; @@ -415,7 +415,7 @@ bool CDataMember::SetChildInt( const char * Path, const long Value, const char } //--------------------------------------------------------------------------- -bool CDataMember::SetChildFloat( const char * Path, const double Value, const char * Mask ) +bool CDataMember::SetMemFloat( const char * Path, const double Value, const char * Mask ) { CDataMember * Member; char ValueStr[20]; @@ -432,7 +432,7 @@ bool CDataMember::SetChildFloat( const char * Path, const double Value, const c } //--------------------------------------------------------------------------- -bool CDataMember::SetChildBool( const char * Path, const bool Value ) +bool CDataMember::SetMemBool( const char * Path, const bool Value ) { CDataMember * Member; @@ -447,7 +447,7 @@ bool CDataMember::SetChildBool( const char * Path, const bool Value ) } //--------------------------------------------------------------------------- -bool CDataMember::SetChildNull( const char * Path ) +bool CDataMember::SetMemNull( const char * Path ) { CDataMember * Member; @@ -500,7 +500,7 @@ const int CDataMember::GetLen( const char * Path ) } //--------------------------------------------------------------------------- -const char * CDataMember::GetChildStr( const char * Path, const char * Default, bool Create ) +const char * CDataMember::GetMemStr( const char * Path, const char * Default, bool Create ) { CDataMember * Member; @@ -519,7 +519,7 @@ const char * CDataMember::GetChildStr( const char * Path, const char * Default, } //--------------------------------------------------------------------------- -const char * CDataMember::GetChildStr( const char * Path, int &Len, const char * Default, bool Create ) +const char * CDataMember::GetMemStr( const char * Path, int &Len, const char * Default, bool Create ) { CDataMember * Member; @@ -541,7 +541,7 @@ const char * CDataMember::GetChildStr( const char * Path, int &Len, const char * } //--------------------------------------------------------------------------- -const long CDataMember::GetChildInt( const char * Path, long Default, bool Create, const char * Mask ) +const long CDataMember::GetMemInt( const char * Path, long Default, bool Create, const char * Mask ) { CDataMember * Member; @@ -562,7 +562,7 @@ const long CDataMember::GetChildInt( const char * Path, long Default, bool Crea } //--------------------------------------------------------------------------- -const double CDataMember::GetChildFloat( const char * Path, double Default, bool Create, const char * Mask ) +const double CDataMember::GetMemFloat( const char * Path, double Default, bool Create, const char * Mask ) { CDataMember * Member; @@ -583,7 +583,7 @@ const double CDataMember::GetChildFloat( const char * Path, double Default, boo } //--------------------------------------------------------------------------- -const bool CDataMember::GetChildBool( const char * Path, bool Default, bool Create ) +const bool CDataMember::GetMemBool( const char * Path, bool Default, bool Create ) { CDataMember * Member; diff --git a/DataTreeCore.h b/DataTreeCore.h index b8dae02..38dfdc2 100644 --- a/DataTreeCore.h +++ b/DataTreeCore.h @@ -66,45 +66,45 @@ public: const int GetLen( const char * Path ); CDataMember * GetMember( const char * Path, bool Create = false ); - CDataMember * GetFirstChild( const char * Path ); - CDataMember * GetElement( const char * Path, const int Index ); + CDataMember * GetMemFirstChild( const char * Path ); + CDataMember * GetMemElement( const char * Path, const int Index ); inline CDataMember * GetFirstChild() { return FirstChild; }; - inline CDataMember * GetElement( const int Index ) { return GetElement( NULL, Index ); }; + inline CDataMember * GetElement( const int Index ) { return GetMemElement( NULL, Index ); }; inline CDataMember * GetParent() { return Parent; }; inline CDataMember * GetPrevPeer() { return PrevPeer; }; inline CDataMember * GetNextPeer() { return NextPeer; }; - const char * GetChildStr( const char * Path, const char * Default = NULL, bool Create = false ); - const char * GetChildStr( const char * Path, int &Len, const char * Default = NULL, bool Create = false ); - const bool GetChildBool( const char * Path, bool Default = false, bool Create = false ); - const long GetChildInt( const char * Path, long Default = 0, bool Create = false, const char * Mask = NULL ); - const double GetChildFloat( const char * Path, double Default = 0.0, bool Create = false, const char * Mask = NULL ); + const char * GetMemStr( const char * Path, const char * Default = NULL, bool Create = false ); + const char * GetMemStr( const char * Path, int &Len, const char * Default = NULL, bool Create = false ); + const bool GetMemBool( const char * Path, bool Default = false, bool Create = false ); + const long GetMemInt( const char * Path, long Default = 0, bool Create = false, const char * Mask = NULL ); + const double GetMemFloat( const char * Path, double Default = 0.0, bool Create = false, const char * Mask = NULL ); - inline const char * GetStr( const char * Default = NULL, bool Create = false ) { return GetChildStr( NULL, Default, Create ); }; - inline const char * GetStr( int &Len, const char * Default = NULL, bool Create = false ) { return GetChildStr( NULL, Len, Default, Create ); }; - inline const bool GetBool( bool Default = false, bool Create = false ) { return GetChildBool( NULL, Default, Create ); }; - inline const long GetInt( long Default = 0, bool Create = false, const char * Mask = NULL ) { return GetChildInt( NULL, Default, Create, Mask ); }; - inline const double GetFloat( double Default = 0.0, bool Create = false, const char * Mask = NULL ) { return GetChildFloat( NULL, Default, Create, Mask ); }; + inline const char * GetStr( const char * Default = NULL, bool Create = false ) { return GetMemStr( NULL, Default, Create ); }; + inline const char * GetStr( int &Len, const char * Default = NULL, bool Create = false ) { return GetMemStr( NULL, Len, Default, Create ); }; + inline const bool GetBool( bool Default = false, bool Create = false ) { return GetMemBool( NULL, Default, Create ); }; + inline const long GetInt( long Default = 0, bool Create = false, const char * Mask = NULL ) { return GetMemInt( NULL, Default, Create, Mask ); }; + inline const double GetFloat( double Default = 0.0, bool Create = false, const char * Mask = NULL ) { return GetMemFloat( NULL, Default, Create, Mask ); }; - bool SetChildBool( const char * Path, const bool Value ); - bool SetChildInt( const char * Path, const long Value, const char * Mask = NULL ); - bool SetChildFloat( const char * Path, const double Value, const char * Mask = NULL ); - bool SetChildStr( const char * Path, const char * Value = NULL, const int Len = -1 ); // Use Len param if Value contains NULL values + bool SetMemBool( const char * Path, const bool Value ); + bool SetMemInt( const char * Path, const long Value, const char * Mask = NULL ); + bool SetMemFloat( const char * Path, const double Value, const char * Mask = NULL ); + bool SetMemStr( const char * Path, const char * Value = NULL, const int Len = -1 ); // Use Len param if Value contains NULL values - inline bool SetBool( const bool Value ) { return SetChildBool( NULL, Value ); }; - inline bool SetInt( const long Value, const char * Mask = NULL ) { return SetChildInt( NULL, Value, Mask ); }; - inline bool SetFloat( const double Value, const char * Mask = NULL ) { return SetChildFloat( NULL, Value, Mask ); }; - inline bool SetStr( const char * Value = NULL, const int Len = -1 ) { return SetChildStr( NULL, Value, Len ); }; + inline bool SetBool( const bool Value ) { return SetMemBool( NULL, Value ); }; + inline bool SetInt( const long Value, const char * Mask = NULL ) { return SetMemInt( NULL, Value, Mask ); }; + inline bool SetFloat( const double Value, const char * Mask = NULL ) { return SetMemFloat( NULL, Value, Mask ); }; + inline bool SetStr( const char * Value = NULL, const int Len = -1 ) { return SetMemStr( NULL, Value, Len ); }; - bool SetChildNull( const char * Path ); - bool SetChildObject( const char * Path ); - bool SetChildArray( const char * Path ); + bool SetMemNull( const char * Path ); + bool SetMemObject( const char * Path ); + bool SetMemArray( const char * Path ); - inline bool SetNull() { return SetChildNull( NULL ); }; - inline bool SetObject() { return SetChildObject( NULL ); }; - inline bool SetArray() { return SetChildArray( NULL ); }; + inline bool SetNull() { return SetMemNull( NULL ); }; + inline bool SetObject() { return SetMemObject( NULL ); }; + inline bool SetArray() { return SetMemArray( NULL ); }; bool Clear(); bool Delete( const char * Path ); diff --git a/FunctionCore.cpp b/FunctionCore.cpp index 61e4cb6..db1d8d2 100644 --- a/FunctionCore.cpp +++ b/FunctionCore.cpp @@ -120,7 +120,7 @@ bool CFunctionCore::LoadConfigData() // Get debug level pLogLevel = dlNone; - TempStr = (char*)ConfigMember->GetChildStr( "Log/Level", "Medium", true ); + TempStr = (char*)ConfigMember->GetMemStr( "Log/Level", "Medium", true ); if (TempStr) { if (!strcasecmp( TempStr, "Low" )) @@ -163,13 +163,13 @@ bool CFunctionCore::LoadConfigData() SetLogParam( pLogLevel, pLogOutput ); // Load Channels - TempMember = ConfigMember->GetFirstChild( "Channels" ); + TempMember = ConfigMember->GetMemFirstChild( "Channels" ); while (TempMember) { if (TempMember->GetName()) { AddChannel( TempMember->GetName(), - TempMember->GetChildBool( "InputEnabled", true, true ), - TempMember->GetChildBool( "OutputEnabled", false, true )); + TempMember->GetMemBool( "InputEnabled", true, true ), + TempMember->GetMemBool( "OutputEnabled", false, true )); } // Next @@ -197,9 +197,9 @@ bool CFunctionCore::LoadChannelLinkData() { // Get Parameters LinkOutputChannel( Channel->Name, - FunctionMember->GetChildStr( "Function" ), - FunctionMember->GetChildStr( "Channel" ), - FunctionMember->GetChildBool( "Bidirectional" ) ); + FunctionMember->GetMemStr( "Function" ), + FunctionMember->GetMemStr( "Channel" ), + FunctionMember->GetMemBool( "Bidirectional" ) ); // Next FunctionMember = FunctionMember->GetNextPeer(); } diff --git a/SelectableCore.cpp b/SelectableCore.cpp index 63d54e1..96aeeb1 100644 --- a/SelectableCore.cpp +++ b/SelectableCore.cpp @@ -94,24 +94,24 @@ bool CSelectableCore::LoadConfigData() // Create Handle and channel link Handle = CreateHandle( TempMember->GetName(), false ); - Handle->Channel = GetChannel( TempMember->GetChildStr( "Channel" ) ); + Handle->Channel = GetChannel( TempMember->GetMemStr( "Channel" ) ); - Type = (char*)TempMember->GetChildStr( "Type", "TCPclient", true ); + Type = (char*)TempMember->GetMemStr( "Type", "TCPclient", true ); if (!strcasecmp( Type, "Serial" )) { - if ((Name = (char*)TempMember->GetChildStr( "Port/Name", NULL ))) { + if ((Name = (char*)TempMember->GetMemStr( "Port/Name", NULL ))) { sprintf( Path, "Address/%s/Address", Name ); - Address = (char*)DataTree->GetChildStr( Path, NULL, true ); // Get address list value + Address = (char*)DataTree->GetMemStr( Path, NULL, true ); // Get address list value } else { - Address = (char*)TempMember->GetChildStr( "Port/Address", NULL, true ); // Get default value + Address = (char*)TempMember->GetMemStr( "Port/Address", NULL, true ); // Get default value } SetSerialHandle( Handle, Address ); // Update configuration if specified if ((SerialConfig = TempMember->GetMember( "Port/SerialConfig", false ))) { - ParityText = (char*)SerialConfig->GetChildStr( "Parity", "none", true ); + ParityText = (char*)SerialConfig->GetMemStr( "Parity", "none", true ); if (!strcasecmp( ParityText, "none" )) Parity = NO_PARITY; else if (!strcasecmp( ParityText, "odd" )) @@ -121,7 +121,7 @@ bool CSelectableCore::LoadConfigData() else if (!strcasecmp( ParityText, "mark" )) Parity = MARK_PARITY; - FlowCtrlText = (char*)SerialConfig->GetChildStr( "FlowCtrl", "none", true ); + FlowCtrlText = (char*)SerialConfig->GetMemStr( "FlowCtrl", "none", true ); if (!strcasecmp( FlowCtrlText, "none" )) FlowCtrl = NO_FLOWCTRL; else if (!strcasecmp( FlowCtrlText, "hardware" )) @@ -130,70 +130,70 @@ bool CSelectableCore::LoadConfigData() FlowCtrl = SW_FLOWCTRL; Handle->SerialConfig = true; - SetSerialHandleConfig( Handle, SerialConfig->GetChildInt( "BaudRate", 19200, true ), - SerialConfig->GetChildInt( "DataBits", 8, true ), - Parity, SerialConfig->GetChildInt( "StopBits", 1, true ), - FlowCtrl, SerialConfig->GetChildInt( "DataWait", 0, true )); + SetSerialHandleConfig( Handle, SerialConfig->GetMemInt( "BaudRate", 19200, true ), + SerialConfig->GetMemInt( "DataBits", 8, true ), + Parity, SerialConfig->GetMemInt( "StopBits", 1, true ), + FlowCtrl, SerialConfig->GetMemInt( "DataWait", 0, true )); } } else if (!strcasecmp( Type, "LinePrinter" )) { - if ((Name = (char*)TempMember->GetChildStr( "Port/Name", NULL ))) { + if ((Name = (char*)TempMember->GetMemStr( "Port/Name", NULL ))) { sprintf( Path, "Address/%s/Address", Name ); - Address = (char*)DataTree->GetChildStr( Path, NULL, true ); // Get address list value + Address = (char*)DataTree->GetMemStr( Path, NULL, true ); // Get address list value } else { - Address = (char*)TempMember->GetChildStr( "Port/Address", NULL, true ); // Get default value + Address = (char*)TempMember->GetMemStr( "Port/Address", NULL, true ); // Get default value } SetLinePrinterHandle( Handle, Address ); } else if (!strcasecmp( Type, "TCPserver" )) { - if ((Name = (char*)TempMember->GetChildStr( "Socket/Name", NULL ))) { + if ((Name = (char*)TempMember->GetMemStr( "Socket/Name", NULL ))) { sprintf( Path, "Address/%s/Address", Name ); - Address = (char*)DataTree->GetChildStr( Path, NULL, true ); // Get AddressList Address value + Address = (char*)DataTree->GetMemStr( Path, NULL, true ); // Get AddressList Address value sprintf( Path, "Address/%s/Port", Name ); - Port = (char*)DataTree->GetChildStr( Path, "0", true ); // Get AddressList Port value + Port = (char*)DataTree->GetMemStr( Path, "0", true ); // Get AddressList Port value } else { - Address = (char*)TempMember->GetChildStr( "Socket/Address", NULL, true ); // Get default Address value - Port = (char*)TempMember->GetChildStr( "Socket/Port", "0", true ); // Get default Port value + Address = (char*)TempMember->GetMemStr( "Socket/Address", NULL, true ); // Get default Address value + Port = (char*)TempMember->GetMemStr( "Socket/Port", "0", true ); // Get default Port value } - Delay = TempMember->GetChildInt( "Socket/ResolveDelay", 0, true ); + Delay = TempMember->GetMemInt( "Socket/ResolveDelay", 0, true ); SetSocketHandle( Handle, ctServer, Address, strlcase(Port), Delay ); } else if (!strcasecmp( Type, "TCPclient" )) { - if ((Name = (char*)TempMember->GetChildStr( "Socket/Name", NULL ))) { + if ((Name = (char*)TempMember->GetMemStr( "Socket/Name", NULL ))) { sprintf( Path, "Address/%s/Address", Name ); - Address = (char*)DataTree->GetChildStr( Path, NULL, true ); // Get AddressList Address value + Address = (char*)DataTree->GetMemStr( Path, NULL, true ); // Get AddressList Address value sprintf( Path, "Address/%s/Port", Name ); - Port = (char*)DataTree->GetChildStr( Path, "0", true ); // Get AddressList Port value + Port = (char*)DataTree->GetMemStr( Path, "0", true ); // Get AddressList Port value } else { - Address = (char*)TempMember->GetChildStr( "Socket/Address", NULL, true ); // Get default Address value - Port = (char*)TempMember->GetChildStr( "Socket/Port", "0", true ); // Get default Port value + Address = (char*)TempMember->GetMemStr( "Socket/Address", NULL, true ); // Get default Address value + Port = (char*)TempMember->GetMemStr( "Socket/Port", "0", true ); // Get default Port value } - Delay = TempMember->GetChildInt( "Socket/ResolveDelay", 0, true ); + Delay = TempMember->GetMemInt( "Socket/ResolveDelay", 0, true ); SetSocketHandle( Handle, ctClient, Address, strlcase(Port), Delay ); } else if (!strcasecmp( Type, "ForkPipe" )) { - Address = (char*)TempMember->GetChildStr( "Fork/ExecPath", NULL, true ); // Get default value + Address = (char*)TempMember->GetMemStr( "Fork/ExecPath", NULL, true ); // Get default value SetForkPipeHandle( Handle, Address ); } // Set Auto Mange - SetAutoManage( Handle, TempMember->GetChildBool( "AutoManage/Enabled", true, true ), - TempMember->GetChildBool( "AutoManage/Persistent", false, true ), - TempMember->GetChildInt( "AutoManage/ReopenDelay", 2000, true ), - TempMember->GetChildInt( "AutoManage/CloseTimeout", 2000, true )); + SetAutoManage( Handle, TempMember->GetMemBool( "AutoManage/Enabled", true, true ), + TempMember->GetMemBool( "AutoManage/Persistent", false, true ), + TempMember->GetMemInt( "AutoManage/ReopenDelay", 2000, true ), + TempMember->GetMemInt( "AutoManage/CloseTimeout", 2000, true )); // Input buffer - SetInBuffer( Handle, TempMember->GetChildInt( "InputBuffer/Size", 0 ), - TempMember->GetChildInt( "InputBuffer/Timeout", 250 ), - TempMember->GetChildStr( "InputBuffer/Marker", "" ), - TempMember->GetChildInt( "InputBuffer/MarkerLen", 0 ) ); - SetOutBuffer( Handle, TempMember->GetChildInt( "OutputBuffer/Size", 0 ) ); + SetInBuffer( Handle, TempMember->GetMemInt( "InputBuffer/Size", 0 ), + TempMember->GetMemInt( "InputBuffer/Timeout", 250 ), + TempMember->GetMemStr( "InputBuffer/Marker", "" ), + TempMember->GetMemInt( "InputBuffer/MarkerLen", 0 ) ); + SetOutBuffer( Handle, TempMember->GetMemInt( "OutputBuffer/Size", 0 ) ); // Next TempMember = TempMember->GetNextPeer(); diff --git a/WatchdogCore.cpp b/WatchdogCore.cpp index 73a53ec..e0e3827 100644 --- a/WatchdogCore.cpp +++ b/WatchdogCore.cpp @@ -50,7 +50,7 @@ bool CWatchdogCore::LoadConfigData() CSelectableCore::LoadConfigData(); // Set specific parameters - SetInterval( ConfigMember->GetChildInt( "Parameters/PingInterval", 500, true )); + SetInterval( ConfigMember->GetMemInt( "Parameters/PingInterval", 500, true )); return true; }