28 std::string
const &name,
29 const std::vector<std::string> &auth_contexts,
30 const std::vector<DoormanAction> &actions)
34 , bus_sub_(ctx,
zmqpp::socket_type::sub)
36 bus_sub_.connect(
"inproc://zmq-bus-pub");
37 for (
auto &endpoint : auth_contexts)
46 zmqpp::socket target_socket(ctx, zmqpp::socket_type::req);
47 target_socket.connect(
"inproc://" + action.target_);
48 targets_.insert(std::make_pair(action.target_, std::move(target_socket)));
59 zmqpp::message bus_msg;
60 std::string auth_name;
64 assert(bus_msg.parts() >= 2);
65 bus_msg >> auth_name >> access_status;
66 DEBUG(
"DOORMAN HERE");
72 DEBUG(
"ACTION (target = " << action.target_ <<
")");
75 for (
auto &frame : action.cmd_)
92 msg << static_cast<int64_t>(v);
93 DEBUG(
"would do : " << frame <<
" to target: " << action.target_);
102 zmqpp::socket &target_socket =
targets_.at(target_name);
103 zmqpp::message response;
105 target_socket.send(msg);
106 target_socket.receive(response);
108 std::string req_status;
109 response >> req_status;
111 if (req_status !=
"OK")
113 WARN(
"Command failed :(");
122 if (d->gpio()->name() == name)
131 if (action.
on_ != status)
135 if (target && (target->is_always_closed(std::chrono::system_clock::now()) ||
136 target->is_always_open(std::chrono::system_clock::now())))
138 NOTICE(
"Door " << target->name() <<
" is in immutable state (always open, " 139 "or always closed) so we ignore this " 140 "action against it");
std::shared_ptr< AuthTarget > AuthTargetPtr
bool ignore_action(const DoormanAction &action, Auth::AccessStatus status) const
Should we ignore this action.
void command_send_recv(const std::string &target_name, zmqpp::message msg)
Send a command to a target and wait for response.
std::map< std::string, zmqpp::socket > targets_
Socket (REP) connected to each target this doorman may have.
zmqpp::socket & bus_sub()
Helper struct to wrap an "action".
DoormanInstance(DoormanModule &module, zmqpp::context &ctx, const std::string &name, const std::vector< std::string > &auth_contexts, const std::vector< DoormanAction > &actions)
Create a new doorman.
Auth::AuthTargetPtr find_target(const std::string &name) const
std::vector< DoormanAction > actions_
const std::vector< Auth::AuthTargetPtr > & doors() const
void handle_bus_msg()
Activity we care about happened on the bus.
Leosac::Auth::AccessStatus on_
When should this action be done? on GRANTED or DENIED ?
std::string target_
Target component.
Module that allows user to configure action to be taken to react to messages from other modules...
Main class for the module, it create handlers and run them to, well, handle events and send command...