23 #include <zmqpp/z85.hpp>    27 static std::string z85_pad(
const std::string &in, 
char pad_char)
    31     while (out.size() % 4)
    37                              const boost::property_tree::ptree &cfg,
    40     , bus_(ctx, 
zmqpp::socket_type::sub)
    43     , kernel_(ctx, 
zmqpp::socket_type::req)
    45     kernel_.connect(
"inproc://leosac-kernel");
    47     bus_.connect(
"inproc://zmq-bus-pub");
    58             std::chrono::duration_cast<std::chrono::seconds>(
    70     auto system_bus_logger = spdlog::get(
"system_bus_event");
    71     assert(system_bus_logger);
    74     std::stringstream full_msg;
    78     for (
size_t i = 0; i < msg.parts(); ++i)
    86         if (std::find_if(buf.begin(), buf.end(),
    87                          [](
char c) { 
return !isprint(c); }) != buf.end())
    90             buf = zmqpp::z85::encode(z85_pad(buf, 0));
    91             full_msg << 
"F" << i << 
": {" << buf << 
"} ; ";
    95             full_msg << 
"F" << i << 
": {" << buf << 
"} ; ";
    98     system_bus_logger->info(full_msg.str());
   101         auto monitor_stdout = spdlog::get(
"monitor_stdout");
   102         assert(monitor_stdout);
   103         monitor_stdout->info(full_msg.str());
   129                              << 
" was successful. Looks like network is up.");
   135                              << 
" failed. Network is probably down.");
   145     zmqpp::poller poller;
   151         throw std::runtime_error(
"Internal Error, timeout'd");
   157     std::string system_bus_log_file =
   158         config_.get_child(
"module_config").get<std::string>(
"file-bus", 
"");
   159     if (!system_bus_log_file.empty())
   162         spdlog::rotating_logger_mt(
"system_bus_event", system_bus_log_file,
   165     verbose_ = 
config_.get_child(
"module_config").get<
bool>(
"verbose", 
false);
   168         spdlog::stdout_logger_mt(
"monitor_stdout");
   171     std::string system_led_name =
   172         config_.get_child(
"module_config").get<std::string>(
"system_ok", 
"");
   173     if (!system_led_name.empty())
   176             std::make_unique<Leosac::Hardware::FLED>(
ctx_, system_led_name);
   185     auto ping_node = 
config_.get_child(
"module_config").get_child_optional(
"ping");
   189         std::string network_led_name = ping_node->get<std::string>(
"led");
   191             std::make_unique<Leosac::Hardware::FLED>(
ctx_, network_led_name);
   198         config_.get_child(
"module_config").get_child_optional(
"reader");
   203         std::string reader_led_name = reader_node->get<std::string>(
"led");
   205             std::make_unique<Leosac::Hardware::FLED>(
ctx_, reader_led_name);
 A module that provide visual feedback to the end-user about system's activity. 
 
MonitorModule(zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
 
virtual void run() override
This is the main loop of the module. 
 
UnixShellScript class declaration. 
 
void process_network_config()
Load config related to network monitoring. 
 
std::unique_ptr< Leosac::Hardware::FLED > network_led_
Led for feedback about network availability. 
 
bool is_running_
Boolean indicating whether the main loop should run or not. 
 
std::string req_scripts_dir()
Get scripts directory from kernel. 
 
Base class for module implementation. 
 
std::string reader_to_watch_
 
zmqpp::context & ctx_
A reference to the ZeroMQ context in case you need it to create additional socket. 
 
std::chrono::system_clock::time_point TimePoint
 
void log_system_bus()
Called when a message arrives on the system bus and we are configured to log that. 
 
zmqpp::reactor reactor_
The reactor object we poll() on in the main loop. 
 
std::unique_ptr< Leosac::Hardware::FLED > reader_led_
Led for feedback about reader activity. 
 
std::shared_ptr< CoreUtils > CoreUtilsPtr
 
std::string addr_to_ping_
 
boost::property_tree::ptree config_
The configuration tree passed to the start_module function. 
 
std::unique_ptr< Leosac::Hardware::FLED > system_led_
Led for feedback about system readiness. 
 
void process_reader_config()
Load config related to reader activity monitoring.