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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 | // Copyright (C) 2023 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Kea Hooks Basic
// Commercial End User License Agreement v2.0. See COPYING file in the premium/
// directory.
#include <config.h>
#include <config_cache.h><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <util/multi_threading_mgr.h>
using namespace isc;
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::util;
using namespace std;
namespace isc {
namespace ping_check {
PingCheckConfigPtr&
ConfigCache::getGlobalConfig() {
return (global_config_);
}
void
ConfigCache::setGlobalConfig(PingCheckConfigPtr& config) {
if (!config) {
isc_throw(BadValue, "ConfigCache - global config cannot be empty");
}
global_config_ = config;
}
bool
ConfigCache::findConfig(const SubnetID& subnet_id, PingCheckConfigPtr& config) {
MultiThreadingLock lock(*mutex_);
return (findConfigInternal(subnet_id, config));
}
bool
ConfigCache::findConfigInternal(const SubnetID& subnet_id, PingCheckConfigPtr& config) const {
auto it = configs_.find(subnet_id);
if (it != configs_.end()) {
config = it->second;
return (true);
}
config = PingCheckConfigPtr();
return (false);
}
PingCheckConfigPtr
ConfigCache::parseAndCacheConfig(const SubnetID& subnet_id, ConstElementPtr& user_context) {
PingCheckConfigPtr config;
if (user_context) {
ConstElementPtr ping_check_params = user_context->get("ping-check");
if (ping_check_params) {
// Copy construct from global to start with.
config.reset(new PingCheckConfig(*getGlobalConfig()));
// Now parse in subnet-specific values. This may throw a DhcpConfigError but
// that's OK, dealt with by the caller.
try {
config->parse(ping_check_params);
} catch (...) {
throw;
}
}
}
// Cache the config. We allow empty configs so higher precedence scopes may
// override lower precedence scopes.
cacheConfig(subnet_id, config);
return (config);
}
void
ConfigCache::cacheConfig(const SubnetID& subnet_id, PingCheckConfigPtr& config) {
MultiThreadingLock lock(*mutex_);
configs_[subnet_id] = config;
}
void
ConfigCache::flush() {
MultiThreadingLock lock(*mutex_);
// Discard the contents.
configs_.clear();
// We use modification time to remember the last time we flushed.
updateModificationTime();
}
size_t
ConfigCache::size() {
MultiThreadingLock lock(*mutex_);
return (configs_.size());
}
boost::posix_time::ptime
ConfigCache::getLastFlushTime() {
MultiThreadingLock lock(*mutex_);
return (BaseStampedElement::getModificationTime());
}
} // end of namespace ping_check
} // end of namespace isc
|