Leosac  0.8.0
Open Source Access Control
WiegandConfig.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2017 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 
21 #include "modules/wiegand/WiegandConfig_odb.h"
22 #include <odb/pgsql/query.hxx>
23 
24 namespace Leosac
25 {
26 namespace Module
27 {
28 namespace Wiegand
29 {
30 constexpr std::array<const char *const, 8>
32 
34 {
35  readers_.push_back(reader);
36 }
37 
38 const std::vector<WiegandReaderConfigPtr> &WiegandConfig::readers() const
39 {
40  return readers_;
41 }
42 
43 void WiegandReaderConfig::validation_callback(odb::callback_event e,
44  odb::database &db) const
45 {
46  Device::validation_callback(e, db);
47 
48  if (e == odb::callback_event::post_update ||
49  e == odb::callback_event::post_persist)
50  {
51  if (std::find(valid_operation_modes.begin(), valid_operation_modes.end(),
52  mode) == valid_operation_modes.end())
53  {
54  throw ModelException("data/attributes/mode",
55  "Invalid wiegand-reader mode.");
56  }
57  }
58 }
59 }
60 }
61 }
Leosac::Module::Wiegand::WiegandConfig::add_reader
void add_reader(WiegandReaderConfigPtr)
Definition: WiegandConfig.cpp:33
Leosac::Module::Wiegand::WiegandConfig::readers_
std::vector< WiegandReaderConfigPtr > readers_
Definition: WiegandConfig.hpp:132
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::Wiegand::WiegandConfig::readers
const std::vector< WiegandReaderConfigPtr > & readers() const
Definition: WiegandConfig.cpp:38
ModelException.hpp
Leosac::Module::Wiegand::WiegandReaderConfig::validation_callback
void validation_callback(odb::callback_event, odb::database &) const
ODB callback wrt database operation.
Definition: WiegandConfig.cpp:43
ModelException
An exception class for general API error.
Definition: ModelException.hpp:33
Leosac::Module::Wiegand::WiegandReaderConfig::mode
std::string mode
Definition: WiegandConfig.hpp:96
Leosac::Module::Wiegand::WiegandReaderConfig::valid_operation_modes
constexpr static std::array< const char *const, 8 > valid_operation_modes
List of valid operation mode for a reader.
Definition: WiegandConfig.hpp:105
Leosac::Module::Wiegand::WiegandReaderConfigPtr
std::shared_ptr< WiegandReaderConfig > WiegandReaderConfigPtr
Definition: WiegandFwd.hpp:31