28 std::string
const &name,
29 const std::vector<std::string> &auth_contexts,
30 const std::vector<DoormanAction> &actions)
33 , bus_sub_(ctx,
zmqpp::socket_type::sub)
35 bus_sub_.connect(
"inproc://zmq-bus-pub");
36 for (
auto &endpoint : auth_contexts)
47 zmqpp::socket target_socket(ctx, zmqpp::socket_type::req);
48 target_socket.connect(
"inproc://" + action.target_);
49 targets_.insert(std::make_pair(action.target_, std::move(target_socket)));
52 for (
auto &door : module.
doors())
54 doors_.push_back(std::make_shared<DoormanDoor>(door, ctx));
65 zmqpp::message bus_msg;
66 std::string auth_name;
70 assert(bus_msg.parts() >= 2);
71 bus_msg >> auth_name >> access_status;
72 DEBUG(
"DOORMAN HERE");
78 DEBUG(
"ACTION (target = " << action.target_ <<
")");
81 for (
auto &frame : action.cmd_)
98 msg << static_cast<int64_t>(v);
99 DEBUG(
"would do : " << frame <<
" to target: " << action.target_);
108 zmqpp::socket &target_socket =
targets_.at(target_name);
109 zmqpp::message response;
111 target_socket.send(msg);
112 target_socket.receive(response);
114 std::string req_status;
115 response >> req_status;
117 if (req_status !=
"OK")
119 WARN(
"Command failed :(");
126 for (
const auto &d :
doors())
128 if (d->door()->gpio()->name() == name)
137 if (action.
on_ != status)
141 if (target && (target->is_always_closed(std::chrono::system_clock::now()) ||
142 target->is_always_open(std::chrono::system_clock::now())))
144 INFO(
"Door " << target->name() <<
" is in immutable state (always open, "
145 "or always closed) so we ignore this "
146 "action against it");