Leosac  0.7.0
OpenSourceAccessControl
AuthTarget.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 "AuthTarget.hpp"
21 #include "tools/log.hpp"
22 
23 using namespace Leosac::Auth;
24 
25 const std::string &AuthTarget::name() const
26 {
27  return name_;
28 }
29 
30 void AuthTarget::name(std::string const &param)
31 {
32  NOTICE("Changing target name (from " << name_ << " to " << param);
33  name_ = param;
34 }
35 
36 AuthTarget::AuthTarget(const std::string target_name)
37  : name_(target_name)
38 {
39 }
40 
42 {
43  always_open_.push_back(sched);
44 }
45 
47 {
48  always_close_.push_back(sched);
49 }
50 
52 {
53  return gpio_.get();
54 }
55 
56 void AuthTarget::gpio(std::unique_ptr<Leosac::Hardware::FGPIO> new_gpio)
57 {
58  gpio_ = std::move(new_gpio);
59 }
60 
62  const std::chrono::system_clock::time_point &tp) const
63 {
64  for (const auto &sched : always_open_)
65  {
66  if (sched->is_in_schedule(tp))
67  return true;
68  }
69  return false;
70 }
71 
73  const std::chrono::system_clock::time_point &tp) const
74 {
75  for (const auto &sched : always_close_)
76  {
77  if (sched->is_in_schedule(tp))
78  return true;
79  }
80  return false;
81 }
bool is_always_closed(const std::chrono::system_clock::time_point &tp) const
Check whether the door is in "always closed" mode at the given time point.
Definition: AuthTarget.cpp:72
std::vector< Tools::IScheduleCPtr > always_open_
Definition: AuthTarget.hpp:76
std::shared_ptr< const ISchedule > IScheduleCPtr
Definition: ToolsFwd.hpp:38
A Facade to a GPIO object.
Definition: FGPIO.hpp:45
std::vector< Tools::IScheduleCPtr > always_close_
Definition: AuthTarget.hpp:77
Hardware::FGPIO * gpio()
Returns the pointer to the optional FGPIO associated with the door.
Definition: AuthTarget.cpp:51
Definition: log.hpp:36
void add_always_open_sched(const Tools::IScheduleCPtr &sched)
Definition: AuthTarget.cpp:41
std::unique_ptr< Hardware::FGPIO > gpio_
Optional GPIO associated with the door.
Definition: AuthTarget.hpp:82
Holds classes relevant to the Authentication and Authorization subsystem.
Definition: AccessPoint.hpp:27
const std::string & name() const
Definition: AuthTarget.cpp:25
void add_always_close_sched(const Tools::IScheduleCPtr &sched)
Definition: AuthTarget.cpp:46
AuthTarget(const std::string target_name)
Definition: AuthTarget.cpp:36
bool is_always_open(const std::chrono::system_clock::time_point &tp) const
Check whether the door is in "always open" mode at the given time point.
Definition: AuthTarget.cpp:61