refactored utility namespace

This commit is contained in:
Jonas Zeunert
2018-10-17 22:00:56 +02:00
parent 8708663cd6
commit c5867acd52
15 changed files with 154 additions and 61 deletions

View File

@@ -10,6 +10,9 @@
#include "ICabinetItem.h" #include "ICabinetItem.h"
#include "utilities/IOutputGPIOInterface.h"
#include <memory>
#include <string> #include <string>
namespace FlippR_Driver namespace FlippR_Driver
@@ -20,8 +23,9 @@ namespace output
class CabinetItem : public ICabinetItem class CabinetItem : public ICabinetItem
{ {
public: public:
CabinetItem(); CabinetItem(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
virtual ~CabinetItem(); virtual ~CabinetItem();
virtual bool isActivated(); virtual bool isActivated();
virtual bool activate(); virtual bool activate();
virtual bool deactivate(); virtual bool deactivate();

View File

@@ -9,15 +9,16 @@
namespace FlippR_Driver namespace FlippR_Driver
{ {
namespace output { namespace output
{
Sound::Sound() { Sound::Sound(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, int address, std::string name)
// TODO Auto-generated constructor stub : output_gpio_interface(output_gpio_interface), address(address), name(name)
{}
} void Sound::play()
{
Sound::~Sound() { this->output_gpio_interface->activate(this);
// TODO Auto-generated destructor stub
} }
} /* namespace output */ } /* namespace output */

View File

@@ -10,8 +10,11 @@
#include "ISound.h" #include "ISound.h"
#include <memory>
#include <string> #include <string>
#include "utilities/IOutputGPIOInterface.h"
namespace FlippR_Driver namespace FlippR_Driver
{ {
namespace output namespace output
@@ -20,12 +23,14 @@ namespace output
class Sound : ISound class Sound : ISound
{ {
public: public:
Sound(); Sound(std::shared_ptr<IOutputGPIOInterface> output_gpio_interface, int address, std::string name);
virtual ~Sound(); virtual ~Sound() = default;
virtual void play(); virtual void play();
private: private:
std::shared_ptr<IOutputGPIOInterface> output_gpio_interface;
int address; int address;
std::string name; std::string name;
}; };

View File

@@ -16,6 +16,11 @@
using namespace boost; using namespace boost;
namespace FlippR_Driver
{
namespace utility
{
template<typename T> template<typename T>
class BlockingQueue : public IBlockingQueue<T> class BlockingQueue : public IBlockingQueue<T>
{ {
@@ -37,12 +42,15 @@ public:
T pop() T pop()
{ {
std::unique_lock<std::mutex> lock(this->d_mutex); std::unique_lock<std::mutex> lock(this->d_mutex);
this->d_condition.wait(lock, [=]{ return !this->p_queue.empty(); }); this->d_condition.wait(lock, [=]
{ return !this->p_queue.empty(); });
T rc = *this->p_queue.begin(); T rc = *this->p_queue.begin();
this->p_queue.pop(); this->p_queue.pop();
return rc; return rc;
} }
}; };
}
}

View File

@@ -12,6 +12,11 @@
#include "wiringPi/wiringPi.h" #include "wiringPi/wiringPi.h"
#include "json/json.hpp" #include "json/json.hpp"
namespace FlippR_Driver
{
namespace utility
{
std::once_flag GPIOInterface::GPIO_LIB_INITIALIZED; std::once_flag GPIOInterface::GPIO_LIB_INITIALIZED;
void GPIOInterface::initialize_input_pin(char address) void GPIOInterface::initialize_input_pin(char address)
@@ -24,7 +29,6 @@ void GPIOInterface::write_pin(char address, char data)
digitalWrite(address, data); digitalWrite(address, data);
} }
bool GPIOInterface::read_pin(char address) bool GPIOInterface::read_pin(char address)
{ {
return PULLDOWN == digitalRead(address); return PULLDOWN == digitalRead(address);
@@ -39,3 +43,5 @@ GPIOInterface::GPIOInterface()
{ {
std::call_once(GPIO_LIB_INITIALIZED, wiringPiSetup); std::call_once(GPIO_LIB_INITIALIZED, wiringPiSetup);
} }
}
}

View File

@@ -15,13 +15,18 @@
#include <mutex> #include <mutex>
#include <fstream> #include <fstream>
namespace FlippR_Driver
{
namespace utility
{
class GPIOInterface class GPIOInterface
{ {
public: public:
GPIOInterface(); GPIOInterface();
virtual ~GPIOInterface() {}; virtual ~GPIOInterface()
{};
static void initialize_input_pin(char address); static void initialize_input_pin(char address);
@@ -35,7 +40,8 @@ public:
static std::once_flag GPIO_LIB_INITIALIZED; static std::once_flag GPIO_LIB_INITIALIZED;
}; };
}
}
#endif #endif

View File

@@ -8,15 +8,23 @@
#ifndef SRC_UTILITIES_IBLOCKINGQUEUE_H_ #ifndef SRC_UTILITIES_IBLOCKINGQUEUE_H_
#define SRC_UTILITIES_IBLOCKINGQUEUE_H_ #define SRC_UTILITIES_IBLOCKINGQUEUE_H_
namespace FlippR_Driver
{
namespace utility
{
template<typename T> template<typename T>
class IBlockingQueue class IBlockingQueue
{ {
public: public:
virtual ~IBlockingQueue(){}; virtual ~IBlockingQueue()
{};
virtual void push(T const &value) = 0; virtual void push(T const &value) = 0;
virtual T pop() = 0; virtual T pop() = 0;
}; };
}
}
#endif #endif

View File

@@ -8,13 +8,21 @@
#ifndef SRC_UTILITIES_IINPUTGPIOINTERFACE_H_ #ifndef SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
#define SRC_UTILITIES_IINPUTGPIOINTERFACE_H_ #define SRC_UTILITIES_IINPUTGPIOINTERFACE_H_
namespace FlippR_Driver
{
namespace utility
{
class IInputGPIOInterface class IInputGPIOInterface
{ {
public: public:
virtual ~IInputGPIOInterface(){}; virtual ~IInputGPIOInterface()
{};
virtual bool read_data(char pin) = 0; virtual bool read_data(char pin) = 0;
}; };
}
}
#endif #endif

View File

@@ -5,8 +5,16 @@
#ifndef FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H #ifndef FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H
#define FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H #define FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H
namespace FlippR_Driver
{
namespace utility
{
class IOutputGPIOInterface class IOutputGPIOInterface
{ {
}; };
}
}
#endif //FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H #endif //FLIPPR_DRIVER_IOUTPUTGPIOINTERFACE_H

View File

@@ -13,6 +13,11 @@
#include "easylogging/easylogging++.h" #include "easylogging/easylogging++.h"
#include "config.h" #include "config.h"
#include <string> #include <string>
namespace FlippR_Driver
{
namespace utility
{
using namespace nlohmann; using namespace nlohmann;
bool InputGPIOInterface::read_data(char pin) bool InputGPIOInterface::read_data(char pin)
@@ -41,7 +46,6 @@ void InputGPIOInterface::write_col(char data)
write_pin(this->col_address_C, data & 0b100); write_pin(this->col_address_C, data & 0b100);
} }
InputGPIOInterface::InputGPIOInterface(std::istream &input_config_stream) InputGPIOInterface::InputGPIOInterface(std::istream &input_config_stream)
{ {
init_members(input_config_stream); init_members(input_config_stream);
@@ -54,7 +58,8 @@ void InputGPIOInterface::init_members(std::istream &input_config_stream)
json input_config; json input_config;
input_config_stream >> input_config; input_config_stream >> input_config;
try { try
{
json row_json = input_config.at("row"); json row_json = input_config.at("row");
row_address_A = row_json.at("A").get<json::number_integer_t>(); row_address_A = row_json.at("A").get<json::number_integer_t>();
row_address_B = row_json.at("B").get<json::number_integer_t>(); row_address_B = row_json.at("B").get<json::number_integer_t>();
@@ -66,9 +71,13 @@ void InputGPIOInterface::init_members(std::istream &input_config_stream)
col_address_C = col_json.at("C").get<json::number_integer_t>(); col_address_C = col_json.at("C").get<json::number_integer_t>();
data_address = input_config.at("data").get<json::number_integer_t>(); data_address = input_config.at("data").get<json::number_integer_t>();
} catch (json::type_error& e) { }
catch(json::type_error &e)
{
CLOG(ERROR, INPUT_LOGGER) << e.what(); CLOG(ERROR, INPUT_LOGGER) << e.what();
} catch (json::out_of_range& e) { }
catch(json::out_of_range &e)
{
CLOG(ERROR, INPUT_LOGGER) << e.what(); CLOG(ERROR, INPUT_LOGGER) << e.what();
} }
} }
@@ -85,3 +94,6 @@ void InputGPIOInterface::init_pins()
initialize_input_pin(data_address); initialize_input_pin(data_address);
} }
}
}

View File

@@ -12,6 +12,11 @@
#include "IInputGPIOInterface.h" #include "IInputGPIOInterface.h"
#include "GPIOInterface.h" #include "GPIOInterface.h"
namespace FlippR_Driver
{
namespace utility
{
class InputGPIOInterface : public IInputGPIOInterface, GPIOInterface class InputGPIOInterface : public IInputGPIOInterface, GPIOInterface
{ {
public: public:
@@ -34,4 +39,6 @@ private:
char data_address; char data_address;
}; };
}
}
#endif #endif

View File

@@ -10,6 +10,11 @@
#define EASYLOGGING_IS_INITIALIZED #define EASYLOGGING_IS_INITIALIZED
INITIALIZE_EASYLOGGINGPP INITIALIZE_EASYLOGGINGPP
#endif #endif
namespace FlippR_Driver
{
namespace utility
{
namespace LoggerFactory namespace LoggerFactory
{ {
@@ -60,3 +65,6 @@ void CreateOutputLogger(el::Level level)
} }
}; };
}
}

View File

@@ -10,6 +10,11 @@
#include "config.h" #include "config.h"
namespace FlippR_Driver
{
namespace utility
{
namespace LoggerFactory namespace LoggerFactory
{ {
void CreateInputTestLogger(el::Level level = el::Level::Global); void CreateInputTestLogger(el::Level level = el::Level::Global);
@@ -19,4 +24,6 @@ namespace LoggerFactory
void CreateOutputLogger(el::Level level = el::Level::Info); void CreateOutputLogger(el::Level level = el::Level::Info);
}; };
}
}
#endif #endif

View File

@@ -11,6 +11,10 @@
#include "GPIOInterface.h" #include "GPIOInterface.h"
#include <mcp23017.h> #include <mcp23017.h>
namespace FlippR_Driver
{
namespace utility
{
class OutputGPIOInterface : GPIOInterface class OutputGPIOInterface : GPIOInterface
{ {
@@ -24,6 +28,7 @@ private:
IBlockingQueue <CabinetItem> event_queue; IBlockingQueue <CabinetItem> event_queue;
}; };
}
}
#endif #endif