31 const boost::property_tree::ptree &cfg,
39 catch (boost::property_tree::ptree_error &e)
41 std::throw_with_nested(
50 for (
auto &&door : doorman->doors())
60 boost::property_tree::ptree module_config =
config_.get_child(
"module_config");
62 auto doors_cfg = module_config.get_child_optional(
"doors");
66 for (
const auto &node : module_config.get_child(
"instances"))
69 boost::property_tree::ptree cfg_doorman = node.second;
71 std::vector<std::string> auth_ctx_names;
72 std::vector<DoormanAction> actions;
73 std::string doorman_name = cfg_doorman.get_child(
"name").data();
75 for (
const auto &auth_contexts_node : cfg_doorman.get_child(
"auth_contexts"))
78 auth_ctx_names.push_back(
79 auth_contexts_node.second.get<std::string>(
"name"));
82 for (
const auto &action_node : cfg_doorman.get_child(
"actions"))
85 boost::property_tree::ptree cfg_action = action_node.second;
87 std::string on_status;
89 on_status = cfg_action.get<std::string>(
"on");
90 a.
on_ = (on_status ==
"GRANTED" ? AccessStatus::GRANTED
91 : AccessStatus::DENIED);
92 a.
target_ = cfg_action.get<std::string>(
"target");
95 for (
auto &cmd_node : cfg_action.get_child(
"cmd"))
100 a.
cmd_.push_back(cmd_node.second.data());
102 actions.push_back(a);
105 INFO(
"Creating Doorman instance " << doorman_name);
106 doormen_.push_back(std::make_shared<DoormanInstance>(
107 *
this,
ctx_, doorman_name, auth_ctx_names, actions));
121 const boost::property_tree::ptree &doors_cfg)
123 DEBUG(
"Processing doors config");
124 for (
const auto &door_cfg : doors_cfg)
126 std::string name = door_cfg.second.get<std::string>(
"name");
127 std::string gpio = door_cfg.second.get<std::string>(
"gpio");
128 const auto &open_schedule =
129 door_cfg.second.get_child_optional(
"on.schedules");
130 const auto &close_schedule =
131 door_cfg.second.get_child_optional(
"off.schedules");
140 xml_sched.
load(*open_schedule);
141 for (
const auto &map_entry : xml_sched.
schedules())
143 door->add_always_open_sched(map_entry.second);
149 xml_sched.
load(*close_schedule);
150 for (
const auto &map_entry : xml_sched.
schedules())
152 door->add_always_close_sched(map_entry.second);
156 const auto &exitreq =
157 door_cfg.second.get_child_optional(
"exitreq");
160 std::string exitreq_gpio = exitreq.get().get<std::string>(
"gpio");
163 door->exitreq_duration(std::chrono::milliseconds(exitreq.get().get<uint16_t>(
"duration")));
166 const auto &contact =
167 door_cfg.second.get_child_optional(
"contact");
170 std::string contact_gpio = contact.get().get<std::string>(
"gpio");
173 door->contact_duration(std::chrono::milliseconds(contact.get().get<uint16_t>(
"duration")));
181 auto now = std::chrono::system_clock::now();
183 for (
auto &&door :
doors_)
185 door->resetToExpectedState(now);