Minor update: code compacting
This commit is contained in:
@@ -284,8 +284,7 @@ bool CRollingBuffer::FindStr( const char * SearchStr, int SearchLen, int &FoundP
|
|||||||
|
|
||||||
// Search for needle in haystack
|
// Search for needle in haystack
|
||||||
FoundPos = StartPos;
|
FoundPos = StartPos;
|
||||||
while (FoundPos < BufLen)
|
while (FoundPos < BufLen) {
|
||||||
{
|
|
||||||
// Check if char match
|
// Check if char match
|
||||||
if (*CheckChar == *MatchChar) {
|
if (*CheckChar == *MatchChar) {
|
||||||
if (MatchChar == MatchLimit) {
|
if (MatchChar == MatchLimit) {
|
||||||
|
|||||||
181
DeviceCore.cpp
181
DeviceCore.cpp
@@ -141,8 +141,7 @@ bool CDeviceCore::InitDevices( CDataMember * FunctionConfig )
|
|||||||
|
|
||||||
// Load Device Types
|
// Load Device Types
|
||||||
DeviceConfig = Config->GetChFirstChild( "DeviceTypes", true );
|
DeviceConfig = Config->GetChFirstChild( "DeviceTypes", true );
|
||||||
while (DeviceConfig)
|
while (DeviceConfig) {
|
||||||
{
|
|
||||||
DeviceType = (char*)DeviceConfig->GetName();
|
DeviceType = (char*)DeviceConfig->GetName();
|
||||||
if (!DeviceConfig->isObject()) {
|
if (!DeviceConfig->isObject()) {
|
||||||
if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Invalid device type config for '%s'",
|
if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Invalid device type config for '%s'",
|
||||||
@@ -177,8 +176,7 @@ bool CDeviceCore::InitDevices( CDataMember * FunctionConfig )
|
|||||||
|
|
||||||
// Load Actual Devices
|
// Load Actual Devices
|
||||||
DeviceConfig = Config->GetChFirstChild( "Devices", true );
|
DeviceConfig = Config->GetChFirstChild( "Devices", true );
|
||||||
while (DeviceConfig)
|
while (DeviceConfig) {
|
||||||
{
|
|
||||||
DeviceName = (char*)DeviceConfig->GetName();
|
DeviceName = (char*)DeviceConfig->GetName();
|
||||||
if (!DeviceConfig->isObject()) {
|
if (!DeviceConfig->isObject()) {
|
||||||
if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Invalid device config for '%s'",
|
if (Log) Log->Message( LogLevel, dlLow, "%s/%s: Invalid device config for '%s'",
|
||||||
@@ -193,9 +191,8 @@ bool CDeviceCore::InitDevices( CDataMember * FunctionConfig )
|
|||||||
DataPath = (char*)DeviceConfig->GetChStr( "DataPath", NULL );
|
DataPath = (char*)DeviceConfig->GetChStr( "DataPath", NULL );
|
||||||
Device = AddDevice( DeviceName, DeviceType, DeviceID, DeviceAddr, DataPath );
|
Device = AddDevice( DeviceName, DeviceType, DeviceID, DeviceAddr, DataPath );
|
||||||
|
|
||||||
if (Device) {
|
if (Device)
|
||||||
InitDeviceParams( Device, DeviceConfig, Device->DataNode );
|
InitDeviceParams( Device, DeviceConfig, Device->DataNode );
|
||||||
}
|
|
||||||
DeviceConfig = DeviceConfig->GetNextPeer();
|
DeviceConfig = DeviceConfig->GetNextPeer();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -222,7 +219,6 @@ bool CDeviceCore::InitDeviceParams( TDevice * Device, CDataMember * DeviceConfi
|
|||||||
InitDeviceParam( Device, ParamConfig, NULL, ((isType)? NULL : Device->DataPath), ParentNode, NULL );
|
InitDeviceParam( Device, ParamConfig, NULL, ((isType)? NULL : Device->DataPath), ParentNode, NULL );
|
||||||
ParamConfig = ParamConfig->GetNextPeer();
|
ParamConfig = ParamConfig->GetNextPeer();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -233,8 +229,7 @@ bool CDeviceCore::CopyTemplateParam( TDevice * Device, TDeviceParam * Template,
|
|||||||
CDataMember * DataNode = NULL;
|
CDataMember * DataNode = NULL;
|
||||||
char * DataPath = NULL;
|
char * DataPath = NULL;
|
||||||
|
|
||||||
if ((Param = AddDeviceParam( Device, Template->Name, Template->DataType, Template->Len )))
|
if ((Param = AddDeviceParam( Device, Template->Name, Template->DataType, Template->Len ))) {
|
||||||
{
|
|
||||||
SetParamAccess( Param, Template->Read, Template->Write );
|
SetParamAccess( Param, Template->Read, Template->Write );
|
||||||
|
|
||||||
if (Template->DataPath) {
|
if (Template->DataPath) {
|
||||||
@@ -332,7 +327,8 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
|||||||
if (ParentName && *ParentName) {
|
if (ParentName && *ParentName) {
|
||||||
FullName = (char*)malloc( strlen(ParentName) + strlen(NodeName) + 2 );
|
FullName = (char*)malloc( strlen(ParentName) + strlen(NodeName) + 2 );
|
||||||
sprintf( FullName, "%s_%s", ParentName, NodeName );
|
sprintf( FullName, "%s_%s", ParentName, NodeName );
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
FullName = strdup( NodeName );
|
FullName = strdup( NodeName );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,17 +337,17 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
|||||||
if (ParentPath && *ParentPath) {
|
if (ParentPath && *ParentPath) {
|
||||||
DataPath = (char*)malloc( strlen(ParentPath) + strlen(NodeName) + 2 );
|
DataPath = (char*)malloc( strlen(ParentPath) + strlen(NodeName) + 2 );
|
||||||
sprintf( DataPath, "%s/%s", ParentPath, NodeName );
|
sprintf( DataPath, "%s/%s", ParentPath, NodeName );
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
DataPath = strdup( NodeName );
|
DataPath = strdup( NodeName );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Children = ParamConfig->GetChild( "Children", false ))) {
|
if ((Children = ParamConfig->GetChild( "Children", false ))) {
|
||||||
// Data Branch
|
// Data Branch
|
||||||
if ((ParamGroupName = (char*)ParamConfig->GetChStr( "ParamGroup", NULL, false ))) {
|
if ((ParamGroupName = (char*)ParamConfig->GetChStr( "ParamGroup", NULL, false )))
|
||||||
ParamGroup = AddParamGroup( Device, ParamGroupName );
|
ParamGroup = AddParamGroup( Device, ParamGroupName );
|
||||||
} else {
|
else
|
||||||
ParamGroup = ParentParamGroup;
|
ParamGroup = ParentParamGroup;
|
||||||
}
|
|
||||||
|
|
||||||
if (Children->isString()) {
|
if (Children->isString()) {
|
||||||
// Load from file
|
// Load from file
|
||||||
@@ -414,11 +410,11 @@ bool CDeviceCore::InitDeviceParam( TDevice * Device, CDataMember * ParamConfig,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ParamGroupName = (char*)ParamConfig->GetChStr( "ParamGroup", NULL, false ))) {
|
if ((ParamGroupName = (char*)ParamConfig->GetChStr( "ParamGroup", NULL, false )))
|
||||||
ParamGroup = AddParamGroup( Device, ParamGroupName );
|
ParamGroup = AddParamGroup( Device, ParamGroupName );
|
||||||
} else {
|
else
|
||||||
ParamGroup = ParentParamGroup;
|
ParamGroup = ParentParamGroup;
|
||||||
}
|
|
||||||
if (ParamGroup)
|
if (ParamGroup)
|
||||||
AddParamItem( ParamGroup, Param );
|
AddParamItem( ParamGroup, Param );
|
||||||
|
|
||||||
@@ -492,10 +488,8 @@ void CDeviceCore::ValidReplyReceived()
|
|||||||
bool CDeviceCore::CheckReplyTimeout()
|
bool CDeviceCore::CheckReplyTimeout()
|
||||||
{
|
{
|
||||||
// Check for Reply timeout
|
// Check for Reply timeout
|
||||||
if (!WaitingForReply || !Timeout( PollWait, ReplyTimeout )) {
|
if (!WaitingForReply || !Timeout( PollWait, ReplyTimeout ))
|
||||||
// No timeout
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// Update flags
|
// Update flags
|
||||||
WaitingForReply = false;
|
WaitingForReply = false;
|
||||||
@@ -503,8 +497,7 @@ bool CDeviceCore::CheckReplyTimeout()
|
|||||||
PollRetry++;
|
PollRetry++;
|
||||||
|
|
||||||
// Handle No Reply / Retry
|
// Handle No Reply / Retry
|
||||||
if (PollRetry > MaxRetries)
|
if (PollRetry > MaxRetries) {
|
||||||
{
|
|
||||||
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Channel '%s' - Device '%s' %s - Max retries",
|
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Channel '%s' - Device '%s' %s - Max retries",
|
||||||
ProcessName, Name, DeviceChannel->Name, ActiveDevice->Name,
|
ProcessName, Name, DeviceChannel->Name, ActiveDevice->Name,
|
||||||
((InvalidReply)? "invalid reply" : "timeout"), PollRetry );
|
((InvalidReply)? "invalid reply" : "timeout"), PollRetry );
|
||||||
@@ -587,9 +580,8 @@ TDevice * CDeviceCore::AddDevice( const char * DeviceName, const char * DeviceTy
|
|||||||
(*Device)->Name = strdup( DeviceName );
|
(*Device)->Name = strdup( DeviceName );
|
||||||
(*Device)->ID = DeviceID;
|
(*Device)->ID = DeviceID;
|
||||||
|
|
||||||
if (DeviceAddress) {
|
if (DeviceAddress)
|
||||||
(*Device)->Address = strdup( DeviceAddress );
|
(*Device)->Address = strdup( DeviceAddress );
|
||||||
}
|
|
||||||
|
|
||||||
if (DeviceType && *DeviceType) {
|
if (DeviceType && *DeviceType) {
|
||||||
(*Device)->Type = strdup( DeviceType );
|
(*Device)->Type = strdup( DeviceType );
|
||||||
@@ -638,12 +630,10 @@ bool CDeviceCore::DestroyDevice( TDevice ** Device )
|
|||||||
free( (*Device)->DataPath );
|
free( (*Device)->DataPath );
|
||||||
|
|
||||||
// Destroy parameters & groups
|
// Destroy parameters & groups
|
||||||
while ((*Device)->FirstParam) {
|
while ((*Device)->FirstParam)
|
||||||
DestroyDeviceParam( &((*Device)->FirstParam) );
|
DestroyDeviceParam( &((*Device)->FirstParam) );
|
||||||
}
|
while ((*Device)->FirstParamGroup)
|
||||||
while ((*Device)->FirstParamGroup) {
|
|
||||||
DestroyParamGroup( &((*Device)->FirstParamGroup) );
|
DestroyParamGroup( &((*Device)->FirstParamGroup) );
|
||||||
}
|
|
||||||
|
|
||||||
// Destroy Device
|
// Destroy Device
|
||||||
delete *Device;
|
delete *Device;
|
||||||
@@ -684,8 +674,7 @@ TDeviceParam * CDeviceCore::AddDeviceParam( TDevice * Device, const char * Param
|
|||||||
(*Param)->Device = Device;
|
(*Param)->Device = Device;
|
||||||
|
|
||||||
// Init values
|
// Init values
|
||||||
switch (DataType)
|
switch (DataType) {
|
||||||
{
|
|
||||||
case dtBool :
|
case dtBool :
|
||||||
// Create Value pointer
|
// Create Value pointer
|
||||||
(*Param)->Value = (bool*)malloc( sizeof(bool) );
|
(*Param)->Value = (bool*)malloc( sizeof(bool) );
|
||||||
@@ -861,9 +850,8 @@ bool CDeviceCore::DestroyParamGroup( TDeviceParamGroup ** ParamGroup )
|
|||||||
free( (*ParamGroup)->Name );
|
free( (*ParamGroup)->Name );
|
||||||
|
|
||||||
// Destroy items
|
// Destroy items
|
||||||
while ((*ParamGroup)->FirstParam) {
|
while ((*ParamGroup)->FirstParam)
|
||||||
DestroyParamItem( &((*ParamGroup)->FirstParam) );
|
DestroyParamItem( &((*ParamGroup)->FirstParam) );
|
||||||
}
|
|
||||||
|
|
||||||
// Destroy ParamGroup
|
// Destroy ParamGroup
|
||||||
delete *ParamGroup;
|
delete *ParamGroup;
|
||||||
@@ -986,11 +974,9 @@ bool CDeviceCore::UpdateUnsignedValue( TDeviceParam * Param, const u_int32_t Val
|
|||||||
if (!Param)
|
if (!Param)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (Param->DataType)
|
switch (Param->DataType) {
|
||||||
{
|
|
||||||
case dtBool :
|
case dtBool :
|
||||||
if (Init || (*((bool*)Param->Value) != Value))
|
if (Init || (*((bool*)Param->Value) != Value)) {
|
||||||
{
|
|
||||||
// Set new value & mark change
|
// Set new value & mark change
|
||||||
*((bool*)Param->Value) = Value;
|
*((bool*)Param->Value) = Value;
|
||||||
|
|
||||||
@@ -1008,8 +994,7 @@ bool CDeviceCore::UpdateUnsignedValue( TDeviceParam * Param, const u_int32_t Val
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case dtUnsigned16 :
|
case dtUnsigned16 :
|
||||||
if (Init || (*((u_int16_t*)Param->Value) != Value))
|
if (Init || (*((u_int16_t*)Param->Value) != Value)) {
|
||||||
{
|
|
||||||
// Set new value & mark change
|
// Set new value & mark change
|
||||||
*((u_int16_t*)Param->Value) = Value;
|
*((u_int16_t*)Param->Value) = Value;
|
||||||
|
|
||||||
@@ -1028,8 +1013,7 @@ bool CDeviceCore::UpdateUnsignedValue( TDeviceParam * Param, const u_int32_t Val
|
|||||||
|
|
||||||
case dtUnsigned32_HL :
|
case dtUnsigned32_HL :
|
||||||
case dtUnsigned32_LH :
|
case dtUnsigned32_LH :
|
||||||
if (Init || (*((u_int32_t*)Param->Value) != Value))
|
if (Init || (*((u_int32_t*)Param->Value) != Value)) {
|
||||||
{
|
|
||||||
// Set new value & mark change
|
// Set new value & mark change
|
||||||
*((u_int32_t*)Param->Value) = Value;
|
*((u_int32_t*)Param->Value) = Value;
|
||||||
|
|
||||||
@@ -1049,8 +1033,7 @@ bool CDeviceCore::UpdateUnsignedValue( TDeviceParam * Param, const u_int32_t Val
|
|||||||
case dtFloat32_L :
|
case dtFloat32_L :
|
||||||
case dtFloat32_B :
|
case dtFloat32_B :
|
||||||
// Special case, where float value is stored in Integer memory (e.g. modbus register)
|
// Special case, where float value is stored in Integer memory (e.g. modbus register)
|
||||||
if (Init || (*((u_int32_t*)Param->Value) != Value))
|
if (Init || (*((u_int32_t*)Param->Value) != Value)) {
|
||||||
{
|
|
||||||
// Set new value & mark change
|
// Set new value & mark change
|
||||||
*((u_int32_t*)Param->Value) = Value;
|
*((u_int32_t*)Param->Value) = Value;
|
||||||
|
|
||||||
@@ -1088,11 +1071,9 @@ bool CDeviceCore::UpdateSignedValue( TDeviceParam * Param, const int32_t Value,
|
|||||||
if (!Param)
|
if (!Param)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (Param->DataType)
|
switch (Param->DataType) {
|
||||||
{
|
|
||||||
case dtBool :
|
case dtBool :
|
||||||
if (Init || (*((bool*)Param->Value) != Value))
|
if (Init || (*((bool*)Param->Value) != Value)) {
|
||||||
{
|
|
||||||
// Set new value & mark change
|
// Set new value & mark change
|
||||||
*((bool*)Param->Value) = Value;
|
*((bool*)Param->Value) = Value;
|
||||||
|
|
||||||
@@ -1110,8 +1091,7 @@ bool CDeviceCore::UpdateSignedValue( TDeviceParam * Param, const int32_t Value,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case dtSigned16 :
|
case dtSigned16 :
|
||||||
if (Init || (*((int16_t*)Param->Value) != Value))
|
if (Init || (*((int16_t*)Param->Value) != Value)) {
|
||||||
{
|
|
||||||
// Set new value & mark change
|
// Set new value & mark change
|
||||||
*((int16_t*)Param->Value) = Value;
|
*((int16_t*)Param->Value) = Value;
|
||||||
|
|
||||||
@@ -1130,8 +1110,7 @@ bool CDeviceCore::UpdateSignedValue( TDeviceParam * Param, const int32_t Value,
|
|||||||
|
|
||||||
case dtSigned32_HL :
|
case dtSigned32_HL :
|
||||||
case dtSigned32_LH :
|
case dtSigned32_LH :
|
||||||
if (Init || (*((int32_t*)Param->Value) != Value))
|
if (Init || (*((int32_t*)Param->Value) != Value)) {
|
||||||
{
|
|
||||||
// Set new value & mark change
|
// Set new value & mark change
|
||||||
*((int32_t*)Param->Value) = Value;
|
*((int32_t*)Param->Value) = Value;
|
||||||
|
|
||||||
@@ -1169,12 +1148,10 @@ bool CDeviceCore::UpdateFloatValue( TDeviceParam * Param, const float Value, boo
|
|||||||
if (!Param)
|
if (!Param)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (Param->DataType)
|
switch (Param->DataType) {
|
||||||
{
|
|
||||||
case dtFloat32_L :
|
case dtFloat32_L :
|
||||||
case dtFloat32_B :
|
case dtFloat32_B :
|
||||||
if (Init || (*((float*)Param->Value) != Value))
|
if (Init || (*((float*)Param->Value) != Value)) {
|
||||||
{
|
|
||||||
// Set new value & mark change
|
// Set new value & mark change
|
||||||
*((float*)Param->Value) = Value;
|
*((float*)Param->Value) = Value;
|
||||||
|
|
||||||
@@ -1212,12 +1189,10 @@ bool CDeviceCore::UpdateStringValue( TDeviceParam * Param, const char * Value, c
|
|||||||
if (!Param || (Param->DataType != dtString))
|
if (!Param || (Param->DataType != dtString))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (Param->DataType)
|
switch (Param->DataType) {
|
||||||
{
|
|
||||||
case dtString :
|
case dtString :
|
||||||
// Update register
|
// Update register
|
||||||
if (Init || !CompareParamString( (char*)Param->Value, Param->Len, Value, Len))
|
if (Init || !CompareParamString( (char*)Param->Value, Param->Len, Value, Len)) {
|
||||||
{
|
|
||||||
if (Len >= Param->Len) {
|
if (Len >= Param->Len) {
|
||||||
// Copy full register length (ignore additional bytes)
|
// Copy full register length (ignore additional bytes)
|
||||||
memcpy( Param->Value, Value, Param->Len );
|
memcpy( Param->Value, Value, Param->Len );
|
||||||
@@ -1262,11 +1237,9 @@ bool CDeviceCore::SetUnsignedValue( TDeviceParam * Param, const u_int32_t Value,
|
|||||||
if (!Param)
|
if (!Param)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (Param->DataType)
|
switch (Param->DataType) {
|
||||||
{
|
|
||||||
case dtBool :
|
case dtBool :
|
||||||
if (Force || (*((bool*)Param->SetValue) != Value))
|
if (Force || (*((bool*)Param->SetValue) != Value)) {
|
||||||
{
|
|
||||||
// Set new value
|
// Set new value
|
||||||
*((bool*)Param->SetValue) = Value;
|
*((bool*)Param->SetValue) = Value;
|
||||||
|
|
||||||
@@ -1276,8 +1249,7 @@ bool CDeviceCore::SetUnsignedValue( TDeviceParam * Param, const u_int32_t Value,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case dtUnsigned16 :
|
case dtUnsigned16 :
|
||||||
if (Force || (*((u_int16_t*)Param->SetValue) != Value))
|
if (Force || (*((u_int16_t*)Param->SetValue) != Value)) {
|
||||||
{
|
|
||||||
// Set new value
|
// Set new value
|
||||||
*((u_int16_t*)Param->SetValue) = Value;
|
*((u_int16_t*)Param->SetValue) = Value;
|
||||||
|
|
||||||
@@ -1288,8 +1260,7 @@ bool CDeviceCore::SetUnsignedValue( TDeviceParam * Param, const u_int32_t Value,
|
|||||||
|
|
||||||
case dtUnsigned32_HL :
|
case dtUnsigned32_HL :
|
||||||
case dtUnsigned32_LH :
|
case dtUnsigned32_LH :
|
||||||
if (Force || (*((u_int32_t*)Param->SetValue) != Value))
|
if (Force || (*((u_int32_t*)Param->SetValue) != Value)) {
|
||||||
{
|
|
||||||
// Set new value
|
// Set new value
|
||||||
*((u_int32_t*)Param->SetValue) = Value;
|
*((u_int32_t*)Param->SetValue) = Value;
|
||||||
|
|
||||||
@@ -1313,11 +1284,9 @@ bool CDeviceCore::SetSignedValue( TDeviceParam * Param, const int32_t Value, boo
|
|||||||
if (!Param)
|
if (!Param)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (Param->DataType)
|
switch (Param->DataType) {
|
||||||
{
|
|
||||||
case dtBool :
|
case dtBool :
|
||||||
if (Force || (*((bool*)Param->SetValue) != Value))
|
if (Force || (*((bool*)Param->SetValue) != Value)) {
|
||||||
{
|
|
||||||
// Set new value
|
// Set new value
|
||||||
*((bool*)Param->SetValue) = Value;
|
*((bool*)Param->SetValue) = Value;
|
||||||
|
|
||||||
@@ -1327,8 +1296,7 @@ bool CDeviceCore::SetSignedValue( TDeviceParam * Param, const int32_t Value, boo
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case dtSigned16 :
|
case dtSigned16 :
|
||||||
if (Force || (*((int16_t*)Param->SetValue) != Value))
|
if (Force || (*((int16_t*)Param->SetValue) != Value)) {
|
||||||
{
|
|
||||||
// Set new value
|
// Set new value
|
||||||
*((int16_t*)Param->SetValue) = Value;
|
*((int16_t*)Param->SetValue) = Value;
|
||||||
|
|
||||||
@@ -1339,8 +1307,7 @@ bool CDeviceCore::SetSignedValue( TDeviceParam * Param, const int32_t Value, boo
|
|||||||
|
|
||||||
case dtSigned32_HL :
|
case dtSigned32_HL :
|
||||||
case dtSigned32_LH :
|
case dtSigned32_LH :
|
||||||
if (Force || (*((int32_t*)Param->SetValue) != Value))
|
if (Force || (*((int32_t*)Param->SetValue) != Value)) {
|
||||||
{
|
|
||||||
// Set new value
|
// Set new value
|
||||||
*((int32_t*)Param->SetValue) = Value;
|
*((int32_t*)Param->SetValue) = Value;
|
||||||
|
|
||||||
@@ -1364,12 +1331,10 @@ bool CDeviceCore::SetFloatValue( TDeviceParam * Param, const float Value, bool F
|
|||||||
if (!Param)
|
if (!Param)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
switch (Param->DataType)
|
switch (Param->DataType) {
|
||||||
{
|
|
||||||
case dtFloat32_L :
|
case dtFloat32_L :
|
||||||
case dtFloat32_B :
|
case dtFloat32_B :
|
||||||
if (Force || (*((float*)Param->SetValue) != Value))
|
if (Force || (*((float*)Param->SetValue) != Value)) {
|
||||||
{
|
|
||||||
// Set new value
|
// Set new value
|
||||||
*((float*)Param->SetValue) = Value;
|
*((float*)Param->SetValue) = Value;
|
||||||
|
|
||||||
@@ -1394,8 +1359,7 @@ bool CDeviceCore::SetStringValue( TDeviceParam * Param, const char * Value, cons
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Update register
|
// Update register
|
||||||
if (Force || !CompareParamString( (char*)Param->Value, Param->Len, Value, Len))
|
if (Force || !CompareParamString( (char*)Param->Value, Param->Len, Value, Len)) {
|
||||||
{
|
|
||||||
if (Len >= Param->SetLen) {
|
if (Len >= Param->SetLen) {
|
||||||
// Copy full register length (ignore additional bytes)
|
// Copy full register length (ignore additional bytes)
|
||||||
memcpy( Param->SetValue, Value, Param->SetLen );
|
memcpy( Param->SetValue, Value, Param->SetLen );
|
||||||
@@ -1429,13 +1393,11 @@ bool CDeviceCore::SetValue( TDeviceParam * Param, const char * Value, const int
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check if string
|
// Check if string
|
||||||
if (Param->DataType == dtString)
|
if (Param->DataType == dtString) {
|
||||||
{
|
|
||||||
// Simply set string
|
// Simply set string
|
||||||
SetStringValue( Param, Value, Len, Force );
|
SetStringValue( Param, Value, Len, Force );
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
// Ensure string is zero terminated
|
// Ensure string is zero terminated
|
||||||
if (Value[Len] != 0) {
|
if (Value[Len] != 0) {
|
||||||
TempStr = strndup( Value, Len );
|
TempStr = strndup( Value, Len );
|
||||||
@@ -1444,8 +1406,7 @@ bool CDeviceCore::SetValue( TDeviceParam * Param, const char * Value, const int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert to correct type
|
// Convert to correct type
|
||||||
switch (Param->DataType)
|
switch (Param->DataType) {
|
||||||
{
|
|
||||||
case dtBool :
|
case dtBool :
|
||||||
case dtUnsigned16 :
|
case dtUnsigned16 :
|
||||||
case dtUnsigned32_HL :
|
case dtUnsigned32_HL :
|
||||||
@@ -1472,10 +1433,9 @@ bool CDeviceCore::SetValue( TDeviceParam * Param, const char * Value, const int
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear memory
|
// Clear memory
|
||||||
if (UseTempStr) {
|
if (UseTempStr)
|
||||||
free( TempStr );
|
free( TempStr );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -1489,8 +1449,7 @@ bool CDeviceCore::GetValue( TDeviceParam * Param, char * Value, int &Len )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if return value longer than actual value
|
// Check if return value longer than actual value
|
||||||
switch (Param->DataType)
|
switch (Param->DataType) {
|
||||||
{
|
|
||||||
case dtBool :
|
case dtBool :
|
||||||
sprintf( Value, "%u", (*((bool*)Param->Value)) );
|
sprintf( Value, "%u", (*((bool*)Param->Value)) );
|
||||||
break;
|
break;
|
||||||
@@ -1519,14 +1478,12 @@ bool CDeviceCore::GetValue( TDeviceParam * Param, char * Value, int &Len )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case dtString :
|
case dtString :
|
||||||
if (Len < Param->Len)
|
if (Len < Param->Len) {
|
||||||
{
|
|
||||||
// Only copy requested no of chars
|
// Only copy requested no of chars
|
||||||
memcpy( Value, Param->Value, Len );
|
memcpy( Value, Param->Value, Len );
|
||||||
Value[ Len ] = 0;
|
Value[ Len ] = 0;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
memcpy( Value, Param->Value, Param->Len );
|
memcpy( Value, Param->Value, Param->Len );
|
||||||
Value[ Param->Len ] = 0;
|
Value[ Param->Len ] = 0;
|
||||||
}
|
}
|
||||||
@@ -1548,15 +1505,14 @@ bool CDeviceCore::CompareParamString( const char * ParamValue, const int ParamLe
|
|||||||
// Compare Value against current value
|
// Compare Value against current value
|
||||||
if (Len >= ParamLen) {
|
if (Len >= ParamLen) {
|
||||||
// Compare full register length (ignore additional bytes)
|
// Compare full register length (ignore additional bytes)
|
||||||
if (memcmp( Value, ParamValue, ParamLen)) {
|
if (memcmp( Value, ParamValue, ParamLen))
|
||||||
Match = false;
|
Match = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
// Compare length of new value only
|
// Compare length of new value only
|
||||||
if (memcmp( ParamValue, Value, Len)) {
|
if (memcmp( ParamValue, Value, Len))
|
||||||
Match = false;
|
Match = false;
|
||||||
}
|
|
||||||
// Remaining bytes must be null
|
// Remaining bytes must be null
|
||||||
else {
|
else {
|
||||||
for (Pos = (char*)ParamValue; Pos < (char*)ParamValue + ParamLen; Pos++) {
|
for (Pos = (char*)ParamValue; Pos < (char*)ParamValue + ParamLen; Pos++) {
|
||||||
@@ -1580,12 +1536,10 @@ bool CDeviceCore::TimedParamEvents()
|
|||||||
|
|
||||||
// Loop through all devices
|
// Loop through all devices
|
||||||
Device = FirstDevice;
|
Device = FirstDevice;
|
||||||
while (Device)
|
while (Device) {
|
||||||
{
|
|
||||||
// Loop through all Read parameters
|
// Loop through all Read parameters
|
||||||
while ((Param = GetNextReadParam( Device, Param ))) {
|
while ((Param = GetNextReadParam( Device, Param )))
|
||||||
EventOutput( Param, false );
|
EventOutput( Param, false );
|
||||||
}
|
|
||||||
Device = Device->Next;
|
Device = Device->Next;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -1641,8 +1595,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * SourceRef,
|
|||||||
|
|
||||||
// Get command command
|
// Get command command
|
||||||
GetCmdParam( Data, Value, &NextParam );
|
GetCmdParam( Data, Value, &NextParam );
|
||||||
if (!strcasecmp( "get", Value ))
|
if (!strcasecmp( "get", Value )) {
|
||||||
{
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if (!GetCmdParam( NextParam, Value, &NextParam)) {
|
if (!GetCmdParam( NextParam, Value, &NextParam)) {
|
||||||
strcpy( OutputStr, "- Missing device name" );
|
strcpy( OutputStr, "- Missing device name" );
|
||||||
@@ -1686,8 +1639,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * SourceRef,
|
|||||||
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!strcasecmp( "set", Value ))
|
else if (!strcasecmp( "set", Value )) {
|
||||||
{
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if (!GetCmdParam( NextParam, Value, &NextParam)) {
|
if (!GetCmdParam( NextParam, Value, &NextParam)) {
|
||||||
strcpy( OutputStr, "- Missing device name" );
|
strcpy( OutputStr, "- Missing device name" );
|
||||||
@@ -1732,8 +1684,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * SourceRef,
|
|||||||
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!strcasecmp( "status", Value ))
|
else if (!strcasecmp( "status", Value )) {
|
||||||
{
|
|
||||||
// Validate parameters
|
// Validate parameters
|
||||||
if (!GetCmdParam( NextParam, Value, &NextParam)) {
|
if (!GetCmdParam( NextParam, Value, &NextParam)) {
|
||||||
strcpy( OutputStr, "- Missing device name" );
|
strcpy( OutputStr, "- Missing device name" );
|
||||||
@@ -1760,8 +1711,7 @@ int CDeviceCore::HandleCommand( const char *ChannelName, const char * SourceRef,
|
|||||||
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
Output( ChannelName, NULL, true, OutputStr, strlen(OutputStr) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
// Unrecognised command
|
// Unrecognised command
|
||||||
strcpy( OutputStr, "- Unknown command");
|
strcpy( OutputStr, "- Unknown command");
|
||||||
Log->Message( LogLevel, dlMedium, "%s/%s: Channel '%s', %s%s",
|
Log->Message( LogLevel, dlMedium, "%s/%s: Channel '%s', %s%s",
|
||||||
@@ -1786,10 +1736,7 @@ bool CDeviceCore::EventOutput( TDeviceParam * Param, bool Force )
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check Timer or force
|
// Check Timer or force
|
||||||
if (Force ||
|
if (Force || (Param->EventInterval && Timeout( Param->EventTimeout, Param->EventInterval ))) {
|
||||||
(Param->EventInterval && Timeout( Param->EventTimeout, Param->EventInterval )) )
|
|
||||||
{
|
|
||||||
// Create message
|
|
||||||
// Post event
|
// Post event
|
||||||
if (true) {
|
if (true) {
|
||||||
// JSON output
|
// JSON output
|
||||||
@@ -1851,8 +1798,7 @@ bool CDeviceCore::EventOutput( TDeviceParam * Param, bool Force )
|
|||||||
JSONparse->WriteToString( NULL, EventMsg, EventLen, 0 );
|
JSONparse->WriteToString( NULL, EventMsg, EventLen, 0 );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
switch (Param->DataType)
|
switch (Param->DataType) {
|
||||||
{
|
|
||||||
case dtBool : sprintf( EventMsg, "%s: %u\n", Param->DataPath, *((bool*)Param->Value) );
|
case dtBool : sprintf( EventMsg, "%s: %u\n", Param->DataPath, *((bool*)Param->Value) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1886,10 +1832,9 @@ bool CDeviceCore::EventOutput( TDeviceParam * Param, bool Force )
|
|||||||
Output( Param->EventChannel, NULL, true, EventMsg, strlen(EventMsg) );
|
Output( Param->EventChannel, NULL, true, EventMsg, strlen(EventMsg) );
|
||||||
|
|
||||||
// Reset timer
|
// Reset timer
|
||||||
if (Param->EventInterval) {
|
if (Param->EventInterval)
|
||||||
SetStartTime( &(Param->EventTimeout) );
|
SetStartTime( &(Param->EventTimeout) );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -66,9 +66,7 @@ TEventEntry * CreateEvent( const char * EventType, const char * Parent, const
|
|||||||
// Check for minimum parameters
|
// Check for minimum parameters
|
||||||
if ((!EventType || !EventType[0]) || (!DeviceName || !DeviceName[0]) ||
|
if ((!EventType || !EventType[0]) || (!DeviceName || !DeviceName[0]) ||
|
||||||
(!DateTimeStr || !DateTimeStr[0]) || (!SourceName || !SourceName[0]))
|
(!DateTimeStr || !DateTimeStr[0]) || (!SourceName || !SourceName[0]))
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
// Create Blank Event Entry
|
// Create Blank Event Entry
|
||||||
Event = CreateEvent();
|
Event = CreateEvent();
|
||||||
@@ -171,16 +169,14 @@ CEventBuffer::~CEventBuffer()
|
|||||||
TEventType * NextEventType;
|
TEventType * NextEventType;
|
||||||
|
|
||||||
// Free Event List
|
// Free Event List
|
||||||
while (FirstItem)
|
while (FirstItem) {
|
||||||
{
|
|
||||||
NextItem = FirstItem->NextItem;
|
NextItem = FirstItem->NextItem;
|
||||||
DestroyItem( &FirstItem );
|
DestroyItem( &FirstItem );
|
||||||
FirstItem = NextItem;
|
FirstItem = NextItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free filters
|
// Free filters
|
||||||
while (FirstEventType)
|
while (FirstEventType) {
|
||||||
{
|
|
||||||
NextEventType = FirstEventType->Next;
|
NextEventType = FirstEventType->Next;
|
||||||
free( FirstEventType->Name );
|
free( FirstEventType->Name );
|
||||||
FirstEventType = NextEventType;
|
FirstEventType = NextEventType;
|
||||||
@@ -201,8 +197,7 @@ bool CEventBuffer::SetEventFilter( int n, ... )
|
|||||||
|
|
||||||
// Process Event Types
|
// Process Event Types
|
||||||
va_start( EventList, n );
|
va_start( EventList, n );
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++) {
|
||||||
{
|
|
||||||
// Create entry
|
// Create entry
|
||||||
*EventType = (TEventType*)malloc( sizeof(TEventType) );
|
*EventType = (TEventType*)malloc( sizeof(TEventType) );
|
||||||
|
|
||||||
@@ -263,8 +258,7 @@ bool CEventBuffer::AddEvent( TEventEntry * Event, unsigned int EventNo )
|
|||||||
TEventEntry * EventCopy = NULL;
|
TEventEntry * EventCopy = NULL;
|
||||||
|
|
||||||
// Validate Event
|
// Validate Event
|
||||||
if (PassEventFilter(Event))
|
if (PassEventFilter(Event)) {
|
||||||
{
|
|
||||||
// Save copy of event entry to Buffer
|
// Save copy of event entry to Buffer
|
||||||
EventCopy = CopyEvent( Event );
|
EventCopy = CopyEvent( Event );
|
||||||
EventCopy->EventNo = (!EventNo)? ++EventCount : EventNo;
|
EventCopy->EventNo = (!EventNo)? ++EventCount : EventNo;
|
||||||
|
|||||||
73
FileCore.cpp
73
FileCore.cpp
@@ -39,8 +39,7 @@ CFileCore::~CFileCore()
|
|||||||
TFileHandle * NextFile = NULL;
|
TFileHandle * NextFile = NULL;
|
||||||
|
|
||||||
// Destroy file specs
|
// Destroy file specs
|
||||||
while (FirstFile)
|
while (FirstFile) {
|
||||||
{
|
|
||||||
// Close file if open
|
// Close file if open
|
||||||
CloseFile( FirstFile );
|
CloseFile( FirstFile );
|
||||||
|
|
||||||
@@ -63,19 +62,16 @@ TFileHandle * CFileCore::AddFile( const char * Name, const char * Path, bool Ap
|
|||||||
TFileHandle ** FileHandle = NULL;
|
TFileHandle ** FileHandle = NULL;
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
if (!Name || !*Name || !Path || !*Path) {
|
if (!Name || !*Name || !Path || !*Path)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
// Find File or End of list
|
// Find File or End of list
|
||||||
FileHandle = &FirstFile;
|
FileHandle = &FirstFile;
|
||||||
while (*FileHandle && strcmp( Name, (*FileHandle)->Name )) {
|
while (*FileHandle && strcmp( Name, (*FileHandle)->Name ))
|
||||||
FileHandle = &((*FileHandle)->Next);
|
FileHandle = &((*FileHandle)->Next);
|
||||||
}
|
|
||||||
|
|
||||||
// Check if found
|
// Check if found
|
||||||
if (!*FileHandle)
|
if (!*FileHandle) {
|
||||||
{
|
|
||||||
// Create new
|
// Create new
|
||||||
*FileHandle = (TFileHandle*)calloc( 1, sizeof(TFileHandle) );
|
*FileHandle = (TFileHandle*)calloc( 1, sizeof(TFileHandle) );
|
||||||
|
|
||||||
@@ -85,9 +81,8 @@ TFileHandle * CFileCore::AddFile( const char * Name, const char * Path, bool Ap
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create Channel if necessary
|
// Create Channel if necessary
|
||||||
if (CreateChannel) {
|
if (CreateChannel)
|
||||||
AddChannel( Name, CH_ready );
|
AddChannel( Name, CH_ready );
|
||||||
}
|
|
||||||
|
|
||||||
// Set Parameters
|
// Set Parameters
|
||||||
(*FileHandle)->Append = Append;
|
(*FileHandle)->Append = Append;
|
||||||
@@ -101,9 +96,8 @@ TFileHandle * CFileCore::AddFile( const char * Name, const char * Path, bool Ap
|
|||||||
bool CFileCore::SetFilePersistence( TFileHandle * FileHandle, bool Persistent, int PersistTimeout )
|
bool CFileCore::SetFilePersistence( TFileHandle * FileHandle, bool Persistent, int PersistTimeout )
|
||||||
{
|
{
|
||||||
// Validate
|
// Validate
|
||||||
if (!FileHandle) {
|
if (!FileHandle)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// Set parameters
|
// Set parameters
|
||||||
FileHandle->Persistent = Persistent;
|
FileHandle->Persistent = Persistent;
|
||||||
@@ -126,19 +120,16 @@ bool CFileCore::SetFilePersistence( TFileHandle * FileHandle, bool Persistent, i
|
|||||||
bool CFileCore::OpenFile( TFileHandle * FileHandle )
|
bool CFileCore::OpenFile( TFileHandle * FileHandle )
|
||||||
{
|
{
|
||||||
// Validate
|
// Validate
|
||||||
if (!FileHandle) {
|
if (!FileHandle)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// Open file if not already open
|
// Open file if not already open
|
||||||
if (!isOpen( FileHandle ))
|
if (!isOpen( FileHandle )) {
|
||||||
{
|
|
||||||
// GEt file handle
|
// GEt file handle
|
||||||
(FileHandle)->FD = open( FileHandle->Path, O_WRONLY | O_CREAT | ((FileHandle->Append)? O_APPEND : O_TRUNC), 0664 );
|
(FileHandle)->FD = open( FileHandle->Path, O_WRONLY | O_CREAT | ((FileHandle->Append)? O_APPEND : O_TRUNC), 0664 );
|
||||||
|
|
||||||
// Report event
|
// Report event
|
||||||
if (isOpen(FileHandle))
|
if (isOpen(FileHandle)) {
|
||||||
{
|
|
||||||
// Set timer
|
// Set timer
|
||||||
SetStartTime( &(FileHandle->PersistTime) );
|
SetStartTime( &(FileHandle->PersistTime) );
|
||||||
|
|
||||||
@@ -149,8 +140,7 @@ bool CFileCore::OpenFile( TFileHandle * FileHandle )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if failed
|
// Check if failed
|
||||||
if (!isOpen(FileHandle))
|
if (!isOpen(FileHandle)) {
|
||||||
{
|
|
||||||
// Report result
|
// Report result
|
||||||
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: File '%s' - Could not open (%d) %s",
|
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: File '%s' - Could not open (%d) %s",
|
||||||
ProcessName, Name, FileHandle->Name, errno, strerror(errno) );
|
ProcessName, Name, FileHandle->Name, errno, strerror(errno) );
|
||||||
@@ -164,13 +154,11 @@ bool CFileCore::OpenFile( TFileHandle * FileHandle )
|
|||||||
bool CFileCore::CloseFile( TFileHandle * FileHandle )
|
bool CFileCore::CloseFile( TFileHandle * FileHandle )
|
||||||
{
|
{
|
||||||
// Validate
|
// Validate
|
||||||
if (!FileHandle) {
|
if (!FileHandle)
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// Close file if not already open
|
// Close file if not already open
|
||||||
if (isOpen(FileHandle))
|
if (isOpen(FileHandle)) {
|
||||||
{
|
|
||||||
// Close file
|
// Close file
|
||||||
close( FileHandle->FD );
|
close( FileHandle->FD );
|
||||||
FileHandle->FD = NO_FD;
|
FileHandle->FD = NO_FD;
|
||||||
@@ -179,7 +167,8 @@ bool CFileCore::CloseFile( TFileHandle * FileHandle )
|
|||||||
if (!isOpen(FileHandle)) {
|
if (!isOpen(FileHandle)) {
|
||||||
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: File '%s' - Closed",
|
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: File '%s' - Closed",
|
||||||
ProcessName, Name, FileHandle->Name );
|
ProcessName, Name, FileHandle->Name );
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: File '%s' - Could not close",
|
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: File '%s' - Could not close",
|
||||||
ProcessName, Name, FileHandle->Name );
|
ProcessName, Name, FileHandle->Name );
|
||||||
}
|
}
|
||||||
@@ -196,13 +185,11 @@ int CFileCore::ReadFromFD( int FD, char * Data, int MaxLen )
|
|||||||
bool Error = false;
|
bool Error = false;
|
||||||
|
|
||||||
// Check if buffer created
|
// Check if buffer created
|
||||||
if ((FD == -1) || !Data) {
|
if ((FD == -1) || !Data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
// Read Data into buffer
|
// Read Data into buffer
|
||||||
while (DataRemain)
|
while (DataRemain) {
|
||||||
{
|
|
||||||
// Read from file descriptor
|
// Read from file descriptor
|
||||||
BytesRead = read( FD, &Data[TotalRead], DataRemain );
|
BytesRead = read( FD, &Data[TotalRead], DataRemain );
|
||||||
if (BytesRead <= 0) {
|
if (BytesRead <= 0) {
|
||||||
@@ -215,11 +202,9 @@ int CFileCore::ReadFromFD( int FD, char * Data, int MaxLen )
|
|||||||
TotalRead += BytesRead;
|
TotalRead += BytesRead;
|
||||||
DataRemain -= BytesRead;
|
DataRemain -= BytesRead;
|
||||||
|
|
||||||
if (DataRemain) {
|
if (DataRemain)
|
||||||
usleep( 500 );
|
usleep( 500 );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (Error)? -TotalRead : TotalRead; // Report negative total on error
|
return (Error)? -TotalRead : TotalRead; // Report negative total on error
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -232,13 +217,11 @@ int CFileCore::WriteToFD( int FD, const char * Data, int Len )
|
|||||||
bool Error = false;
|
bool Error = false;
|
||||||
|
|
||||||
// Check if buffer created
|
// Check if buffer created
|
||||||
if ((FD == -1) || !DataRemain) {
|
if ((FD == -1) || !DataRemain)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
// Read Data into buffer
|
// Read Data into buffer
|
||||||
while (DataRemain)
|
while (DataRemain) {
|
||||||
{
|
|
||||||
// Read from file descriptor
|
// Read from file descriptor
|
||||||
BytesWritten = write( FD, &Data[TotalWritten], DataRemain );
|
BytesWritten = write( FD, &Data[TotalWritten], DataRemain );
|
||||||
if ((BytesWritten <= 0) && (errno != EAGAIN)) {
|
if ((BytesWritten <= 0) && (errno != EAGAIN)) {
|
||||||
@@ -251,10 +234,9 @@ int CFileCore::WriteToFD( int FD, const char * Data, int Len )
|
|||||||
TotalWritten += BytesWritten;
|
TotalWritten += BytesWritten;
|
||||||
DataRemain -= BytesWritten;
|
DataRemain -= BytesWritten;
|
||||||
|
|
||||||
if (DataRemain) {
|
if (DataRemain)
|
||||||
usleep( 500 );
|
usleep( 500 );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return (Error)? -TotalWritten : TotalWritten; // Report negative total on error
|
return (Error)? -TotalWritten : TotalWritten; // Report negative total on error
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -266,16 +248,13 @@ int CFileCore::Input( const char * ChannelName, const char * SourceRef, const ch
|
|||||||
int BytesWritten = 0;
|
int BytesWritten = 0;
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
if (!ChannelName || !Data) {
|
if (!ChannelName || !Data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
else if (Len == -1)
|
||||||
else if (Len == -1) {
|
|
||||||
Len = strlen( Data );
|
Len = strlen( Data );
|
||||||
};
|
|
||||||
|
|
||||||
// Get Channel
|
// Get Channel
|
||||||
if (!(FileHandle = GetFile( ChannelName )))
|
if (!(FileHandle = GetFile( ChannelName ))) {
|
||||||
{
|
|
||||||
// Log event
|
// Log event
|
||||||
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Channel '%s' - Input rejected, Channel not found",
|
if (Log) Log->Message( LogLevel, dlHigh, "%s/%s: Channel '%s' - Input rejected, Channel not found",
|
||||||
ProcessName, Name, ChannelName );
|
ProcessName, Name, ChannelName );
|
||||||
@@ -287,9 +266,8 @@ int CFileCore::Input( const char * ChannelName, const char * SourceRef, const ch
|
|||||||
ProcessName, Name, ChannelName );
|
ProcessName, Name, ChannelName );
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
if (!OpenFile( FileHandle )) {
|
if (!OpenFile( FileHandle ))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
// Handle Incoming data
|
// Handle Incoming data
|
||||||
BytesWritten = WriteToFD( FileHandle->FD, Data, Len );
|
BytesWritten = WriteToFD( FileHandle->FD, Data, Len );
|
||||||
@@ -306,8 +284,7 @@ bool CFileCore::Process()
|
|||||||
|
|
||||||
// Close Persistent files not used
|
// Close Persistent files not used
|
||||||
FileHandle = FirstFile;
|
FileHandle = FirstFile;
|
||||||
while (FileHandle)
|
while (FileHandle) {
|
||||||
{
|
|
||||||
if (isOpen(FileHandle) &&
|
if (isOpen(FileHandle) &&
|
||||||
(!FileHandle->Persistent ||
|
(!FileHandle->Persistent ||
|
||||||
(FileHandle->PersistTimeout && Timeout( FileHandle->PersistTime, FileHandle->PersistTimeout )))) {
|
(FileHandle->PersistTimeout && Timeout( FileHandle->PersistTime, FileHandle->PersistTimeout )))) {
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ CFunctionCore::~CFunctionCore()
|
|||||||
TChannel * NextChannel = NULL;
|
TChannel * NextChannel = NULL;
|
||||||
|
|
||||||
// Destroy Channels
|
// Destroy Channels
|
||||||
while (FirstChannel)
|
while (FirstChannel) {
|
||||||
{
|
|
||||||
// Destroy Linked Channels
|
// Destroy Linked Channels
|
||||||
while (FirstChannel->FirstLink)
|
while (FirstChannel->FirstLink)
|
||||||
UnlinkChannel( FirstChannel->Name, FirstChannel->FirstLink->Function->Name, FirstChannel->FirstLink->Channel->Name );
|
UnlinkChannel( FirstChannel->Name, FirstChannel->FirstLink->Function->Name, FirstChannel->FirstLink->Channel->Name );
|
||||||
@@ -122,13 +121,10 @@ bool CFunctionCore::InitChannelLinks( CDataMember * LinkConfig )
|
|||||||
|
|
||||||
// Process each Channel
|
// Process each Channel
|
||||||
ChannelMember = LinkConfig->GetFirstChild();
|
ChannelMember = LinkConfig->GetFirstChild();
|
||||||
while (ChannelMember)
|
while (ChannelMember) {
|
||||||
{
|
if ((Channel = GetChannel( ChannelMember->GetName() ))) {
|
||||||
if ((Channel = GetChannel( ChannelMember->GetName() )))
|
|
||||||
{
|
|
||||||
FunctionMember = ChannelMember->GetElement( 0 );
|
FunctionMember = ChannelMember->GetElement( 0 );
|
||||||
while (FunctionMember)
|
while (FunctionMember) {
|
||||||
{
|
|
||||||
// Get Parameters
|
// Get Parameters
|
||||||
LinkChannel( Channel->Name,
|
LinkChannel( Channel->Name,
|
||||||
FunctionMember->GetChStr( "Function", NULL, true ),
|
FunctionMember->GetChStr( "Function", NULL, true ),
|
||||||
@@ -167,15 +163,13 @@ TChannel * CFunctionCore::AddChannel( const char * ChannelName, const EChannelSt
|
|||||||
TChannel ** Channel = NULL;
|
TChannel ** Channel = NULL;
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
if (!ChannelName) {
|
if (!ChannelName)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
// Check if exists
|
// Check if exists
|
||||||
Channel = &FirstChannel;
|
Channel = &FirstChannel;
|
||||||
while (*Channel && strcmp( ChannelName, (*Channel)->Name )) {
|
while (*Channel && strcmp( ChannelName, (*Channel)->Name ))
|
||||||
Channel = &((*Channel)->Next);
|
Channel = &((*Channel)->Next);
|
||||||
}
|
|
||||||
|
|
||||||
// Create if not exist
|
// Create if not exist
|
||||||
if (!*Channel) {
|
if (!*Channel) {
|
||||||
@@ -224,7 +218,6 @@ bool CFunctionCore::SetChannelInState( TChannel * Channel, const EChannelState S
|
|||||||
|
|
||||||
LinkChannel = LinkChannel->Next;
|
LinkChannel = LinkChannel->Next;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -258,18 +251,14 @@ EChannelState CFunctionCore::GetChannelOutState( TChannel * Channel, const char
|
|||||||
TChannelLink * LinkChannel = NULL;
|
TChannelLink * LinkChannel = NULL;
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
if (!Channel) {
|
if (!Channel)
|
||||||
return CH_off;
|
return CH_off;
|
||||||
}
|
else if (!TargetRef || !*TargetRef)
|
||||||
else if (!TargetRef || !*TargetRef) {
|
|
||||||
return Channel->OutState;
|
return Channel->OutState;
|
||||||
}
|
else if ((LinkChannel = GetLinkChannel( Channel, TargetRef )))
|
||||||
else if ((LinkChannel = GetLinkChannel( Channel, TargetRef ))) {
|
|
||||||
return LinkChannel->Channel->InState;
|
return LinkChannel->Channel->InState;
|
||||||
}
|
else
|
||||||
else {
|
|
||||||
return CH_off;
|
return CH_off;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -284,9 +273,8 @@ bool CFunctionCore::LinkChannel( const char * ChannelName, const char * LinkFunc
|
|||||||
// Check if Channels & Function exist
|
// Check if Channels & Function exist
|
||||||
if (!(Channel = GetChannel( ChannelName )) ||
|
if (!(Channel = GetChannel( ChannelName )) ||
|
||||||
!(LinkFunction = Application->GetFunction( LinkFunctionName )) ||
|
!(LinkFunction = Application->GetFunction( LinkFunctionName )) ||
|
||||||
!(LinkChannel = LinkFunction->GetChannel( LinkChannelName )) ) {
|
!(LinkChannel = LinkFunction->GetChannel( LinkChannelName )) )
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// Check if linked Channel exists
|
// Check if linked Channel exists
|
||||||
LinkedChannel = &(Channel->FirstLink);
|
LinkedChannel = &(Channel->FirstLink);
|
||||||
@@ -344,9 +332,8 @@ bool CFunctionCore::UnlinkChannel( const char * ChannelName, const char * LinkFu
|
|||||||
// Check if Channels & Function exist
|
// Check if Channels & Function exist
|
||||||
if (!(Channel = GetChannel( ChannelName )) ||
|
if (!(Channel = GetChannel( ChannelName )) ||
|
||||||
!(LinkFunction = Application->GetFunction( LinkFunctionName )) ||
|
!(LinkFunction = Application->GetFunction( LinkFunctionName )) ||
|
||||||
!(LinkChannel = LinkFunction->GetChannel( LinkChannelName )) ) {
|
!(LinkChannel = LinkFunction->GetChannel( LinkChannelName )) )
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
// Check if linked Channel exists
|
// Check if linked Channel exists
|
||||||
LinkedChannel = &(Channel->FirstLink);
|
LinkedChannel = &(Channel->FirstLink);
|
||||||
@@ -388,9 +375,8 @@ int CFunctionCore::Input( const char * ChannelName, const char * SourceRef, cons
|
|||||||
TChannel * Channel = NULL;
|
TChannel * Channel = NULL;
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
if (!ChannelName || !*ChannelName || !Data) {
|
if (!ChannelName || !*ChannelName || !Data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
// Get Channel
|
// Get Channel
|
||||||
if (!(Channel = GetChannel( ChannelName ))) {
|
if (!(Channel = GetChannel( ChannelName ))) {
|
||||||
@@ -406,9 +392,9 @@ int CFunctionCore::Input( const char * ChannelName, const char * SourceRef, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return processed bytes
|
// Return processed bytes
|
||||||
if (Len == -1) {
|
if (Len == -1)
|
||||||
Len = strlen( Data );
|
Len = strlen( Data );
|
||||||
}
|
|
||||||
if (Log) Log->Output( LogLevel, dlHigh, LogOutput, Data, Len, "%s/%s: Channel '%s'->'%s' - IN:",
|
if (Log) Log->Output( LogLevel, dlHigh, LogOutput, Data, Len, "%s/%s: Channel '%s'->'%s' - IN:",
|
||||||
ProcessName, Name, ((SourceRef && *SourceRef)? SourceRef : "(Any)"), ChannelName );
|
ProcessName, Name, ((SourceRef && *SourceRef)? SourceRef : "(Any)"), ChannelName );
|
||||||
return Len;
|
return Len;
|
||||||
@@ -421,9 +407,8 @@ int CFunctionCore::Output( const char * ChannelName, const char * TargetRef, con
|
|||||||
TChannel * Channel = NULL;
|
TChannel * Channel = NULL;
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
if (!ChannelName || !*ChannelName) {
|
if (!ChannelName || !*ChannelName)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
// Get Channel
|
// Get Channel
|
||||||
if (!(Channel = GetChannel( ChannelName ))) {
|
if (!(Channel = GetChannel( ChannelName ))) {
|
||||||
@@ -445,9 +430,8 @@ int CFunctionCore::Output( const TChannel * Channel, const char * TargetRef, con
|
|||||||
int OutLen = 0;
|
int OutLen = 0;
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
if (!Channel || !Data) {
|
if (!Channel || !Data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
// Log event
|
// Log event
|
||||||
if (Log) Log->Output( LogLevel, dlHigh, ((!OutputFormat)? LogOutput : OutputFormat), Data, Len, "%s/%s: Channel '%s'->'%s' - OUT:",
|
if (Log) Log->Output( LogLevel, dlHigh, ((!OutputFormat)? LogOutput : OutputFormat), Data, Len, "%s/%s: Channel '%s'->'%s' - OUT:",
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ TBufferItem * CItemBuffer::CreateItem( void * Entry, int Size )
|
|||||||
|
|
||||||
// Create Entry
|
// Create Entry
|
||||||
BufferItem->Size = Size;
|
BufferItem->Size = Size;
|
||||||
if (CopyEntries)
|
if (CopyEntries) {
|
||||||
{
|
|
||||||
// Create copy
|
// Create copy
|
||||||
if ((BufferItem->Entry = (void *)malloc( sizeof(char)*Size ))) {
|
if ((BufferItem->Entry = (void *)malloc( sizeof(char)*Size ))) {
|
||||||
// Copy Value
|
// Copy Value
|
||||||
@@ -58,8 +57,7 @@ TBufferItem * CItemBuffer::CreateItem( void * Entry, int Size )
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
// Use pointer as is
|
// Use pointer as is
|
||||||
BufferItem->Entry = Entry;
|
BufferItem->Entry = Entry;
|
||||||
}
|
}
|
||||||
@@ -123,9 +121,8 @@ void * CItemBuffer::Pop( int * Size )
|
|||||||
void * Entry;
|
void * Entry;
|
||||||
|
|
||||||
// Return entry
|
// Return entry
|
||||||
if ((Entry = Peek( Size ))) {
|
if ((Entry = Peek( Size )))
|
||||||
Delete();
|
Delete();
|
||||||
}
|
|
||||||
return Entry;
|
return Entry;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -179,8 +176,7 @@ void CItemBuffer::DeleteAll()
|
|||||||
{
|
{
|
||||||
TBufferItem * NextItem;
|
TBufferItem * NextItem;
|
||||||
|
|
||||||
while (FirstItem)
|
while (FirstItem) {
|
||||||
{
|
|
||||||
NextItem = FirstItem->NextItem;
|
NextItem = FirstItem->NextItem;
|
||||||
DestroyItem( &FirstItem );
|
DestroyItem( &FirstItem );
|
||||||
FirstItem = NextItem;
|
FirstItem = NextItem;
|
||||||
|
|||||||
@@ -279,17 +279,14 @@ bool CLiteProtocol::AppendCommandStr( char * pString, int &pLength )
|
|||||||
Start = 0;
|
Start = 0;
|
||||||
|
|
||||||
// Look for other markers
|
// Look for other markers
|
||||||
while (Pos < pLength)
|
while (Pos < pLength) {
|
||||||
{
|
|
||||||
// Check if start character
|
// Check if start character
|
||||||
if (pString[Pos] == StartChar)
|
if (pString[Pos] == StartChar) {
|
||||||
{
|
|
||||||
// Mark start point
|
// Mark start point
|
||||||
Start = Pos;
|
Start = Pos;
|
||||||
}
|
}
|
||||||
// Check if end character with valid start
|
// Check if end character with valid start
|
||||||
else if ((pString[Pos] == EndChar) && (Start < pLength))
|
else if ((pString[Pos] == EndChar) && (Start < pLength)) {
|
||||||
{
|
|
||||||
// Mark end and continue
|
// Mark end and continue
|
||||||
End = Pos+1;
|
End = Pos+1;
|
||||||
break;
|
break;
|
||||||
@@ -300,8 +297,7 @@ bool CLiteProtocol::AppendCommandStr( char * pString, int &pLength )
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Check if anything available
|
// Check if anything available
|
||||||
if (Start < pLength)
|
if (Start < pLength) {
|
||||||
{
|
|
||||||
// Calculate length
|
// Calculate length
|
||||||
newLen = End - Start;
|
newLen = End - Start;
|
||||||
|
|
||||||
@@ -347,8 +343,7 @@ bool CLiteProtocol::AppendParam( const char * pString, const int pLength )
|
|||||||
int StringLen;
|
int StringLen;
|
||||||
|
|
||||||
// Check if valid
|
// Check if valid
|
||||||
if (!pLength || (!pString && (pLength == -1)))
|
if (!pLength || (!pString && (pLength == -1))) {
|
||||||
{
|
|
||||||
// Increase string length if required
|
// Increase string length if required
|
||||||
StringLen = 0;
|
StringLen = 0;
|
||||||
IncCommandStr( Length + 1 );
|
IncCommandStr( Length + 1 );
|
||||||
@@ -357,8 +352,7 @@ bool CLiteProtocol::AppendParam( const char * pString, const int pLength )
|
|||||||
CommandStr[CurrPos+StringLen] = Separator;
|
CommandStr[CurrPos+StringLen] = Separator;
|
||||||
Length += 1; // Allow for separator character
|
Length += 1; // Allow for separator character
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
// Increase string length if required
|
// Increase string length if required
|
||||||
StringLen = (pLength < 0)? strlen(pString) : pLength;
|
StringLen = (pLength < 0)? strlen(pString) : pLength;
|
||||||
IncCommandStr( Length + StringLen+1 );
|
IncCommandStr( Length + StringLen+1 );
|
||||||
@@ -501,8 +495,7 @@ char const * CLiteProtocol::GetParam( char ** pString, int * pLength )
|
|||||||
char * Mark = NULL;
|
char * Mark = NULL;
|
||||||
|
|
||||||
// Check if valid parameter no
|
// Check if valid parameter no
|
||||||
if (!Verified)
|
if (!Verified) {
|
||||||
{
|
|
||||||
if (pString) *pString = NULL;
|
if (pString) *pString = NULL;
|
||||||
if (pLength) pLength = 0;
|
if (pLength) pLength = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -529,8 +522,7 @@ bool CLiteProtocol::CreateCommand( char const * From, char const * To, char cons
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Insert Parameters in correct order
|
// Insert Parameters in correct order
|
||||||
if (!AppendParam( From ) || !AppendParam( To ) || !AppendParam( Command ))
|
if (!AppendParam( From ) || !AppendParam( To ) || !AppendParam( Command )) {
|
||||||
{
|
|
||||||
ClearCommandStr();
|
ClearCommandStr();
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -89,9 +89,9 @@ void CSelect::Add( int FD, bool Read, bool Write, THandle * Handle, CSelectableB
|
|||||||
|
|
||||||
// Check if SelectHandle already exists
|
// Check if SelectHandle already exists
|
||||||
SelectHandle = &FirstHandle;
|
SelectHandle = &FirstHandle;
|
||||||
while (*SelectHandle && ((*SelectHandle)->FD != FD)) {
|
while (*SelectHandle && ((*SelectHandle)->FD != FD))
|
||||||
SelectHandle = &((*SelectHandle)->Next);
|
SelectHandle = &((*SelectHandle)->Next);
|
||||||
}
|
|
||||||
if (!*SelectHandle) {
|
if (!*SelectHandle) {
|
||||||
// Create if not exist
|
// Create if not exist
|
||||||
*SelectHandle = new TSelectHandle;
|
*SelectHandle = new TSelectHandle;
|
||||||
@@ -151,9 +151,9 @@ void CSelect::Remove( int FD, bool Read, bool Write )
|
|||||||
|
|
||||||
// Check if SelectHandle already exists
|
// Check if SelectHandle already exists
|
||||||
SelectHandle = &FirstHandle;
|
SelectHandle = &FirstHandle;
|
||||||
while (*SelectHandle && ((*SelectHandle)->FD != FD)) {
|
while (*SelectHandle && ((*SelectHandle)->FD != FD))
|
||||||
SelectHandle = &((*SelectHandle)->Next);
|
SelectHandle = &((*SelectHandle)->Next);
|
||||||
}
|
|
||||||
// Check if found
|
// Check if found
|
||||||
if (!*SelectHandle)
|
if (!*SelectHandle)
|
||||||
return;
|
return;
|
||||||
@@ -210,10 +210,9 @@ bool CSelect::Test()
|
|||||||
// Update Maximum Test FD
|
// Update Maximum Test FD
|
||||||
if (Handle->FD == MaxFD-1) {
|
if (Handle->FD == MaxFD-1) {
|
||||||
for (TestFD = MaxFD-1; TestFD >= 0; TestFD--) {
|
for (TestFD = MaxFD-1; TestFD >= 0; TestFD--) {
|
||||||
if (FD_ISSET( TestFD, &ReadTestFDS ) || FD_ISSET( TestFD, &WriteTestFDS )) {
|
if (FD_ISSET( TestFD, &ReadTestFDS ) || FD_ISSET( TestFD, &WriteTestFDS ))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
MaxFD = TestFD+1;
|
MaxFD = TestFD+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -235,7 +235,6 @@ bool CSelectableBare::SetInBuffer( THandle * Handle, int InBufSize, int InTimeou
|
|||||||
memcpy( Handle->InMarker, InMarker, InMarkerLen );
|
memcpy( Handle->InMarker, InMarker, InMarkerLen );
|
||||||
Handle->InMarker[InMarkerLen] = 0;
|
Handle->InMarker[InMarkerLen] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -391,6 +390,7 @@ bool CSelectableBare::Close( THandle * Handle, bool QuickReopen )
|
|||||||
// Device Interface
|
// Device Interface
|
||||||
bool CSelectableBare::Read( THandle * Handle )
|
bool CSelectableBare::Read( THandle * Handle )
|
||||||
{
|
{
|
||||||
|
|
||||||
int BytesRead = 0;
|
int BytesRead = 0;
|
||||||
int BytesWaiting = -1;
|
int BytesWaiting = -1;
|
||||||
|
|
||||||
@@ -450,7 +450,6 @@ bool CSelectableBare::Read( THandle * Handle )
|
|||||||
|
|
||||||
// Reset timer
|
// Reset timer
|
||||||
SetStartTime( &(Handle->InStart) );
|
SetStartTime( &(Handle->InStart) );
|
||||||
|
|
||||||
return (bool)BytesRead;
|
return (bool)BytesRead;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -535,7 +534,6 @@ bool CSelectableBare::Write( THandle * Handle )
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -652,7 +650,6 @@ int CSelectableBare::Input( const char * ChannelName, const char * SourceRef, co
|
|||||||
ProcessName, Name, ((SourceRef && *SourceRef)? SourceRef : "(Any)"), ChannelName );
|
ProcessName, Name, ((SourceRef && *SourceRef)? SourceRef : "(Any)"), ChannelName );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BytesWritten;
|
return BytesWritten;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
@@ -733,7 +730,6 @@ int CSelectableBare::OutputHandle( THandle * Handle, const char * Data, int Len
|
|||||||
if (BytesWritten != 0)
|
if (BytesWritten != 0)
|
||||||
SetStartTime( &(Handle->LastAction) );
|
SetStartTime( &(Handle->LastAction) );
|
||||||
}
|
}
|
||||||
|
|
||||||
return BytesWritten;
|
return BytesWritten;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -79,8 +79,7 @@ bool CWatchdogCore::Process()
|
|||||||
CSelectableCore::Process();
|
CSelectableCore::Process();
|
||||||
|
|
||||||
// Watchdog ping
|
// Watchdog ping
|
||||||
if (Timeout( PingTimer, PingInterval ))
|
if (Timeout( PingTimer, PingInterval )) {
|
||||||
{
|
|
||||||
// Send command
|
// Send command
|
||||||
OutputHandle( Ping, Protocol->GetCommandStr(), Protocol->GetCommandLen() );
|
OutputHandle( Ping, Protocol->GetCommandStr(), Protocol->GetCommandLen() );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user