Leosac  0.7.0
OpenSourceAccessControl
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 }
NotifierInstance & operator=(const NotifierInstance &)=delete
This is the header file for a generated source file, GitSHA1.cpp.
TargetInfo * find_target(const std::string &routing_id)
Attempt to find a target from its routing_id.
Some information for each tcp server target.
bool act_as_server_
Are we a server or a client ?
void handle_credential(Cred::RFIDCard &card)
Notify the peers of the card credential.
void handle_tcp_msg()
Some event on our ZMQ Stream socket.
std::unique_ptr< ProtocolHandler > ProtocolHandlerUPtr
std::unique_ptr< NotifierInstance > NotifierInstanceUPtr
zmqpp::socket bus_sub_
Read internal message bus.
This is an instance of the Notifier.
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.
TargetInfo & operator=(const TargetInfo &o)=default
void configure_tcp_socket(const std::vector< std::string > &endpoints)
zmqpp::socket tcp_
Stream socket used to connect to remote client we want to notify.
An RFID card credential.
Definition: RFIDCard.hpp:33