Skip to content

Commit 0b8e7d7

Browse files
committed
Add additional validity checks for broadcastMessage handling
1 parent aa73db8 commit 0b8e7d7

5 files changed

Lines changed: 43 additions & 21 deletions

File tree

Plugins/LfpDisplayNode/DisplayBuffer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ namespace LfpViewer {
9393

9494
Array<ChannelMetadata> channelMetadata;
9595

96-
void setFilteredChannels(Array<int> channels) {filteredChannels = channels;}
97-
9896
String name;
9997
int id;
10098

@@ -127,8 +125,6 @@ namespace LfpViewer {
127125
void removeDisplay(int splitID);
128126

129127
Array<int> displays;
130-
131-
Array<int> filteredChannels;
132128

133129
};
134130
};

Plugins/LfpDisplayNode/LfpDisplay.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ void LfpDisplay::rebuildDrawableChannelsList()
983983
Array<LfpChannelTrack> channelsToDraw; // all visible channels will be added to this array
984984
Array<int> filteredChannels;
985985
if(canvasSplit -> displayBuffer) {
986-
filteredChannels = canvasSplit -> displayBuffer -> filteredChannels;
986+
filteredChannels = canvasSplit -> getFilteredChannels();
987987
}
988988
// iterate over all channels and select drawable ones
989989
for (int i = 0, drawableChannelNum = 0, filterChannelIndex = 0; i < channels.size(); i++)

Plugins/LfpDisplayNode/LfpDisplayCanvas.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ class LfpDisplaySplitter : public Component,
342342
void refreshScreenBuffer();
343343

344344
bool shouldRebuildChannelList = false;
345+
346+
void setFilteredChannels(Array<int> channels){filteredChannels = channels;}
347+
Array<int> getFilteredChannels(){return filteredChannels;}
345348

346349
private:
347350

@@ -383,6 +386,8 @@ class LfpDisplaySplitter : public Component,
383386
int displayBufferSize;
384387

385388
int scrollBarThickness;
389+
390+
Array<int> filteredChannels = Array<int>();
386391

387392
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LfpDisplaySplitter);
388393

Plugins/LfpDisplayNode/LfpDisplayNode.cpp

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ void LfpDisplayNode::acknowledgeTrigger(int id)
329329
latestTrigger.set(id, -1);
330330
}
331331

332+
bool LfpDisplayNode::getIntField(DynamicObject::Ptr payload, String name, int& value, int lowerBound, int upperBound) {
333+
if(!payload->hasProperty(name) || !payload->getProperty(name).isInt())
334+
return false;
335+
int tempVal = payload->getProperty(name);
336+
if((upperBound != INT_MIN && tempVal > upperBound) || (lowerBound != INT_MAX && tempVal < lowerBound))
337+
return false;
338+
value = tempVal;
339+
return true;
340+
}
341+
342+
332343
void LfpDisplayNode::handleBroadcastMessage(String msg) {
333344
var parsedMessage = JSON::parse(msg);
334345
if(!parsedMessage.isObject())
@@ -343,29 +354,36 @@ void LfpDisplayNode::handleBroadcastMessage(String msg) {
343354
String command = jsonMessage -> getProperty("command");
344355
DynamicObject::Ptr payload = jsonMessage -> getProperty("payload").getDynamicObject();
345356
if(command == "filter") {
346-
if(payload.get() == nullptr)
357+
if(payload.get() == nullptr){
358+
LOGD("Tried to filter in LFPViewer, but could not find a payload");
347359
return;
348-
int streamID = payload -> getProperty("streamID");
349-
int start = payload -> getProperty("start");
350-
int rows = payload -> getProperty("rows");
351-
int cols = payload -> getProperty("cols");
352-
int colsPerRow = payload -> getProperty("colsPerRow");
353-
if(streamID < 0 || start < 0 || rows < 0 || cols < 0 || colsPerRow < 0){
360+
}
361+
int split, start, rows, cols, colsPerRow, end;
362+
if(!getIntField(payload, "split", split, 0, 2) || !getIntField(payload, "start", start, 0)) {
363+
LOGD("Tried to filter in LFPViewer, but a valid split and start weren't provided");
354364
return;
355365
}
356366
Array<int> channelNames;
357-
for(int row = 0; row < rows; row++) {
358-
for(int col = 0; col < cols; col++) {
359-
channelNames.add(start + col + row*colsPerRow);
367+
//If an end is specificed add channels from start to end
368+
//Else calculate the rectangular selection based on rows and columns
369+
if(getIntField(payload, "end", end, 0)) {
370+
for(int index = 0; index < (end - start); index++) {
371+
channelNames.add(start + index);
360372
}
361373
}
362-
displayBufferMap[streamID] -> setFilteredChannels(channelNames);
363-
for(auto split : splitDisplays) {
364-
split -> shouldRebuildChannelList = split->displayBuffer->id == streamID;
374+
else {
375+
if(!getIntField(payload, "rows", rows, 0) || !getIntField(payload, "cols", cols, 0) || !getIntField(payload, "colsPerRow", colsPerRow, 0)) {
376+
LOGD("Tried to filter by rectangular selection in LFPViewer, but valid row/column/columnsPerRow counts weren't provided");
377+
return;
378+
}
379+
for(int row = 0; row < rows; row++) {
380+
for(int col = 0; col < cols; col++) {
381+
channelNames.add(start + col + row*colsPerRow);
382+
}
383+
}
365384
}
366-
385+
splitDisplays[split] -> setFilteredChannels(channelNames);
386+
splitDisplays[split] -> shouldRebuildChannelList = true;
367387
}
368-
369-
370388
}
371389

Plugins/LfpDisplayNode/LfpDisplayNode.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ class LfpDisplayNode : public GenericProcessor
100100
/** Acknowledges receipt of a trigger for a given split display*/
101101
void acknowledgeTrigger(int splitId);
102102

103+
/** Reads from int value from payload, returns if the value was found and is within bounds*/
104+
bool getIntField(DynamicObject::Ptr payload, String name, int& value, int lowerBound = INT_MAX, int upperBound = INT_MIN);
105+
103106
/** Handles messages from other processors during acquisition*/
104107
void handleBroadcastMessage(String msg) override;
105108

0 commit comments

Comments
 (0)