-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSynchronizedConfiguration.h
More file actions
42 lines (34 loc) · 1.04 KB
/
SynchronizedConfiguration.h
File metadata and controls
42 lines (34 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// A synchronized wrapper for Configuration
//
// LICENSE: This file is distributed under the "Lesser GPL" (LGPL)
// license. License text is included with the source
// distribution.
#pragma once
#include "Configuration.h"
#include <mutex>
#include <optional>
class SynchronizedConfiguration {
public:
void addSetting(const PropertySetting& setting) {
std::lock_guard<std::mutex> lock(mutex_);
config_.addSetting(setting);
}
std::optional<PropertySetting> getSetting(const char* device,
const char* prop) {
std::lock_guard<std::mutex> lock(mutex_);
if (!config_.isPropertyIncluded(device, prop))
return std::nullopt;
return config_.getSetting(device, prop);
}
Configuration get() const {
std::lock_guard<std::mutex> lock(mutex_);
return config_;
}
void set(Configuration config) {
std::lock_guard<std::mutex> lock(mutex_);
config_ = std::move(config);
}
private:
mutable std::mutex mutex_;
Configuration config_;
};