Leosac  0.8.0
Open Source Access Control
PFDigitalModule.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "PFDigitalPin.hpp"
23 #include "modules/BaseModule.hpp"
25 #include <boost/asio/io_service.hpp>
26 #include <boost/property_tree/ptree.hpp>
28 #include <zmqpp/reactor.hpp>
29 #include <zmqpp/socket.hpp>
30 
31 namespace Leosac
32 {
33 namespace Module
34 {
47 namespace Piface
48 {
49 
50 class PFDigitalModule;
56 {
58 };
59 
60 class WSHelperThread : public WebSockAPI::BaseModuleSupportThread<ModuleParameters>
61 {
62  public:
63  explicit WSHelperThread(const CoreUtilsPtr &core_utils)
64  : BaseModuleSupportThread(core_utils, {})
65  {
66  }
67 
71  void test_output_pin(const UUID &gpio_id);
72 
73  void unregister_ws_handlers(WebSockAPI::Service &ws_service) override;
74 
75  private:
76  void register_ws_handlers(WebSockAPI::Service &ws_service) override;
77 };
78 
83 {
84  public:
85  PFDigitalModule(zmqpp::context &ctx, zmqpp::socket *module_manager_pipe,
86  const boost::property_tree::ptree &config, CoreUtilsPtr utils);
87 
88 
90 
94  virtual void run() override;
95 
96  private:
100  void handle_interrupt();
101 
105  void process_xml_config(const boost::property_tree::ptree &cfg);
106 
110  void process_config();
111 
115  void setup_database();
116 
118 
122  zmqpp::socket bus_push_;
123 
127  std::vector<PFDigitalPin> gpios_;
128 
136  bool get_input_pin_name(std::string &dest, int idx, uint8_t hw_addr);
137 
143 
148 
154 };
155 }
156 }
157 }
Leosac::Module::BaseModule
Base class for module implementation.
Definition: BaseModule.hpp:110
Leosac::Module::Piface::PFDigitalModule::get_input_pin_name
bool get_input_pin_name(std::string &dest, int idx, uint8_t hw_addr)
Retrieve the (user-given) name of the pin and store it in dest.
Definition: PFDigitalModule.cpp:168
Leosac::Module::Piface::PFDigitalModule::bus_push_
zmqpp::socket bus_push_
Socket to push event to the bus.
Definition: PFDigitalModule.hpp:122
Leosac::Module::Piface::PFDigitalModule::PFDigitalModule
PFDigitalModule(zmqpp::context &ctx, zmqpp::socket *module_manager_pipe, const boost::property_tree::ptree &config, CoreUtilsPtr utils)
Definition: PFDigitalModule.cpp:54
ServiceRegistry.hpp
WSHelperThread.hpp
BaseModule.hpp
Leosac::Module::Piface::WSHelperThread::unregister_ws_handlers
void unregister_ws_handlers(WebSockAPI::Service &ws_service) override
Definition: PFDigitalModule.cpp:376
Leosac::Module::WebSockAPI::BaseModuleSupportThread
This class provide a base implementation -designed to be extended by subclass- so that non-boost-asio...
Definition: WSHelperThread.hpp:61
Leosac::Module::WebSockAPI::BaseModuleSupportThread< ModuleParameters >::BaseModuleSupportThread
BaseModuleSupportThread(const CoreUtilsPtr &core_utils, const ModuleParameters &param)
Definition: WSHelperThread.hpp:64
Leosac::Module::Piface::PFDigitalModule
Main class for the piface digital module.
Definition: PFDigitalModule.hpp:82
Leosac::Module::Piface::PFDigitalModule::load_config_from_database
void load_config_from_database()
Definition: PFDigitalModule.cpp:270
Leosac::Module::Piface::PFDigitalModule::process_xml_config
void process_xml_config(const boost::property_tree::ptree &cfg)
Process the XML configuration, preparing configured GPIO pin.
Definition: PFDigitalModule.cpp:182
Leosac::Module::Piface::WSHelperThread::test_output_pin
void test_output_pin(const UUID &gpio_id)
Implements the "pfdigital.test_output_pin" API call.
Definition: PFDigitalModule.cpp:309
Leosac::Module::Piface::PFDigitalModule::setup_database
void setup_database()
Create / update database schema for the module.
Definition: PFDigitalModule.cpp:246
Leosac::Module::Piface::WSHelperThread::register_ws_handlers
void register_ws_handlers(WebSockAPI::Service &ws_service) override
Called when websocket handler registration is possible.
Definition: PFDigitalModule.cpp:353
Leosac::Module::Piface::WSHelperThread::WSHelperThread
WSHelperThread(const CoreUtilsPtr &core_utils)
Definition: PFDigitalModule.hpp:63
PFDigitalPin.hpp
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Module::Piface::PFDigitalModule::run
virtual void run() override
Module's main loop.
Definition: PFDigitalModule.cpp:111
Leosac::Module::WebSockAPI::Service
A service object provided by the Websocket module.
Definition: Service.hpp:45
Leosac::Module::Piface::PFDigitalModule::gpios_
std::vector< PFDigitalPin > gpios_
GPIO vector.
Definition: PFDigitalModule.hpp:127
Leosac::Module::Piface::PFDigitalModule::~PFDigitalModule
~PFDigitalModule()
Definition: PFDigitalModule.cpp:103
Leosac::Module::Piface::PFDigitalModule::degraded_mode_
bool degraded_mode_
True if we are running in "degraded" mode (ie, not on a device that support the PifaceDigital).
Definition: PFDigitalModule.hpp:153
Leosac::Module::Piface::PFDigitalModule::handle_interrupt
void handle_interrupt()
An interrupt was triggered.
Definition: PFDigitalModule.cpp:136
Leosac::Module::Piface::PFDigitalModule::process_config
void process_config()
Process configuration.
Definition: PFDigitalModule.cpp:213
Leosac::Module::Piface::PFDigitalModule::interrupt_fd_
int interrupt_fd_
File descriptor of the PIN that triggers interrupts.
Definition: PFDigitalModule.hpp:142
Leosac::Module::Piface::PFDigitalModule::ws_helper_thread_
WSHelperThread ws_helper_thread_
Support thread for processing websocket requests.
Definition: PFDigitalModule.hpp:147
Leosac::Module::Piface::WSHelperThread
Definition: PFDigitalModule.hpp:60
Leosac::CoreUtilsPtr
std::shared_ptr< CoreUtils > CoreUtilsPtr
Definition: LeosacFwd.hpp:35
Leosac::Module::Piface::ModuleParameters::degraded_mode
bool degraded_mode
Definition: PFDigitalModule.hpp:57
Leosac::UUID
Thin wrapper around boost::uuids::uuid.
Definition: Uuid.hpp:35
Leosac::Module::Piface::ModuleParameters
Some ~const parameter that are required to process websocket requests.
Definition: PFDigitalModule.hpp:55