RecorderMutex.cpp 816 B

12345678910111213141516171819202122232425262728293031
  1. #include "RecorderMutex.h"
  2. #include <algorithm>
  3. namespace CameraRecorder {
  4. namespace Util {
  5. RecorderMutex::RecorderMutex()
  6. {
  7. }
  8. void RecorderMutex::RegisterRecording(const std::string& ipAddress)
  9. {
  10. std::unique_lock<std::mutex> lock(m_mutex);
  11. m_activeRecordings.push_back(ipAddress);
  12. }
  13. void RecorderMutex::UnregisterRecording(const std::string& ipAddress)
  14. {
  15. std::unique_lock<std::mutex> lock(m_mutex);
  16. m_activeRecordings.erase(std::remove(m_activeRecordings.begin(), m_activeRecordings.end(), ipAddress), m_activeRecordings.end());
  17. }
  18. bool RecorderMutex::IsRecording(const std::string& ipAddress)
  19. {
  20. std::unique_lock<std::mutex> lock(m_mutex);
  21. return std::find(m_activeRecordings.begin(), m_activeRecordings.end(), ipAddress) != m_activeRecordings.end();
  22. }
  23. } // namespace Util
  24. } // namespace CameraRecorder