Leosac  0.7.0
OpenSourceAccessControl
RplethModule.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 "modules/BaseModule.hpp"
25 #include "rplethpacket.hpp"
26 #include <memory>
27 #include <vector>
28 
29 namespace Leosac
30 {
31 namespace Module
32 {
37 namespace Rpleth
38 {
43 class RplethModule : public BaseModule
44 {
45  public:
46  RplethModule(zmqpp::context &ctx, zmqpp::socket *pipe,
47  const boost::property_tree::ptree &cfg, CoreUtilsPtr utils);
48 
49  ~RplethModule();
50 
51  RplethModule(const RplethModule &) = delete;
52 
53  RplethModule &operator=(const RplethModule &) = delete;
54 
64  static std::vector<uint8_t>
65  card_convert_from_text(const std::pair<std::string, int> &card_info);
66 
67  private:
68  void process_config();
69 
73  bool client_connected(const std::string &identity) const;
74 
79  bool client_failed(const std::string &identity) const;
80 
81  static constexpr int buffer_size = 8192;
82 
98  bool handle_client_msg(const std::string &client_identity, CircularBuffer &buf);
99 
104 
108  void handle_socket();
109 
115  void rpleth_send_cards(const RplethPacket &packet);
116 
123 
127  void rpleth_beep(const RplethPacket &p);
128 
132  void rpleth_greenled(const RplethPacket &p);
133 
138 
143 
148 
153 
158 
159  void restart_reader();
160 
164  boost::property_tree::ptree get_network_config();
165 
169  bool push_network_config(const boost::property_tree::ptree &tree);
170 
175  void rpleth_publish_card();
176 
182  void handle_wiegand_event();
183 
187  std::list<std::string> cards_pushed_;
188 
193  std::list<std::string> cards_read_;
194 
199  std::list<std::pair<std::string, int>> cards_read_stream_;
200 
201  std::map<std::string, CircularBuffer> clients_;
202 
203  zmqpp::context &ctx_;
204 
208  zmqpp::socket server_;
209 
214  zmqpp::socket bus_sub_;
215 
219  zmqpp::socket core_;
220 
224  std::unique_ptr<Hardware::FWiegandReader> reader_;
225 
232  std::vector<std::string> failed_clients_;
233 
235 };
236 }
237 }
238 }
RplethPacket rpleth_receive_cards(const RplethPacket &packet)
Handle Rpleth ReceiveUnpresentedCards command.
boost::property_tree::ptree get_network_config()
Retrieve the network configuration from the core.
RplethPacket get_dhcp_state()
Handle Rpleth GetDHCP command.
RplethPacket set_reader_ip(const RplethPacket &p)
Update the IP of this Leosac unit.
void rpleth_publish_card()
Flush the cards_read_stream_ list to clients.
void handle_socket()
Handle data available on server socket.
RplethPacket set_reader_gw(const RplethPacket &p)
Update the reader gateway.
This is the header file for a generated source file, GitSHA1.cpp.
bool handle_client_msg(const std::string &client_identity, CircularBuffer &buf)
Try to handle a client message.
std::map< std::string, CircularBuffer > clients_
void rpleth_send_cards(const RplethPacket &packet)
Handle Rpleth SendCards command: we will store the list of received card somewhere safe...
zmqpp::socket core_
REQ socket to core.
std::list< std::string > cards_pushed_
List of cards pushed by SendCards Rpleth command.
Implementation of a ring buffer.
RplethPacket set_dhcp_state(const RplethPacket &p)
Enable or disable DHCP.
Rpleth packet class.
static std::vector< uint8_t > card_convert_from_text(const std::pair< std::string, int > &card_info)
Convert a card number from textual hexadecimal representation to a 8 bytes byte-vector in Network Byt...
RplethPacket handle_client_packet(RplethPacket packet)
If we successfully built a packet, lets handle it.
zmqpp::socket bus_sub_
Subscribe to the message bus and listen for event sent by the wiegand reader we watch.
std::list< std::pair< std::string, int > > cards_read_stream_
If stream mode is on, all cards read are stored here.
std::vector< std::string > failed_clients_
Client that are "failed".
Main class for the Rpleth module.
Base class for module implementation.
Definition: BaseModule.hpp:110
RplethModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
void rpleth_beep(const RplethPacket &p)
Handle Rpleth Beep command.
bool client_failed(const std::string &identity) const
Is the client in an invalid state ?
simple circular buffer class
RplethModule & operator=(const RplethModule &)=delete
zmqpp::socket server_
Stream socket to receive Rpleth connection.
bool client_connected(const std::string &identity) const
Do we already know this client ?
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
std::list< std::string > cards_read_
Valid cards our Wiegand reader read: cards that were not pushed are not stored here.
RplethPacket set_reader_netmask(const RplethPacket &p)
Update netmask of this Leosac unit.
std::unique_ptr< Hardware::FWiegandReader > reader_
Interface to the reader.
void handle_wiegand_event()
We received a message (on the BUS, from the wiegand reader we watch), that means a card was inserted...
void rpleth_greenled(const RplethPacket &p)
Handle rpleth greenled command.
bool push_network_config(const boost::property_tree::ptree &tree)
Push a configuration to the core as the new network config.