diff --git a/ApplicationCore.cpp b/ApplicationCore.cpp index 9aaa8af..e441d53 100644 --- a/ApplicationCore.cpp +++ b/ApplicationCore.cpp @@ -104,8 +104,7 @@ void CApplication::GetProcessName( char ** ProcessName, char * pFilePath ) if (TempStr[0] == '/') TempStr++; // Copy Process Name - *ProcessName = (char*)malloc( strlen(TempStr)+1 ); - strcpy( *ProcessName, TempStr ); + *ProcessName = strdup( TempStr ); // Remove extension TempStr = strrchr( *ProcessName, '.' ); @@ -163,7 +162,7 @@ bool CApplication::LoadConfig() } // Load Address List - if (!(AddressFile = (char*)Config->GetChStr( "Application/AddressList" ))) { + if (!(AddressFile = (char*)Config->GetChStr( "Application/Addresses/List" ))) { if (Log) Log->Message( dlLow, dlLow, "%s: No Address List file specified", ProcessName ); } else if (!JSONparser->ReadFromFile( "AddressList", AddressFile )) { @@ -235,7 +234,7 @@ bool CApplication::InitApplication() bool CApplication::InitFunction( CFunctionCore * Function ) { char FunctionPath[100]; - CDataMember * FunctionConfig = NULL; + CDataMember * FunctionConfig; // Validate if (!Function) @@ -274,7 +273,7 @@ bool CApplication::InitFunctions() return false; } - // Process each Channel + // Process each Function FunctionConfig = FunctionList->GetFirstChild(); while (FunctionConfig) { @@ -358,8 +357,7 @@ bool CApplication::AddFunctionType( const char * Type, FFuncConstructor Construc // Add new Type *FunctionType = (TFunctionType*)calloc( sizeof(TFunctionType), 1 ); - (*FunctionType)->Name = (char*)malloc( strlen(Type)+1 ); - strcpy( (*FunctionType)->Name, Type ); + (*FunctionType)->Name = strdup( Type ); (*FunctionType)->Constructor = Constructor; return true; diff --git a/DeviceCore.cpp b/DeviceCore.cpp index d6a8148..d1f6c35 100644 --- a/DeviceCore.cpp +++ b/DeviceCore.cpp @@ -410,8 +410,7 @@ TDevice * CDeviceCore::AddDeviceType( const char * DeviceTypeName ) else { *DeviceType = new TDevice; - (*DeviceType)->Type = (char *)malloc( strlen( DeviceTypeName )+1 ); - strcpy( (*DeviceType)->Type, DeviceTypeName ); + (*DeviceType)->Type = strdup( DeviceTypeName ); if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Added device type '%s'", ProcessName, Name, DeviceTypeName ); @@ -454,20 +453,15 @@ TDevice * CDeviceCore::AddDevice( const char * DeviceName, const char * DeviceTy else { *Device = new TDevice; - (*Device)->Name = (char *)malloc( strlen( DeviceName )+1 ); - strcpy( (*Device)->Name, DeviceName ); - - (*Device)->ID = DeviceID; + (*Device)->Name = strdup( DeviceName ); + (*Device)->ID = DeviceID; if (DeviceAddress) { - (*Device)->Address = (char *)malloc( strlen( DeviceAddress )+1 ); - strcpy( (*Device)->Address, DeviceAddress ); + (*Device)->Address = strdup( DeviceAddress ); } if (DeviceType && *DeviceType) { - (*Device)->Type = (char *)malloc( strlen( DeviceType )+1 ); - strcpy( (*Device)->Type, DeviceType ); - + (*Device)->Type = strdup( DeviceType ); (*Device)->Template = GetDeviceType( DeviceType ); } @@ -540,8 +534,7 @@ TDeviceParam * CDeviceCore::AddDeviceParam( TDevice * Device, const char * Param *Param = new TDeviceParam; // Set Name - (*Param)->Name = (char *)malloc( strlen( ParamName )+1 ); - strcpy( (*Param)->Name, ParamName ); + (*Param)->Name = strdup( ParamName ); (*Param)->DataType = DataType; (*Param)->Device = Device; @@ -683,9 +676,7 @@ TDeviceParamGroup * CDeviceCore::AddParamGroup( TDevice * Device, const char * G else { *ParamGroup = new TDeviceParamGroup; - (*ParamGroup)->Name = (char *)malloc( strlen( GroupName )+1 ); - strcpy( (*ParamGroup)->Name, GroupName ); - + (*ParamGroup)->Name = strdup( GroupName ); (*ParamGroup)->Device = Device; if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Added param group '%s/%s'", @@ -1197,8 +1188,7 @@ bool CDeviceCore::SetValue( TDeviceParam * Param, const char * Value, const int { // Ensure string is zero terminated if (Value[Len] != 0) { - TempStr = (char *)malloc( Len+1 ); - memcpy( TempStr, Value, Len ); + TempStr = strndup( Value, Len ); TempStr[Len] = 0; UseTempStr = true; } diff --git a/EventBufferCore.cpp b/EventBufferCore.cpp index ab1ad1b..3c317dc 100644 --- a/EventBufferCore.cpp +++ b/EventBufferCore.cpp @@ -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; diff --git a/FileCore.cpp b/FileCore.cpp index 2a56b62..6a96902 100644 --- a/FileCore.cpp +++ b/FileCore.cpp @@ -80,10 +80,8 @@ TFileHandle * CFileCore::AddFile( const char * Name, const char * Path, bool Ap *FileHandle = (TFileHandle*)calloc( 1, sizeof(TFileHandle) ); // Set name & Path - (*FileHandle)->Name = (char*)malloc( strlen(Name)+1 ); - strcpy( (*FileHandle)->Name, Name ); - (*FileHandle)->Path = (char*)malloc( strlen(Path)+1 ); - strcpy( (*FileHandle)->Path, Path ); + (*FileHandle)->Name = strdup( Name ); + (*FileHandle)->Path = strdup( Path ); } // Create Channel if necessary diff --git a/FunctionCore.cpp b/FunctionCore.cpp index d90682d..b8da187 100644 --- a/FunctionCore.cpp +++ b/FunctionCore.cpp @@ -31,8 +31,7 @@ CFunctionCore::CFunctionCore( const char * pName, const char * pType ) : Type( p { // Set name if (pName) { - Name = (char*)malloc( strlen(pName)+1 ); - strcpy( Name, pName ); + Name = strdup( pName ); } // Logging @@ -195,8 +194,7 @@ TChannel * CFunctionCore::AddChannel( const char * ChannelName, const bool pInpu *Channel = new TChannel; // Set Name - (*Channel)->Name = (char*)malloc( strlen(ChannelName)+1 ); - strcpy( (*Channel)->Name, ChannelName ); + (*Channel)->Name = strdup( ChannelName ); // Log Event if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Channel '%s' - Created", @@ -237,8 +235,7 @@ bool CFunctionCore::LinkInputChannel( const char * ChannelName, const char * Out // Set Parameters (*LinkedChannel)->Function = OutFunction; - (*LinkedChannel)->Name = (char*)malloc( strlen(OutChannelName)+1 ); - strcpy( (*LinkedChannel)->Name, OutChannelName ); + (*LinkedChannel)->Name = strdup( OutChannelName ); // Log Event if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Input Linked - '%s'/'%s' <-- '%s'/'%s'", @@ -282,8 +279,7 @@ bool CFunctionCore::LinkOutputChannel( const char * ChannelName, const char * In // Set Parameters (*LinkedChannel)->Function = InFunction; - (*LinkedChannel)->Name = (char*)malloc( strlen(InChannelName)+1 ); - strcpy( (*LinkedChannel)->Name, InChannelName ); + (*LinkedChannel)->Name = strdup( InChannelName ); // Log Event if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Output Linked - '%s'/'%s' --> '%s'/'%s'", diff --git a/SelectableCore.cpp b/SelectableCore.cpp index 425f42a..5f36109 100644 --- a/SelectableCore.cpp +++ b/SelectableCore.cpp @@ -44,9 +44,6 @@ CSelectableCore::CSelectableCore( const char * pName, const char * pType ) : CFu { // Quick access Selector = Application->Selector; - - // Handles - FirstHandle = NULL; } //--------------------------------------------------------------------------- @@ -98,6 +95,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig ) Handle = CreateHandle( HandleConfig->GetName(), false ); Handle->Channel = GetChannel( HandleConfig->GetChStr( "Channel" ) ); + // Load handle specifics Type = (char*)HandleConfig->GetChStr( "Type", "TCPclient", true ); if (!strcasecmp( Type, "Serial" )) { @@ -142,7 +140,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig ) } else if (!strcasecmp( Type, "LinePrinter" )) { - if ((Name = (char*)HandleConfig->GetChStr( "Port/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) { + if ((Name = (char*)HandleConfig->GetChStr( "Port/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) { Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value } else { Address = (char*)HandleConfig->GetChStr( "Port/Address", NULL, true ); // Get default value @@ -151,7 +149,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig ) } else if (!strcasecmp( Type, "UNIXserver" )) { - if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) { + if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) { Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value } else { Address = (char*)HandleConfig->GetChStr( "Socket/Address", NULL, true ); // Get default Address value @@ -161,7 +159,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig ) } else if (!strcasecmp( Type, "UNIXclient" )) { - if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) { + if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) { Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value } else { Address = (char*)HandleConfig->GetChStr( "Socket/Address", NULL, true ); // Get default Address value @@ -170,7 +168,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig ) } else if (!strcasecmp( Type, "UDPserver" )) { - if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) { + if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) { Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value } else { @@ -182,7 +180,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig ) } else if (!strcasecmp( Type, "UDPclient" )) { - if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) { + if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) { Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value } else { @@ -194,7 +192,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig ) } else if (!strcasecmp( Type, "TCPserver" )) { - if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) { + if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) { Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value } else { @@ -207,7 +205,7 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig ) } else if (!strcasecmp( Type, "TCPclient" )) { - if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = Application->AddressList->GetChild( Name ))) { + if ((Name = (char*)HandleConfig->GetChStr( "Socket/Name", NULL )) && (AddressDef = GetHandleAddress( Handle, Name ))) { Address = (char*)AddressDef->GetChStr( "Address", NULL, true ); // Get address list value Port = (char*)AddressDef->GetChStr( "Port", "0", true ); // Get AddressList Port value } else { @@ -243,6 +241,27 @@ bool CSelectableCore::Init( CDataMember * FunctionConfig ) } //--------------------------------------------------------------------------- +CDataMember * CSelectableCore::GetHandleAddress( THandle * Handle, const char * HandleRef ) +{ + CDataMember * AddressDef = NULL; + char NamePath[100]; + char * Address; + + // Handle renamed? + sprintf( NamePath, "Application/Addresses/Rename/%s", HandleRef ); + if (!(Address = (char*)Application->Config->GetChStr( NamePath, NULL, false ))) { + Address = (char*)HandleRef; + } + + // Get address def + if ((AddressDef = Application->AddressList->GetChild( Address ))) { + if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Use address '%s' ('%s')", + ProcessName, Name, Handle->Name, Address, HandleRef ); + } + return AddressDef; +} +//--------------------------------------------------------------------------- + THandle * CSelectableCore::CreateHandle( const char * HandleName, bool CreateChannel ) { THandle ** Handle = NULL; @@ -260,8 +279,7 @@ THandle * CSelectableCore::CreateHandle( const char * HandleName, bool CreateCh // Set name if (HandleName) { - (*Handle)->Name = (char*)malloc( strlen(HandleName)+1 ); - strcpy( (*Handle)->Name, HandleName ); + (*Handle)->Name = strdup( HandleName ); } // Set File Descriptor @@ -354,14 +372,9 @@ bool CSelectableCore::SetSerialHandle( THandle * Handle, const char * FileName ) // Set Type Handle->Type = ctSerial; - // Clear File Name - if (Handle->Path) { - free( Handle->Path ); - } - - // Set name - Handle->Path = (char*)malloc( strlen(FileName)+1 ); - strcpy( Handle->Path, FileName ); + // Set path + if (Handle->Path) free( Handle->Path ); + Handle->Path = strdup( FileName ); // Log event if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Set as Port [%s]", @@ -399,14 +412,9 @@ bool CSelectableCore::SetLinePrinterHandle( THandle * Handle, const char * FileN // Set Type Handle->Type = ctLinePrinter; - // Clear File Name - if (Handle->Path) { - free( Handle->Path ); - } - - // Set name - Handle->Path = (char*)malloc( strlen(FileName)+1 ); - strcpy( Handle->Path, FileName ); + // Set Path + if (Handle->Path) free( Handle->Path ); + Handle->Path = strdup( FileName ); // Log event if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Set as Port [%s]", @@ -425,14 +433,9 @@ bool CSelectableCore::SetForkPipeHandle( THandle * Handle, const char * ExecPath // Set Type Handle->Type = ctForkPipe; - // Clear File Name - if (Handle->Path) { - free( Handle->Path ); - } - - // Set name - Handle->Path = (char*)malloc( strlen(ExecPath)+1 ); - strcpy( Handle->Path, ExecPath ); + // Set path + if (Handle->Path) free( Handle->Path ); + Handle->Path = strdup( ExecPath ); // Log event if (Log) Log->Message( LogLevel, dlMedium, "%s/%s: Handle '%s' - Set as ForkPipe [%s]", @@ -459,8 +462,7 @@ bool CSelectableCore::SetUnixHandle( THandle * Handle, EConnectType Type, const } // Set name - Handle->Path = (char*)malloc( strlen(FileName)+1 ); - strcpy( Handle->Path, FileName ); + Handle->Path = strdup( FileName ); Handle->Queue = Queue; // Log event @@ -492,11 +494,8 @@ bool CSelectableCore::SetSocketHandle( THandle * Handle, EConnectType Type, con freeaddrinfo( Handle->AddressList ); // Set HostName & Port - Handle->HostName = (char*)malloc( strlen(HostName)+1 ); - strcpy( Handle->HostName, HostName ); - - Handle->PortName = (char*)malloc( strlen(PortName)+1 ); - strcpy( Handle->PortName, PortName ); + Handle->HostName = strdup( HostName ); + Handle->PortName = strdup( PortName ); Handle->AddressList = NULL; Handle->AddressInfo = NULL; @@ -597,8 +596,7 @@ bool CSelectableCore::SetInBuffer( THandle * Handle, int InBufSize, int InTimeou // Set Input Markers if (InMarkerLen && InMarker) { Handle->InMarkerLen = InMarkerLen; - Handle->InMarker = (char *)malloc( InMarkerLen+1 ); - memcpy( Handle->InMarker, InMarker, InMarkerLen ); + Handle->InMarker = strndup( InMarker, InMarkerLen ); Handle->InMarker[InMarkerLen] = 0; } @@ -1954,7 +1952,7 @@ bool CSelectableCore::Read( THandle * Handle ) // Read incoming message and address errno = 0; - UDPbuffer = (char*)malloc( BytesWaiting+1 ); + UDPbuffer = (char*)malloc( BytesWaiting+1 ); BytesRead = ReadFromUDP( Handle, (char*)UDPaddress, (char*)UDPport, UDPbuffer, BytesWaiting ); if (!errno && (Handle->Type == ctUDPserver)) @@ -2906,8 +2904,7 @@ bool CSelectableCore::BuildArgs( const char * ExecPath, int &Count, char * Args[ // Another quote ends parameter if (*MatchPos == '"') { Len = MatchPos-StartPos-1; // Skip end quote - Args[Count] = (char*)malloc( Len+1 ); - strncpy( Args[Count], StartPos, Len ); + Args[Count] = strndup( StartPos, Len ); Args[Count][Len] = 0; Count++; ParamStarted = false; @@ -2919,8 +2916,7 @@ bool CSelectableCore::BuildArgs( const char * ExecPath, int &Count, char * Args[ // Whitespace ends parameter if ((*MatchPos == ' ') || (*MatchPos == 0)) { Len = MatchPos-StartPos; - Args[Count] = (char*)malloc( Len+1 ); - strncpy( Args[Count], StartPos, Len ); + Args[Count] = strndup( StartPos, Len ); Args[Count][Len] = 0; Count++; ParamStarted = false; diff --git a/SelectableCore.h b/SelectableCore.h index 499226e..50ee239 100644 --- a/SelectableCore.h +++ b/SelectableCore.h @@ -55,16 +55,16 @@ typedef void (*FHandleCallback)( CSelectableCore * Function, THandle * Handle, E // List of Handles for Select Object struct SSelectHandle { // File Descriptor - int FD; - bool Read; - bool Write; + int FD = -1; + bool Read = false; + bool Write = false; // Event Object - THandle * Handle; - CSelectableCore * Function; + THandle * Handle = NULL; + CSelectableCore * Function = NULL; // List - TSelectHandle * Next; + TSelectHandle * Next = NULL; }; //--------------------------------------------------------------------------- @@ -72,63 +72,63 @@ struct SSelectHandle { // List or Handles for Selectable Function Object struct SHandle { // Description - char * Name; - EConnectType Type; + char * Name = NULL; + EConnectType Type = ctNone; // State - int FD; - EConnectState State; + int FD = -1; + EConnectState State = csNone; - bool AutoManage; - bool Persistent; - timeval LastAction; - long ReopenDelay; // millisecs before trying to re-open socket - long CloseTimeout; // millisecs of no traffic before closing socket + bool AutoManage = false; + bool Persistent = false; + timeval LastAction = {0,0}; + long ReopenDelay = 1000; // millisecs before trying to re-open socket + long CloseTimeout = 1000; // millisecs of no traffic before closing socket // Callback functions - FHandleCallback StateCallback[ 7 ]; + FHandleCallback StateCallback[ 7 ] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; // Type specific parameters - char * Path; // Port (file)name or Exec path + char * Path = NULL; // Port (file)name or Exec path // Fork config pid_t ChildPID; // Forked child PID // Socket config - char * HostName; // Host name or IP adddress - char * PortName; // Socket port no or protocol, e.g. "80" or "HTTP" - struct addrinfo * AddressList; // List of resolved IP Addresses for host name - struct addrinfo * AddressInfo; // Current selected IP Address - bool AddressFailed; // Indicate failure to connect to address - short Queue; // Max waiting connections - long ResolveDelay; // Delay before resolving hostname via DNS + char * HostName = NULL; // Host name or IP adddress + char * PortName = NULL; // Socket port no or protocol, e.g. "80" or "HTTP" + struct addrinfo * AddressList = NULL; // List of resolved IP Addresses for host name + struct addrinfo * AddressInfo = NULL; // Current selected IP Address + bool AddressFailed = false; // Indicate failure to connect to address + short Queue = 2; // Max waiting connections + long ResolveDelay = 0; // Delay before resolving hostname via DNS // Serial Port config - bool SerialConfig; - int InBaudrate; - int OutBaudrate; - short DataBits; - short Parity; - short StopBits; - short FlowCtrl; - int DataWait; + bool SerialConfig = false; + int InBaudrate = 0; + int OutBaudrate = 0; + short DataBits = 0; + short Parity = NO_PARITY; + short StopBits = 0; + short FlowCtrl = NO_FLOWCTRL; + int DataWait = 0; // Buffers - CRollingBuffer * InBuffer; - CRollingBuffer * OutBuffer; + CRollingBuffer * InBuffer = NULL; + CRollingBuffer * OutBuffer = NULL; // Input Markers - char * InMarker; - int InMarkerLen; + char * InMarker = NULL; + int InMarkerLen = 0; // Input Timer - timeval InStart; - long InTimeout; // millisecs + timeval InStart = {0,0}; + long InTimeout = 0; // millisecs // List / Tree - TChannel * Channel; - THandle * Parent; - THandle * Next; + TChannel * Channel = NULL; + THandle * Parent = NULL; + THandle * Next = NULL; }; //--------------------------------------------------------------------------- @@ -137,7 +137,7 @@ class CSelect { protected: // List - TSelectHandle * FirstHandle; + TSelectHandle * FirstHandle = NULL; // Select Variables fd_set ReadTestFDS; @@ -147,12 +147,12 @@ protected: fd_set WriteFDS; // Configuration - int MaxFD; - timeval Timeout; + int MaxFD = 0; + timeval Timeout = {0,0}; // Output - CLogCore * Log; - EDebugLevel LogLevel; + CLogCore * Log = NULL; + EDebugLevel LogLevel = dlNone; public: // Life Cycle @@ -184,10 +184,10 @@ class CSelectableCore : public CFunctionCore { protected: // FDs - THandle * FirstHandle; + THandle * FirstHandle = NULL; // Select interface - CSelect * Selector; + CSelect * Selector = NULL; // Managing File Handles bool RemoveHandle( THandle * Handle ); @@ -278,6 +278,7 @@ public: // General port parameters THandle * CreateHandle( const char * HandleName, bool CreateChannel ); + virtual CDataMember * GetHandleAddress( THandle * Handle, const char * HandleRef ); bool SetCallback( THandle * Handle, EConnectState pState, FHandleCallback pCallback ); bool SetAutoManage( THandle * Handle, bool AutoManage, bool Persistent, int ReopenDelay = 0, int CloseTimeout = 0 );