Leosac  0.8.0
Open Source Access Control
DoormanDoor.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2022 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 "DoormanDoor.hpp"
21 #include "core/auth/AuthTarget.hpp"
22 #include "core/auth/Auth.hpp"
23 #include "tools/log.hpp"
24 
25 using namespace Leosac::Module::Doorman;
26 
27 DoormanDoor::DoormanDoor(const Auth::AuthTargetPtr &door, zmqpp::context &ctx)
28  : door_(door)
29  , bus_sub_(ctx, zmqpp::socket_type::sub)
30  , contact_triggered(false)
31 {
32  bus_sub_.connect("inproc://zmq-bus-pub");
33 
34  if (door->exitreq_gpio())
35  {
36  topic_exitreq_ = "S_INT:" + door->exitreq_gpio()->name();
37  bus_sub_.subscribe(topic_exitreq_);
38  }
39  if (door->contact_gpio())
40  {
41  topic_contact_ = "S_INT:" + door->contact_gpio()->name();
42  bus_sub_.subscribe(topic_contact_);
43  }
44 }
45 
47 {
48  return door_;
49 }
50 
51 zmqpp::socket &DoormanDoor::bus_sub()
52 {
53  return bus_sub_;
54 }
55 
57 {
58  std::string msg;
59  bus_sub_.receive(msg);
60 
61  if (msg == topic_exitreq_)
62  {
63  Hardware::FGPIO *gpio = door_->gpio();
64  if (gpio)
65  {
66  gpio->turnOn(door_->exitreq_duration());
67  }
68  }
69  else if (msg == topic_contact_)
70  {
71  // TODO: We don't use this information yet, we need the ALARM module first
73  contact_lastupdate = std::chrono::system_clock::now();
74  }
75 }
Leosac::Module::Doorman::DoormanDoor::contact_lastupdate
std::chrono::system_clock::time_point contact_lastupdate
Definition: DoormanDoor.hpp:74
Leosac::Module::Doorman::DoormanDoor::contact_triggered
bool contact_triggered
Definition: DoormanDoor.hpp:72
AuthTarget.hpp
zmqpp
Definition: CoreUtils.hpp:27
Auth.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::Module::Doorman::DoormanDoor::topic_exitreq_
std::string topic_exitreq_
Definition: DoormanDoor.hpp:68
Leosac::Module::Doorman::DoormanDoor::DoormanDoor
DoormanDoor(const Auth::AuthTargetPtr &door, zmqpp::context &ctx)
Create a new doorman door.
Definition: DoormanDoor.cpp:27
Leosac::Module::Doorman::DoormanDoor::door
Leosac::Auth::AuthTargetPtr door() const
Definition: DoormanDoor.cpp:46
Leosac::Module::Doorman::DoormanDoor::door_
Leosac::Auth::AuthTargetPtr door_
Definition: DoormanDoor.hpp:64
DoormanDoor.hpp
Leosac::Module::Doorman::DoormanDoor::handle_bus_msg
void handle_bus_msg()
Activity we care about happened on the bus.
Definition: DoormanDoor.cpp:56
Leosac::Module::Doorman::DoormanDoor::bus_sub
zmqpp::socket & bus_sub()
Definition: DoormanDoor.cpp:51
log.hpp
Leosac::Module::Doorman::DoormanDoor::bus_sub_
zmqpp::socket bus_sub_
Definition: DoormanDoor.hpp:66
Leosac::Module::Doorman
Module that allows user to configure action to be taken to react to messages from other modules.
Definition: DoormanDoor.hpp:31
Leosac::Hardware::FGPIO::turnOn
bool turnOn(std::chrono::milliseconds duration)
Turn the GPIO ON and turn it OFF duration milliseconds later.
Definition: FGPIO.cpp:34
Leosac::Module::Doorman::DoormanDoor::topic_contact_
std::string topic_contact_
Definition: DoormanDoor.hpp:70