Add RecorderMutex
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#include "RecorderMutex.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace CameraRecorder {
|
||||
namespace Util {
|
||||
|
||||
RecorderMutex::RecorderMutex()
|
||||
{
|
||||
}
|
||||
|
||||
void RecorderMutex::RegisterRecording(const std::string& ipAddress)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
m_activeRecordings.push_back(ipAddress);
|
||||
}
|
||||
|
||||
void RecorderMutex::UnregisterRecording(const std::string& ipAddress)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
m_activeRecordings.erase(std::remove(m_activeRecordings.begin(), m_activeRecordings.end(), ipAddress), m_activeRecordings.end());
|
||||
}
|
||||
|
||||
bool RecorderMutex::IsRecording(const std::string& ipAddress)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
return std::find(m_activeRecordings.begin(), m_activeRecordings.end(), ipAddress) != m_activeRecordings.end();
|
||||
}
|
||||
|
||||
} // namespace Util
|
||||
} // namespace CameraRecorder
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef UTIL_RECORDERMUTEX_H
|
||||
#define UTIL_RECORDERMUTEX_H
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace CameraRecorder {
|
||||
namespace Util {
|
||||
|
||||
class RecorderMutex
|
||||
{
|
||||
public:
|
||||
RecorderMutex();
|
||||
|
||||
void RegisterRecording(const std::string& ipAddress);
|
||||
void UnregisterRecording(const std::string& ipAddress);
|
||||
bool IsRecording(const std::string& ipAddress);
|
||||
|
||||
private:
|
||||
std::mutex m_mutex;
|
||||
std::vector<std::string> m_activeRecordings;
|
||||
};
|
||||
|
||||
typedef RecorderMutex* const RecorderMutexPointer;
|
||||
|
||||
} // namespace Util
|
||||
} // namespace CameraRecorder
|
||||
|
||||
#endif // UTIL_RECORDERMUTEX_H
|
||||
Reference in New Issue
Block a user