31 const boost::property_tree::ptree &cfg,
39 catch (boost::property_tree::ptree_error &e)
41 std::throw_with_nested(
54 boost::property_tree::ptree module_config =
config_.get_child(
"module_config");
56 auto doors_cfg = module_config.get_child_optional(
"doors");
60 for (
const auto &node : module_config.get_child(
"instances"))
63 boost::property_tree::ptree cfg_doorman = node.second;
65 std::vector<std::string> auth_ctx_names;
66 std::vector<DoormanAction> actions;
67 std::string doorman_name = cfg_doorman.get_child(
"name").data();
69 for (
const auto &auth_contexts_node : cfg_doorman.get_child(
"auth_contexts"))
72 auth_ctx_names.push_back(
73 auth_contexts_node.second.get<std::string>(
"name"));
76 for (
const auto &action_node : cfg_doorman.get_child(
"actions"))
79 boost::property_tree::ptree cfg_action = action_node.second;
81 std::string on_status;
83 on_status = cfg_action.get<std::string>(
"on");
84 a.
on_ = (on_status ==
"GRANTED" ? AccessStatus::GRANTED
85 : AccessStatus::DENIED);
86 a.
target_ = cfg_action.get<std::string>(
"target");
89 for (
auto &cmd_node : cfg_action.get_child(
"cmd"))
94 a.
cmd_.push_back(cmd_node.second.data());
99 INFO(
"Creating Doorman instance " << doorman_name);
100 doormen_.push_back(std::make_shared<DoormanInstance>(
101 *
this,
ctx_, doorman_name, auth_ctx_names, actions));
115 const boost::property_tree::ptree &doors_cfg)
117 DEBUG(
"Processing doors config");
118 for (
const auto &door_cfg : doors_cfg)
120 std::string name = door_cfg.second.get<std::string>(
"name");
121 std::string gpio = door_cfg.second.get<std::string>(
"gpio");
122 const auto &open_schedule =
123 door_cfg.second.get_child_optional(
"on.schedules");
124 const auto &close_schedule =
125 door_cfg.second.get_child_optional(
"off.schedules");
134 xml_sched.
load(*open_schedule);
135 for (
const auto &map_entry : xml_sched.
schedules())
137 door->add_always_open_sched(map_entry.second);
143 xml_sched.
load(*close_schedule);
144 for (
const auto &map_entry : xml_sched.
schedules())
146 door->add_always_close_sched(map_entry.second);
155 auto now = std::chrono::system_clock::now();
157 for (
auto &&door :
doors_)
159 if (door->is_always_open(now) && door->is_always_closed(now))
163 <<
" is both always open and always close at the same time.");
166 if (door->is_always_open(now) && !door->gpio()->isOn())
168 door->gpio()->turnOn();
170 if (door->is_always_closed(now) && !door->gpio()->isOff())
172 door->gpio()->turnOff();
std::shared_ptr< AuthTarget > AuthTargetPtr
std::vector< std::shared_ptr< DoormanInstance > > doormen_
Authenticator instances.
Represent an object that we are authorizing against (a door).
A Facade to a GPIO object.
DoormanModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
Helper struct to wrap an "action".
void process_config()
Processing the configuration tree, spawning AuthFileInstance object as described in the configuration...
virtual void run() override
This is the main loop of the module.
bool is_running_
Boolean indicating whether the main loop should run or not.
Holds classes relevant to the Authentication and Authorization subsystem.
void process_doors_config(const boost::property_tree::ptree &t)
void config_check(const std::string &obj_name, ConfigChecker::ObjectType type)
An helper that checks configuration the existence of some objects.
const std::vector< Auth::AuthTargetPtr > & doors() const
Base class for module implementation.
zmqpp::context & ctx_
A reference to the ZeroMQ context in case you need it to create additional socket.
void handle_bus_msg()
Activity we care about happened on the bus.
zmqpp::reactor reactor_
The reactor object we poll() on in the main loop.
Leosac::Auth::AccessStatus on_
When should this action be done? on GRANTED or DENIED ?
std::shared_ptr< CoreUtils > CoreUtilsPtr
boost::property_tree::ptree config_
The configuration tree passed to the start_module function.
std::vector< std::string > cmd_
The command to be send.
std::vector< Auth::AuthTargetPtr > doors_
Doors, to manage the always-on or always off stuff.
std::string target_
Target component.
Module that allows user to configure action to be taken to react to messages from other modules...