22 #include "hardware/Buzzer_odb.h" 24 #include "hardware/LED_odb.h" 27 #include "ws/WSHelperThread.hpp" 28 #include <boost/iterator/transform_iterator.hpp> 38 boost::property_tree::ptree
const &cfg,
56 if (
config_.get_child(
"module_config").get<
bool>(
"use_database",
false))
63 auto itr_transform = [](
const std::shared_ptr<LedBuzzerImpl> &lb) {
64 return lb->next_update();
71 if (led->next_update() <= std::chrono::system_clock::now())
82 boost::property_tree::ptree module_config =
config_.get_child(
"module_config");
84 if (module_config.get<
bool>(
"use_database",
false))
96 boost::property_tree::ptree module_config =
config_.get_child(
"module_config");
98 if (
const auto &leds_node = module_config.get_child_optional(
"leds"))
100 for (
auto &node : *leds_node)
102 boost::property_tree::ptree led_cfg = node.second;
104 std::string led_name = led_cfg.get<std::string>(
"name");
105 std::string gpio_name = led_cfg.get<std::string>(
"gpio");
106 int default_blink_duration =
107 led_cfg.get<
int>(
"default_blink_duration", 1000);
108 int default_blink_speed = led_cfg.get<
int>(
"default_blink_speed", 200);
110 INFO(
"Creating LED " << led_name <<
", linked to GPIO " << gpio_name);
114 ctx_, led_name, gpio_name, default_blink_duration,
115 default_blink_speed));
116 utils_->config_checker().register_object(led_name,
121 if (
const auto &buzzers_node = module_config.get_child_optional(
"buzzers"))
123 for (
auto &node : *buzzers_node)
125 boost::property_tree::ptree buzzer_cfg = node.second;
127 std::string buzzer_name = buzzer_cfg.get<std::string>(
"name");
128 std::string gpio_name = buzzer_cfg.get<std::string>(
"gpio");
129 int default_blink_duration =
130 buzzer_cfg.get<
int>(
"default_blink_duration", 1000);
131 int default_blink_speed =
132 buzzer_cfg.get<
int>(
"default_blink_speed", 200);
134 INFO(
"Creating Buzzer " << buzzer_name <<
", linked to GPIO " 140 ctx_, buzzer_name, gpio_name, default_blink_duration,
141 default_blink_speed));
142 utils_->config_checker().register_object(
151 using namespace odb::core;
152 auto db =
utils_->database();
156 odb::transaction t(
utils_->database()->begin());
157 odb::result<Hardware::LED> result(
159 for (
const auto &led : result)
165 WARN(
"No GPIO associated with device " << led.name()
170 ctx_, led.name(), led.gpio()->name(), led.default_blink_duration(),
171 led.default_blink_speed()));
172 utils_->config_checker().register_object(led.name(),
180 odb::transaction t(
utils_->database()->begin());
181 odb::result<Hardware::Buzzer> result(
183 for (
const auto &buzzer : result)
185 if (!buzzer.enabled())
189 WARN(
"No GPIO associated with device " << buzzer.name()
194 ctx_, buzzer.name(), buzzer.gpio()->name(),
195 buzzer.default_blink_duration(), buzzer.default_blink_speed()));
196 utils_->config_checker().register_object(
202 INFO(
"LEDBuzzer module using SQL database for configuration.");
std::unique_ptr< WSHelperThread > ws_helper_thread_
A service object provided by the Websocket module.
This is the header file for a generated source file, GitSHA1.cpp.
ServiceRegistry & get_service_registry()
A function to retrieve the ServiceRegistry from pretty much anywhere.
CoreUtilsPtr utils_
Pointer to the core utils, which gives access to scheduler and others.
bool is_running_
Boolean indicating whether the main loop should run or not.
virtual ~LEDBuzzerModule()
void config_check(const std::string &obj_name, ConfigChecker::ObjectType type)
An helper that checks configuration the existence of some objects.
void run() override
This is the main loop of the module.
Base class for module implementation.
zmqpp::context & ctx_
A reference to the ZeroMQ context in case you need it to create additional socket.
Provide ODB magic to be able to store an Leosac::Audit::EventType (FlagSet) object.
std::vector< std::shared_ptr< LedBuzzerImpl > > leds_and_buzzers_
zmqpp::reactor reactor_
The reactor object we poll() on in the main loop.
std::shared_ptr< ServiceInterface > get_service() const
Retrieve the service instance implementing the ServiceInterface, or nullptr if no such service was re...
std::shared_ptr< CoreUtils > CoreUtilsPtr
LEDBuzzerModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
boost::property_tree::ptree config_
The configuration tree passed to the start_module function.
Abstraction of LED device attributes.
Abstraction of Buzzer device attributes.
void handle_message()
Message received on the rep_ socket.