Allow registration of multiple data handlers

This commit is contained in:
Martchus 2021-03-06 16:44:42 +01:00
parent cbfa8d8298
commit 29c0741984
2 changed files with 6 additions and 4 deletions

View File

@ -113,7 +113,7 @@ void BuildProcessSession::registerWebSession(std::shared_ptr<WebAPI::Session> &&
void BuildProcessSession::registerNewDataHandler(std::function<void(BuildProcessSession::BufferType, std::size_t)> &&handler)
{
std::unique_lock<std::mutex> lock(m_mutex);
m_newDataHandler = std::move(handler);
m_newDataHandlers.emplace_back(std::move(handler));
}
void BuildProcessSession::prpareLogFile()
@ -176,8 +176,10 @@ void BuildProcessSession::writeDataFromPipe(boost::system::error_code ec, std::s
sessionInfo->outstandingBuffersToSend.emplace_back(std::pair(m_buffer, bytesTransferred));
}
}
if (m_newDataHandler) {
m_newDataHandler(m_buffer, bytesTransferred);
for (const auto &handler : m_newDataHandlers) {
if (handler) {
handler(m_buffer, bytesTransferred);
}
}
}
// continue reading from the pipe unless there was an error

View File

@ -186,7 +186,7 @@ private:
std::mutex m_mutex;
BuffersToWrite m_logFileBuffers;
std::unordered_map<std::shared_ptr<WebAPI::Session>, std::unique_ptr<DataForWebSession>> m_registeredWebSessions;
std::function<void(BufferType, std::size_t)> m_newDataHandler;
std::vector<std::function<void(BufferType, std::size_t)>> m_newDataHandlers;
AssociatedLocks m_locks;
std::atomic_bool m_exited = false;
};