summaryrefslogtreecommitdiffstats
path: root/src/conditions.hpp
blob: 54a6dc62ef0fdb5a0a90c44ed3d005d2a7086436 (plain)
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
#pragma once

#include <algorithm>
#include "data_types.hpp"

namespace phosphor
{
namespace dbus
{
namespace monitoring
{
namespace condition
{

template <typename T>
auto countAtOrAbove(Group& items, const char* path, size_t count, T&& value)
{
    return [&items,
            path,
            count,
            value = std::forward<T>(value)](T&& arg)
    {
        Group::iterator it =
            std::find_if(items.begin(),
                         items.end(),
                         [&path](auto const& item)
                         {
                             return std::get<0>(item) == path;
                         });
        if (it != std::end(items))
        {
            std::get<1>(*it) = arg;
        }
        size_t condCount =
            std::count_if(items.begin(),
                          items.end(),
                          [&value](auto const& item)
                          {
                              return std::get<1>(item) >= value;
                          });
        return condCount >= count;
    };
}

} // namespace condition
} // namespace monitoring
} // namespace dbus
} // namespace phosphor
OpenPOWER on IntegriCloud