Kea 2.5.9
alarm_store.h
Go to the documentation of this file.
1// Copyright (C) 2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef ALARM_STORE_H
8#define ALARM_STORE_H
9
11#include <alarm.h>
12
13#include <boost/multi_index/indexed_by.hpp>
14#include <boost/multi_index/member.hpp>
15#include <boost/multi_index/mem_fun.hpp>
16#include <boost/multi_index/ordered_index.hpp>
17#include <boost/multi_index_container.hpp>
18#include <boost/multi_index/composite_key.hpp>
19#include <boost/multi_index/sequenced_index.hpp>
20#include <boost/multi_index/identity.hpp>
21#include <boost/scoped_ptr.hpp>
22
23#include <string>
24
25namespace isc {
26namespace perfmon {
27
30class DuplicateAlarm : public Exception {
31public:
32 DuplicateAlarm(const char* file, size_t line, const char* what) :
33 isc::Exception(file, line, what) {}
34};
35
38
48typedef boost::multi_index_container<
49 // It holds pointers to Lease6 objects.
51 boost::multi_index::indexed_by<
52 // Specification of the first index starts here.
53 // This index sorts using DurationKey::operators
54 boost::multi_index::ordered_unique<
55 boost::multi_index::tag<AlarmPrimaryKeyTag>,
56 boost::multi_index::identity<DurationKey>
57 >
58 >
60
62typedef std::vector<AlarmPtr> AlarmCollection;
63
65typedef boost::shared_ptr<AlarmCollection> AlarmCollectionPtr;
66
75public:
79 explicit AlarmStore(uint16_t family);
80
82 ~AlarmStore() = default;
83
103 const Duration& report_interval);
104
115 AlarmPtr addAlarm(DurationKeyPtr key, const Duration& low_water,
116 const Duration& high_water, bool enabled = true);
117
122
129
137 void updateAlarm(AlarmPtr& alarm);
138
144 void deleteAlarm(DurationKeyPtr key);
145
150
152 void clear();
153
157 uint16_t getFamily() {
158 return (family_);
159 }
160
161private:
169 void validateKey(const std::string& label, DurationKeyPtr key) const;
170
172 uint16_t family_;
173
175 AlarmContainer alarms_;
176
178 const boost::scoped_ptr<std::mutex> mutex_;
179};
180
181typedef boost::shared_ptr<AlarmStore> AlarmStorePtr;
182
183} // end of namespace perfmon
184} // end of namespace isc
185
186#endif
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Maintains an in-memory store of alarms.
Definition: alarm_store.h:74
~AlarmStore()=default
Destructor.
AlarmPtr checkDurationSample(DurationKeyPtr key, const Duration &sample, const Duration &report_interval)
Checks a sample against an alarm.
Definition: alarm_store.cc:43
void updateAlarm(AlarmPtr &alarm)
Updates an alarm in the store.
Definition: alarm_store.cc:116
void deleteAlarm(DurationKeyPtr key)
Removes the alarm from the store.
Definition: alarm_store.cc:132
AlarmCollectionPtr getAll()
Fetches all of the alarms (in order by target)
Definition: alarm_store.cc:148
AlarmPtr addAlarm(DurationKeyPtr key, const Duration &low_water, const Duration &high_water, bool enabled=true)
Creates a new alarm and adds it to the store.
Definition: alarm_store.cc:89
AlarmPtr getAlarm(DurationKeyPtr key)
Fetches a duration from the store for a given key.
Definition: alarm_store.cc:105
void clear()
Removes all alarms from the store.
Definition: alarm_store.cc:160
uint16_t getFamily()
Get protocol family.
Definition: alarm_store.h:157
Exception thrown when an attempt was made to add a duplicate key to either the duration or alarm stor...
Definition: alarm_store.h:30
DuplicateAlarm(const char *file, size_t line, const char *what)
Definition: alarm_store.h:32
boost::posix_time::time_duration Duration
boost::shared_ptr< DurationKey > DurationKeyPtr
Defines a pointer to a DurationKey instance.
std::vector< AlarmPtr > AlarmCollection
Type for a collection of AlarmPtrs.
Definition: alarm_store.h:62
boost::shared_ptr< AlarmCollection > AlarmCollectionPtr
Type for a pointer to a collection of AlarmPtrs.
Definition: alarm_store.h:65
boost::shared_ptr< AlarmStore > AlarmStorePtr
Definition: alarm_store.h:181
boost::shared_ptr< Alarm > AlarmPtr
Defines a pointer to an Alarm instance.
Definition: alarm.h:168
boost::multi_index_container< AlarmPtr, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< AlarmPrimaryKeyTag >, boost::multi_index::identity< DurationKey > > > > AlarmContainer
A multi index container holding pointers to alarms.
Definition: alarm_store.h:59
Defines the logger used by the top-level component of kea-lfc.
Tag for index by primary key (DurationKey).
Definition: alarm_store.h:37