Leosac  0.8.0
Open Source Access Control
Leosac::Module::Rpleth::RplethModule Class Reference

Main class for the Rpleth module. More...

#include <RplethModule.hpp>

+ Inheritance diagram for Leosac::Module::Rpleth::RplethModule:
+ Collaboration diagram for Leosac::Module::Rpleth::RplethModule:

Public Member Functions

 RplethModule (zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
 
 ~RplethModule ()
 
 RplethModule (const RplethModule &)=delete
 
RplethModuleoperator= (const RplethModule &)=delete
 
- Public Member Functions inherited from Leosac::Module::BaseModule
 BaseModule (zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
 Constructor of BaseModule. More...
 
virtual ~BaseModule ()=default
 
virtual void run ()
 This is the main loop of the module. More...
 

Static Public Member Functions

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 Byte Order. More...
 

Private Member Functions

void process_config ()
 
bool client_connected (const std::string &identity) const
 Do we already know this client ? More...
 
bool client_failed (const std::string &identity) const
 Is the client in an invalid state ? More...
 
bool handle_client_msg (const std::string &client_identity, CircularBuffer &buf)
 Try to handle a client message. More...
 
RplethPacket handle_client_packet (RplethPacket packet)
 If we successfully built a packet, lets handle it. More...
 
void handle_socket ()
 Handle data available on server socket. More...
 
void rpleth_send_cards (const RplethPacket &packet)
 Handle Rpleth SendCards command: we will store the list of received card somewhere safe. More...
 
RplethPacket rpleth_receive_cards (const RplethPacket &packet)
 Handle Rpleth ReceiveUnpresentedCards command. More...
 
void rpleth_beep (const RplethPacket &p)
 Handle Rpleth Beep command. More...
 
void rpleth_greenled (const RplethPacket &p)
 Handle rpleth greenled command. More...
 
RplethPacket get_dhcp_state ()
 Handle Rpleth GetDHCP command. More...
 
RplethPacket set_dhcp_state (const RplethPacket &p)
 Enable or disable DHCP. More...
 
RplethPacket set_reader_ip (const RplethPacket &p)
 Update the IP of this Leosac unit. More...
 
RplethPacket set_reader_netmask (const RplethPacket &p)
 Update netmask of this Leosac unit. More...
 
RplethPacket set_reader_gw (const RplethPacket &p)
 Update the reader gateway. More...
 
void restart_reader ()
 
boost::property_tree::ptree get_network_config ()
 Retrieve the network configuration from the core. More...
 
bool push_network_config (const boost::property_tree::ptree &tree)
 Push a configuration to the core as the new network config. More...
 
void rpleth_publish_card ()
 Flush the cards_read_stream_ list to clients. More...
 
void handle_wiegand_event ()
 We received a message (on the BUS, from the wiegand reader we watch), that means a card was inserted. More...
 

Private Attributes

std::list< std::string > cards_pushed_
 List of cards pushed by SendCards Rpleth command. More...
 
std::list< std::string > cards_read_
 Valid cards our Wiegand reader read: cards that were not pushed are not stored here. More...
 
std::list< std::pair< std::string, int > > cards_read_stream_
 If stream mode is on, all cards read are stored here. More...
 
std::map< std::string, CircularBufferclients_
 
zmqpp::context & ctx_
 
zmqpp::socket server_
 Stream socket to receive Rpleth connection. More...
 
zmqpp::socket bus_sub_
 Subscribe to the message bus and listen for event sent by the wiegand reader we watch. More...
 
zmqpp::socket core_
 REQ socket to core. More...
 
std::unique_ptr< Hardware::FWiegandReaderreader_
 Interface to the reader. More...
 
std::vector< std::string > failed_clients_
 Client that are "failed". More...
 
bool stream_mode_
 

Static Private Attributes

static constexpr int buffer_size = 8192
 

Additional Inherited Members

- Protected Member Functions inherited from Leosac::Module::BaseModule
virtual void handle_pipe ()
 The base class register the pipe_ socket to its reactor_ so that this function is called when the pipe_ is available from reading. More...
 
virtual void handle_control ()
 Handle called when a message on the module's control socket arrives. More...
 
virtual void dump_additional_config (zmqpp::message *out) const
 Dump additional configuration (for example module specific config file). More...
 
void dump_config (ConfigManager::ConfigFormat fmt, zmqpp::message *out_msg) const
 Fills a message with the module's configuration information. More...
 
void config_check (const std::string &obj_name, Leosac::Hardware::DeviceClass type)
 An helper that checks configuration the existence of some objects. More...
 
void config_check (const std::string &obj_name)
 An helper that checks configuration the existence of some objects. More...
 
- Protected Attributes inherited from Leosac::Module::BaseModule
zmqpp::context & ctx_
 A reference to the ZeroMQ context in case you need it to create additional socket. More...
 
zmqpp::socket & pipe_
 A reference to the pair socket that link back to the module manager. More...
 
boost::property_tree::ptree config_
 The configuration tree passed to the start_module function. More...
 
CoreUtilsPtr utils_
 Pointer to the core utils, which gives access to scheduler and others. More...
 
bool is_running_
 Boolean indicating whether the main loop should run or not. More...
 
zmqpp::socket control_
 Control REP socket. More...
 
zmqpp::reactor reactor_
 The reactor object we poll() on in the main loop. More...
 
std::string name_
 

Detailed Description

Main class for the Rpleth module.

For configuration information, see Configuration Options.

Definition at line 43 of file RplethModule.hpp.

Constructor & Destructor Documentation

◆ RplethModule() [1/2]

RplethModule::RplethModule ( zmqpp::context &  ctx,
zmqpp::socket *  pipe,
const boost::property_tree::ptree &  cfg,
CoreUtilsPtr  utils 
)

Definition at line 33 of file RplethModule.cpp.

◆ ~RplethModule()

RplethModule::~RplethModule ( )

Definition at line 52 of file RplethModule.cpp.

◆ RplethModule() [2/2]

Leosac::Module::Rpleth::RplethModule::RplethModule ( const RplethModule )
delete

Member Function Documentation

◆ card_convert_from_text()

std::vector< uint8_t > RplethModule::card_convert_from_text ( const std::pair< std::string, int > &  card_info)
static

Convert a card number from textual hexadecimal representation to a 8 bytes byte-vector in Network Byte Order.

The format (Wiegand 26, 32, ...) is ingored. The whole frame will be used to compute the card serial number returned in the vector.

Parameters
card_infopair (string, int) with hex representation and number of bit.

Definition at line 386 of file RplethModule.cpp.

◆ client_connected()

bool RplethModule::client_connected ( const std::string &  identity) const
private

Do we already know this client ?

Definition at line 332 of file RplethModule.cpp.

◆ client_failed()

bool RplethModule::client_failed ( const std::string &  identity) const
private

Is the client in an invalid state ?

Returns
true if the client is in the clients_failed_ list.

Definition at line 337 of file RplethModule.cpp.

◆ get_dhcp_state()

RplethPacket RplethModule::get_dhcp_state ( )
private

Handle Rpleth GetDHCP command.

Definition at line 402 of file RplethModule.cpp.

◆ get_network_config()

boost::property_tree::ptree RplethModule::get_network_config ( )
private

Retrieve the network configuration from the core.

Definition at line 565 of file RplethModule.cpp.

◆ handle_client_msg()

bool RplethModule::handle_client_msg ( const std::string &  client_identity,
CircularBuffer buf 
)
private

Try to handle a client message.

This is called when we received any amount of data, for any client. If there isn't enough data to handle a rpleth message, this does nothing.

It returns true unless sending a packing would have blocked.

Note
There is a possible race between client disconnection and notification, so it sometime happens that we attempt to send data to an already disconnected client. This would block forever so we use dont_wait flag and report a failed client by returning false. Message from failed client are ignored until reception of disconnection notification.

Definition at line 110 of file RplethModule.cpp.

◆ handle_client_packet()

RplethPacket RplethModule::handle_client_packet ( RplethPacket  packet)
private

If we successfully built a packet, lets handle it.

Definition at line 140 of file RplethModule.cpp.

◆ handle_socket()

void RplethModule::handle_socket ( )
private

Handle data available on server socket.

Definition at line 72 of file RplethModule.cpp.

◆ handle_wiegand_event()

void RplethModule::handle_wiegand_event ( )
private

We received a message (on the BUS, from the wiegand reader we watch), that means a card was inserted.

We store all cards until we receive a RECEIVE_CARDS command.

Definition at line 196 of file RplethModule.cpp.

◆ operator=()

RplethModule& Leosac::Module::Rpleth::RplethModule::operator= ( const RplethModule )
delete

◆ process_config()

void RplethModule::process_config ( )
private

Definition at line 56 of file RplethModule.cpp.

◆ push_network_config()

bool RplethModule::push_network_config ( const boost::property_tree::ptree &  tree)
private

Push a configuration to the core as the new network config.

Definition at line 553 of file RplethModule.cpp.

◆ restart_reader()

void RplethModule::restart_reader ( )
private

Definition at line 584 of file RplethModule.cpp.

◆ rpleth_beep()

void RplethModule::rpleth_beep ( const RplethPacket p)
private

Handle Rpleth Beep command.

Definition at line 302 of file RplethModule.cpp.

◆ rpleth_greenled()

void RplethModule::rpleth_greenled ( const RplethPacket p)
private

Handle rpleth greenled command.

Definition at line 317 of file RplethModule.cpp.

◆ rpleth_publish_card()

void RplethModule::rpleth_publish_card ( )
private

Flush the cards_read_stream_ list to clients.

This will notify client of all card that we read.

Definition at line 343 of file RplethModule.cpp.

◆ rpleth_receive_cards()

RplethPacket RplethModule::rpleth_receive_cards ( const RplethPacket packet)
private

Handle Rpleth ReceiveUnpresentedCards command.

This sends cards that were read to the Rpleth client.

Returns
a response packet with the cards, ascii format, separated by a pipe.

Definition at line 254 of file RplethModule.cpp.

◆ rpleth_send_cards()

void RplethModule::rpleth_send_cards ( const RplethPacket packet)
private

Handle Rpleth SendCards command: we will store the list of received card somewhere safe.

Cards are text data, separated by a pipe.

Definition at line 225 of file RplethModule.cpp.

◆ set_dhcp_state()

RplethPacket RplethModule::set_dhcp_state ( const RplethPacket p)
private

Enable or disable DHCP.

Rpleth command

Definition at line 431 of file RplethModule.cpp.

◆ set_reader_gw()

RplethPacket RplethModule::set_reader_gw ( const RplethPacket p)
private

Update the reader gateway.

Definition at line 521 of file RplethModule.cpp.

◆ set_reader_ip()

RplethPacket RplethModule::set_reader_ip ( const RplethPacket p)
private

Update the IP of this Leosac unit.

Definition at line 456 of file RplethModule.cpp.

◆ set_reader_netmask()

RplethPacket RplethModule::set_reader_netmask ( const RplethPacket p)
private

Update netmask of this Leosac unit.

Definition at line 489 of file RplethModule.cpp.

Member Data Documentation

◆ buffer_size

constexpr int Leosac::Module::Rpleth::RplethModule::buffer_size = 8192
staticconstexprprivate

Definition at line 81 of file RplethModule.hpp.

◆ bus_sub_

zmqpp::socket Leosac::Module::Rpleth::RplethModule::bus_sub_
private

Subscribe to the message bus and listen for event sent by the wiegand reader we watch.

Definition at line 214 of file RplethModule.hpp.

◆ cards_pushed_

std::list<std::string> Leosac::Module::Rpleth::RplethModule::cards_pushed_
private

List of cards pushed by SendCards Rpleth command.

Definition at line 187 of file RplethModule.hpp.

◆ cards_read_

std::list<std::string> Leosac::Module::Rpleth::RplethModule::cards_read_
private

Valid cards our Wiegand reader read: cards that were not pushed are not stored here.

Definition at line 193 of file RplethModule.hpp.

◆ cards_read_stream_

std::list<std::pair<std::string, int> > Leosac::Module::Rpleth::RplethModule::cards_read_stream_
private

If stream mode is on, all cards read are stored here.

String data of card and number of bit read.

Definition at line 199 of file RplethModule.hpp.

◆ clients_

std::map<std::string, CircularBuffer> Leosac::Module::Rpleth::RplethModule::clients_
private

Definition at line 201 of file RplethModule.hpp.

◆ core_

zmqpp::socket Leosac::Module::Rpleth::RplethModule::core_
private

REQ socket to core.

Definition at line 219 of file RplethModule.hpp.

◆ ctx_

zmqpp::context& Leosac::Module::Rpleth::RplethModule::ctx_
private

Definition at line 203 of file RplethModule.hpp.

◆ failed_clients_

std::vector<std::string> Leosac::Module::Rpleth::RplethModule::failed_clients_
private

Client that are "failed".

A client is considered fail if a send() to them would have block. It's likely they are disconnected but we dont know it yet. Message from those client are ignored.

Definition at line 232 of file RplethModule.hpp.

◆ reader_

std::unique_ptr<Hardware::FWiegandReader> Leosac::Module::Rpleth::RplethModule::reader_
private

Interface to the reader.

Definition at line 224 of file RplethModule.hpp.

◆ server_

zmqpp::socket Leosac::Module::Rpleth::RplethModule::server_
private

Stream socket to receive Rpleth connection.

Definition at line 208 of file RplethModule.hpp.

◆ stream_mode_

bool Leosac::Module::Rpleth::RplethModule::stream_mode_
private

Definition at line 234 of file RplethModule.hpp.


The documentation for this class was generated from the following files: