Phosphor
category_registry.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 2016 Couchbase, Inc
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
22 #pragma once
23 
24 #include <array>
25 #include <atomic>
26 #include <mutex>
27 #include <string>
28 #include <vector>
29 
30 #include "phosphor/platform/core.h"
31 
32 namespace phosphor {
33 
37  enum class CategoryStatus : char { Disabled, Enabled };
38 
39  using AtomicCategoryStatus = std::atomic<CategoryStatus>;
40 
41  // Forward declare
42  class StatsCallback;
43 
48  class PHOSPHOR_API CategoryRegistry {
49  public:
53  static constexpr int registry_size = 250;
54 
59 
70  const AtomicCategoryStatus& getStatus(const char* category_group);
71 
78  void updateEnabled(const std::vector<std::string>& enabled,
79  const std::vector<std::string>& disabled);
80 
90  void disableAll();
91 
102  static CategoryStatus calculateEnabled(
103  const std::string& category_group,
104  const std::vector<std::string>& enabled,
105  const std::vector<std::string>& disabled);
106 
111  void getStats(StatsCallback& addStats) const;
112 
113  protected:
122  CategoryStatus calculateEnabled(size_t index);
123 
124  mutable std::mutex mutex;
125 
126  std::array<std::string, registry_size> groups;
127  static constexpr int index_category_limit = 1;
128  static constexpr int index_metadata = 2;
129  static constexpr int index_non_default_categories = 3;
130 
131  std::array<AtomicCategoryStatus, registry_size> group_statuses;
132  std::atomic<size_t> group_count;
133 
134  std::vector<std::string> enabled_categories;
135  std::vector<std::string> disabled_categories;
136  };
137 }
Definition: category_registry.h:48
CategoryStatus
Definition: category_registry.h:37
Definition: category_registry.h:32
Definition: stats_callback.h:45