Skip to content

Commit

Permalink
374 multiple pedestrians fix (#378)
Browse files Browse the repository at this point in the history
* pass copy of queue instead of reference, clear queue in get

* removing comment from timeStringParser description

* small change to clear queue functionality
  • Loading branch information
abey-yoseph authored May 19, 2022
1 parent eed67f9 commit 38f2034
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
16 changes: 12 additions & 4 deletions src/v2i-hub/PedestrianPlugin/src/FLIRWebSockAsyncClnSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,19 @@ namespace PedestrianPlugin
std::cout << beast::make_printable(buffer_.data()) << std::endl;
}

std::queue<std::string>& FLIRWebSockAsyncClnSession::getPSMQueue()
std::queue<std::string> FLIRWebSockAsyncClnSession::getPSMQueue()
{
std::lock_guard<mutex> lock(_psmLock);
return psmQueue;

//pass copy of the queue to Pedestrian Plugin
std::queue<std::string> queueToPass = psmQueue;

//empty the queue internally
std::queue<std::string> empty;
std::swap(psmQueue, empty);

return queueToPass;

}

vector<int> FLIRWebSockAsyncClnSession::timeStringParser(string dateTimeStr) const
Expand Down Expand Up @@ -368,7 +377,6 @@ namespace PedestrianPlugin
parsedArr.push_back(std::stoi(milliseconds));

return parsedArr;
}

}

}
17 changes: 10 additions & 7 deletions src/v2i-hub/PedestrianPlugin/src/PedestrianPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,16 @@ int PedestrianPlugin::checkXML()
else
{
//retrieve the PSM queue and send each one to be broadcast, then pop
std::queue<string> &currentPSMQueue = flirSession->getPSMQueue();

for (int i = 0; i < currentPSMQueue.size(); i++)
{
BroadcastPsm(const_cast<char*>(currentPSMQueue.front().c_str()));
currentPSMQueue.pop();
}
std::queue<string> currentPSMQueue = flirSession->getPSMQueue();

if (currentPSMQueue.size() > 0)
{
for (int i = 0; i < currentPSMQueue.size(); i++)
{
BroadcastPsm(const_cast<char*>(currentPSMQueue.front().c_str()));
currentPSMQueue.pop();
}
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ namespace PedestrianPlugin
on_close(beast::error_code ec);

/**
* @brief Get method for queue containing psm for all tracked pedestrians
* @brief Get method for queue containing psm for all tracked pedestrians. Copies the queue into
* a temporary queue and returns temporary queue. Clears the original queue.
*
* @return std::queue the psm queue
*/
std::queue<std::string> &getPSMQueue();
std::queue<std::string> getPSMQueue();

/**
* @brief Parses the datetime string that the camera returns into a vector containing each component
Expand All @@ -145,6 +146,7 @@ namespace PedestrianPlugin
* @return: vector with all components
*/
std::vector<int> timeStringParser(std::string dateTimeStr) const;
};
};

};

0 comments on commit 38f2034

Please sign in to comment.