Leosac  0.8.0
Open Source Access Control
NotifierInstance.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 
22 #include "LeosacFwd.hpp"
23 #include "ProtocolHandler.hpp"
24 #include "core/auth/AuthFwd.hpp"
26 #include <zmqpp/reactor.hpp>
27 #include <zmqpp/socket.hpp>
28 
29 namespace Leosac
30 {
31 namespace Module
32 {
33 namespace TCPNotifier
34 {
35 class NotifierInstance;
36 using NotifierInstanceUPtr = std::unique_ptr<NotifierInstance>;
37 
59 {
60  public:
77  NotifierInstance(zmqpp::context &ctx, zmqpp::reactor &reactor,
78  std::vector<std::string> auth_sources,
79  std::vector<std::string> connect_to,
80  std::vector<std::string> bind_to,
81  ProtocolHandlerUPtr protocol_handler);
82 
83  ~NotifierInstance() = default;
84 
85  NotifierInstance(const NotifierInstance &) = delete;
86  NotifierInstance &operator=(const NotifierInstance &) = delete;
87  NotifierInstance(NotifierInstance &&o) = delete;
89 
90  private:
95 
96  void handle_one(zmqpp::message &msg);
97 
98  void handle_msg_bus();
99 
103  void handle_tcp_msg();
104 
105  void configure_tcp_socket(const std::vector<std::string> &endpoints);
106 
110  struct TargetInfo
111  {
113  : status_(false)
114  {
115  }
116  TargetInfo(const TargetInfo &) = default;
117  TargetInfo(TargetInfo &&o) = default;
118  TargetInfo &operator=(const TargetInfo &o) = default;
119  TargetInfo &operator=(TargetInfo &&o) = default;
120 
121  // Url is IP:PORT
122  // Maybe be empty is peer is connecting to us.
123  std::string url_;
124 
125  // The ZMQ routing-id for this target.
126  std::string zmq_identity_;
127 
128  // ZMQ provide auto reconnection
129  // This tracks the status.
130  bool status_;
131  };
132 
136  zmqpp::socket bus_sub_;
137 
142  zmqpp::socket tcp_;
143 
144  std::list<TargetInfo> targets_;
145 
147 
152 
158  TargetInfo *find_target(const std::string &routing_id);
159 };
160 }
161 }
162 }
Leosac::Module::TCPNotifier::NotifierInstance::act_as_server_
bool act_as_server_
Are we a server or a client ?
Definition: NotifierInstance.hpp:151
Leosac::Module::TCPNotifier::NotifierInstance::handle_one
void handle_one(zmqpp::message &msg)
Definition: NotifierInstance.cpp:86
Leosac::Module::TCPNotifier::NotifierInstance::TargetInfo::zmq_identity_
std::string zmq_identity_
Definition: NotifierInstance.hpp:126
Leosac::Module::TCPNotifier::NotifierInstance::TargetInfo::operator=
TargetInfo & operator=(const TargetInfo &o)=default
Leosac::Module::TCPNotifier::NotifierInstance::TargetInfo::TargetInfo
TargetInfo()
Definition: NotifierInstance.hpp:112
AuthFwd.hpp
LeosacFwd.hpp
Leosac::Module::TCPNotifier::NotifierInstance::handle_msg_bus
void handle_msg_bus()
Definition: NotifierInstance.cpp:155
Leosac::Module::TCPNotifier::NotifierInstance::operator=
NotifierInstance & operator=(const NotifierInstance &)=delete
Leosac::Module::TCPNotifier::NotifierInstance::configure_tcp_socket
void configure_tcp_socket(const std::vector< std::string > &endpoints)
Definition: NotifierInstance.cpp:182
Leosac::Cred::RFIDCard
An RFID card credential.
Definition: RFIDCard.hpp:33
ProtocolHandler.hpp
Leosac::Module::TCPNotifier::ProtocolHandlerUPtr
std::unique_ptr< ProtocolHandler > ProtocolHandlerUPtr
Definition: ProtocolHandler.hpp:38
Leosac::Module::TCPNotifier::NotifierInstance::protocol_
ProtocolHandlerUPtr protocol_
Definition: NotifierInstance.hpp:146
Leosac::Module::TCPNotifier::NotifierInstanceUPtr
std::unique_ptr< NotifierInstance > NotifierInstanceUPtr
Definition: NotifierInstance.hpp:36
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::TCPNotifier::NotifierInstance::handle_tcp_msg
void handle_tcp_msg()
Some event on our ZMQ Stream socket.
Definition: NotifierInstance.cpp:133
Leosac::Module::TCPNotifier::NotifierInstance::TargetInfo::url_
std::string url_
Definition: NotifierInstance.hpp:123
Leosac::Module::TCPNotifier::NotifierInstance::tcp_
zmqpp::socket tcp_
Stream socket used to connect to remote client we want to notify.
Definition: NotifierInstance.hpp:142
Leosac::Module::TCPNotifier::NotifierInstance::~NotifierInstance
~NotifierInstance()=default
Leosac::Module::TCPNotifier::NotifierInstance::TargetInfo::status_
bool status_
Definition: NotifierInstance.hpp:130
Leosac::Module::TCPNotifier::NotifierInstance::find_target
TargetInfo * find_target(const std::string &routing_id)
Attempt to find a target from its routing_id.
Definition: NotifierInstance.cpp:144
CredentialFwd.hpp
Leosac::Module::TCPNotifier::NotifierInstance::handle_credential
void handle_credential(Cred::RFIDCard &card)
Notify the peers of the card credential.
Definition: NotifierInstance.cpp:58
Leosac::Module::TCPNotifier::NotifierInstance::targets_
std::list< TargetInfo > targets_
Definition: NotifierInstance.hpp:144
Leosac::Module::TCPNotifier::NotifierInstance::NotifierInstance
NotifierInstance(zmqpp::context &ctx, zmqpp::reactor &reactor, std::vector< std::string > auth_sources, std::vector< std::string > connect_to, std::vector< std::string > bind_to, ProtocolHandlerUPtr protocol_handler)
Create a new notifier instance.
Definition: NotifierInstance.cpp:31
Leosac::Module::TCPNotifier::NotifierInstance::bus_sub_
zmqpp::socket bus_sub_
Read internal message bus.
Definition: NotifierInstance.hpp:136
Leosac::Module::TCPNotifier::NotifierInstance
This is an instance of the Notifier.
Definition: NotifierInstance.hpp:58
Leosac::Module::TCPNotifier::NotifierInstance::TargetInfo
Some information for each tcp server target.
Definition: NotifierInstance.hpp:110