Skip to content

Commit c7e5515

Browse files
committed
re #1089: Make data collection setup fail if a device refers to a non-existent input channel
1 parent 9117a5e commit c7e5515

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

PlusLib/src/PlusDataCollection/vtkPlusDataCollector.cxx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ PlusStatus vtkPlusDataCollector::ReadConfiguration( vtkXMLDataElement* aConfig )
174174
vtkPlusDevice* thisDevice = NULL;
175175
if( this->GetDevice(thisDevice, deviceElement->GetAttribute("Id")) != PLUS_SUCCESS )
176176
{
177-
LOG_ERROR("Device " << deviceElement->GetAttribute("Id") << " doesn't exist.");
177+
LOG_ERROR("Device " << deviceElement->GetAttribute("Id") << " does not exist.");
178178
return PLUS_FAIL;
179179
}
180180
vtkXMLDataElement* inputChannelsElement = deviceElement->FindNestedElementWithName("InputChannels");
@@ -189,17 +189,32 @@ PlusStatus vtkPlusDataCollector::ReadConfiguration( vtkXMLDataElement* aConfig )
189189
if( STRCASECMP(inputChannelElement->GetName(), "InputChannel") == 0 )
190190
{
191191
// We have an input channel, lets find it
192+
const char* inputChannelId = inputChannelElement->GetAttribute("Id");
193+
if (inputChannelId == NULL)
194+
{
195+
LOG_ERROR("Device " << deviceElement->GetAttribute("Id") << " has an input channel without Id attribute.");
196+
return PLUS_FAIL;
197+
}
198+
vtkPlusChannel* aChannel = NULL;
192199
for( DeviceCollectionIterator it = Devices.begin(); it != Devices.end(); ++it )
193200
{
194201
vtkPlusDevice* device = (*it);
195-
vtkPlusChannel* aChannel = NULL;
196-
if( device->GetOutputChannelByName(aChannel, inputChannelElement->GetAttribute("Id")) == PLUS_SUCCESS )
202+
if (device->GetOutputChannelByName(aChannel, inputChannelId) == PLUS_SUCCESS)
197203
{
198204
// Found it!
199-
thisDevice->AddInputChannel(aChannel);
200205
break;
201206
}
202207
}
208+
if (aChannel == NULL)
209+
{
210+
LOG_ERROR("Device " << deviceElement->GetAttribute("Id") << " is specified to use channel " << inputChannelId << " as input, but an output channel by this Id does not exist");
211+
return PLUS_FAIL;
212+
}
213+
if (thisDevice->AddInputChannel(aChannel) != PLUS_SUCCESS)
214+
{
215+
LOG_ERROR("Failed to add input channel " << inputChannelId << " to device " << deviceElement->GetAttribute("Id"));
216+
return PLUS_FAIL;
217+
}
203218
}
204219
}
205220
}

PlusLib/src/PlusDataCollection/vtkPlusDevice.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,11 @@ PlusStatus vtkPlusDevice::GetOutputChannelByName( vtkPlusChannel*& aChannel, con
18701870
//----------------------------------------------------------------------------
18711871
PlusStatus vtkPlusDevice::AddInputChannel( vtkPlusChannel* aChannel )
18721872
{
1873+
if (aChannel == NULL)
1874+
{
1875+
LOCAL_LOG_ERROR("vtkPlusDevice::AddInputChannel failed: input channel is invalid");
1876+
return PLUS_FAIL;
1877+
}
18731878
for( ChannelContainerIterator it = InputChannels.begin(); it != InputChannels.end(); ++it )
18741879
{
18751880
if( STRCASECMP( ( *it )->GetChannelId(), aChannel->GetChannelId() ) == 0 )

0 commit comments

Comments
 (0)