We need a lock around accessing the alarms map, because the onvif thread may clear an item while we are accessing it.

pull/3195/merge
Isaac Connor 2024-10-21 15:18:05 -04:00
parent 42914b63c0
commit 890f14860d
2 changed files with 6 additions and 1 deletions

View File

@ -341,6 +341,7 @@ class Monitor : public std::enable_shared_from_this<Monitor> {
PullPointSubscriptionBindingProxy proxyEvent; PullPointSubscriptionBindingProxy proxyEvent;
void set_credentials(struct soap *soap); void set_credentials(struct soap *soap);
std::unordered_map<std::string, std::string> alarms; std::unordered_map<std::string, std::string> alarms;
std::mutex alarms_mutex;
#endif #endif
public: public:
explicit ONVIF(Monitor *parent_); explicit ONVIF(Monitor *parent_);

View File

@ -187,7 +187,10 @@ void Monitor::ONVIF::WaitForMessage() {
// Apparently simple motion events, the value is boolean, but for people detection can be things like isMotion, isPeople // Apparently simple motion events, the value is boolean, but for people detection can be things like isMotion, isPeople
if (last_value.find("false") == 0) { if (last_value.find("false") == 0) {
Info("Triggered off ONVIF"); Info("Triggered off ONVIF");
alarms.erase(last_topic); {
std::unique_lock<std::mutex> lck(alarms_mutex);
alarms.erase(last_topic);
}
Debug(1, "ONVIF Alarms Empty: Alarms count is %zu, alarmed is %s, empty is %d ", alarms.size(), alarmed ? "true": "false", alarms.empty()); Debug(1, "ONVIF Alarms Empty: Alarms count is %zu, alarmed is %s, empty is %d ", alarms.size(), alarmed ? "true": "false", alarms.empty());
if (alarms.empty()) { if (alarms.empty()) {
alarmed = false; alarmed = false;
@ -285,6 +288,7 @@ int SOAP_ENV__Fault(struct soap *soap, char *faultcode, char *faultstring, char
void Monitor::ONVIF::SetNoteSet(Event::StringSet &noteSet) { void Monitor::ONVIF::SetNoteSet(Event::StringSet &noteSet) {
#ifdef WITH_GSOAP #ifdef WITH_GSOAP
std::unique_lock<std::mutex> lck(alarms_mutex);
if (alarms.empty()) return; if (alarms.empty()) return;
std::string note = ""; std::string note = "";