Leosac  0.8.0
Open Source Access Control
AuthTarget.hpp
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 #pragma once
21 
23 #include "tools/ISchedule.hpp"
24 #include <memory>
25 #include <string>
26 
27 namespace Leosac
28 {
29 namespace Auth
30 {
31 class AuthTarget;
32 using AuthTargetPtr = std::shared_ptr<AuthTarget>;
33 
38 {
39  public:
40  virtual ~AuthTarget() = default;
41  explicit AuthTarget(const std::string target_name);
42 
43  const std::string &name() const;
44  void name(const std::string &new_name);
45 
48 
52  bool is_always_open(const std::chrono::system_clock::time_point &tp) const;
53 
57  bool is_always_closed(const std::chrono::system_clock::time_point &tp) const;
58 
59  /*
60  * Reset the door the its expected default state at the current time.
61  */
62  void resetToExpectedState(const std::chrono::system_clock::time_point &tp);
63 
75 
76  void gpio(std::unique_ptr<Hardware::FGPIO> new_gpio);
77 
79 
80  void exitreq_gpio(std::unique_ptr<Hardware::FGPIO> new_gpio);
81 
82  std::chrono::milliseconds exitreq_duration();
83 
84  void exitreq_duration(std::chrono::milliseconds duration);
85 
87 
88  void contact_gpio(std::unique_ptr<Hardware::FGPIO> new_gpio);
89 
90  std::chrono::milliseconds contact_duration();
91 
92  void contact_duration(std::chrono::milliseconds duration);
93 
94  protected:
95  std::string name_;
96 
97  std::vector<Tools::IScheduleCPtr> always_open_;
98  std::vector<Tools::IScheduleCPtr> always_close_;
99 
103  std::unique_ptr<Hardware::FGPIO> gpio_;
104 
108  std::unique_ptr<Hardware::FGPIO> exitreq_gpio_;
109 
113  std::chrono::milliseconds exitreq_duration_;
114 
118  std::unique_ptr<Hardware::FGPIO> contact_gpio_;
119 
123  std::chrono::milliseconds contact_duration_;
124 };
125 }
126 }
Leosac::Auth::AuthTarget::add_always_open_sched
void add_always_open_sched(const Tools::IScheduleCPtr &sched)
Definition: AuthTarget.cpp:42
FGPIO.hpp
Leosac::Auth::AuthTarget
Represent an object that we are authorizing against (a door).
Definition: AuthTarget.hpp:37
Leosac::Auth::AuthTarget::exitreq_gpio
Hardware::FGPIO * exitreq_gpio()
Leosac::Auth::AuthTarget::always_close_
std::vector< Tools::IScheduleCPtr > always_close_
Definition: AuthTarget.hpp:98
Leosac::Auth::AuthTarget::contact_duration
std::chrono::milliseconds contact_duration()
Leosac::Auth::AuthTarget::name
const std::string & name() const
Definition: AuthTarget.cpp:25
Leosac::Auth::AuthTarget::gpio
Hardware::FGPIO * gpio()
Returns the pointer to the optional FGPIO associated with the door.
Definition: AuthTarget.cpp:52
ISchedule.hpp
Leosac::Hardware::FGPIO
A Facade to a GPIO object.
Definition: FGPIO.hpp:45
Leosac::Auth::AuthTargetPtr
std::shared_ptr< AuthTarget > AuthTargetPtr
Definition: AuthFwd.hpp:93
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Auth::AuthTarget::gpio_
std::unique_ptr< Hardware::FGPIO > gpio_
Optional GPIO associated with the door.
Definition: AuthTarget.hpp:103
Leosac::Tools::IScheduleCPtr
std::shared_ptr< const ISchedule > IScheduleCPtr
Definition: ToolsFwd.hpp:38
Leosac::Auth::AuthTarget::~AuthTarget
virtual ~AuthTarget()=default
Leosac::Auth::AuthTarget::contact_gpio
Hardware::FGPIO * contact_gpio()
Leosac::Auth::AuthTarget::name_
std::string name_
Definition: AuthTarget.hpp:95
Leosac::Auth::AuthTarget::add_always_close_sched
void add_always_close_sched(const Tools::IScheduleCPtr &sched)
Definition: AuthTarget.cpp:47
Leosac::Auth::AuthTarget::exitreq_gpio_
std::unique_ptr< Hardware::FGPIO > exitreq_gpio_
Optional Exit Req GPIO associated with the door.
Definition: AuthTarget.hpp:108
Leosac::Auth::AuthTarget::exitreq_duration
std::chrono::milliseconds exitreq_duration()
Leosac::Auth::AuthTarget::always_open_
std::vector< Tools::IScheduleCPtr > always_open_
Definition: AuthTarget.hpp:97
Leosac::Auth::AuthTarget::resetToExpectedState
void resetToExpectedState(const std::chrono::system_clock::time_point &tp)
Definition: AuthTarget.cpp:104
Leosac::Auth::AuthTarget::is_always_closed
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:93
Leosac::Auth::AuthTarget::exitreq_duration_
std::chrono::milliseconds exitreq_duration_
Duration for the Exit Req to keep the door open.
Definition: AuthTarget.hpp:113
Leosac::Auth::AuthTarget::contact_duration_
std::chrono::milliseconds contact_duration_
Duration for the Contact Door Sensor to be ignored before triggering an alarm.
Definition: AuthTarget.hpp:123
Leosac::Auth::AuthTarget::AuthTarget
AuthTarget(const std::string target_name)
Definition: AuthTarget.cpp:36
Leosac::Auth::AuthTarget::contact_gpio_
std::unique_ptr< Hardware::FGPIO > contact_gpio_
Optional Contact Door Sensor GPIO associated with the door.
Definition: AuthTarget.hpp:118
Leosac::Auth::AuthTarget::is_always_open
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:82