Leosac  0.8.0
Open Source Access Control
ConfigChecker.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "ConfigChecker.hpp"
21 #include "tools/log.hpp"
22 
23 using namespace Leosac;
24 
25 void ConfigChecker::register_object(const std::string &name,
27 {
28  std::lock_guard<std::mutex> lg(mutex_);
29  ASSERT_LOG(objects_.count(name) == 0, "Already have an object with name "
30  << name << " registered");
31  objects_[name] = type;
32 }
33 
34 bool ConfigChecker::has_object(const std::string &name) const
35 {
36  std::lock_guard<std::mutex> lg(mutex_);
37  return objects_.count(name) != 0;
38 }
39 
40 bool ConfigChecker::has_object(const std::string &name,
41  const Leosac::Hardware::DeviceClass &type) const
42 {
43  std::lock_guard<std::mutex> lg(mutex_);
44  const auto itr = objects_.find(name);
45  return itr != objects_.end() && type == itr->second;
46 }
47 
49 {
50  std::lock_guard<std::mutex> lg(mutex_);
51  objects_.clear();
52 }
Leosac::Hardware::DeviceClass
DeviceClass
An enumeration describing the class of the device.
Definition: HardwareFwd.hpp:42
Leosac::ConfigChecker::has_object
bool has_object(const std::string &name) const
Check whether or not an object with name name is declared in the registry, no matter its type.
Definition: ConfigChecker.cpp:34
ASSERT_LOG
#define ASSERT_LOG(cond, msg)
Definition: log.hpp:190
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::ConfigChecker::clear
void clear()
Clear all informations.
Definition: ConfigChecker.cpp:48
Leosac::ConfigChecker::mutex_
std::mutex mutex_
Definition: ConfigChecker.hpp:74
Leosac::ConfigChecker::register_object
void register_object(const std::string &name, const Leosac::Hardware::DeviceClass &type)
Declare an object on the registry.
Definition: ConfigChecker.cpp:25
Leosac::ConfigChecker::objects_
std::map< std::string, Leosac::Hardware::DeviceClass > objects_
Definition: ConfigChecker.hpp:73
log.hpp
ConfigChecker.hpp