From 9272666ffe705899c1d5ab857fb330f7feb4a63e Mon Sep 17 00:00:00 2001 From: PixlOne <8843371+PixlOne@users.noreply.github.com> Date: Fri, 4 Oct 2019 21:56:17 -0400 Subject: [PATCH] Use logid namespace --- src/logid/Actions.cpp | 2 + src/logid/Actions.h | 261 ++++++++++++++++++----------------- src/logid/Configuration.cpp | 3 +- src/logid/Configuration.h | 63 +++++---- src/logid/Device.cpp | 2 + src/logid/Device.h | 266 ++++++++++++++++++------------------ src/logid/DeviceFinder.cpp | 2 + src/logid/DeviceFinder.h | 54 ++++---- src/logid/EvdevDevice.cpp | 2 + src/logid/EvdevDevice.h | 33 +++-- src/logid/logid.cpp | 10 +- src/logid/util.cpp | 16 ++- src/logid/util.h | 37 ++--- 13 files changed, 394 insertions(+), 357 deletions(-) diff --git a/src/logid/Actions.cpp b/src/logid/Actions.cpp index 3ecff7a..c4f61d4 100644 --- a/src/logid/Actions.cpp +++ b/src/logid/Actions.cpp @@ -11,6 +11,8 @@ #include "util.h" #include "EvdevDevice.h" +using namespace logid; + NoAction* NoAction::copy(Device *dev) { auto action = new NoAction(); diff --git a/src/logid/Actions.h b/src/logid/Actions.h index b5927ea..65e0b14 100644 --- a/src/logid/Actions.h +++ b/src/logid/Actions.h @@ -1,141 +1,144 @@ -#ifndef ACTIONS_H -#define ACTIONS_H +#ifndef LOGID_ACTIONS_H +#define LOGID_ACTIONS_H #include "Device.h" #include #include #include -enum class Action +namespace logid { - None, - Keypress, - Gestures, - CycleDPI, - ChangeDPI, - ToggleSmartshift, - ToggleHiresScroll -}; -enum class Direction -{ - None, - Up, - Down, - Left, - Right -}; -enum class GestureMode -{ - NoPress, - OnRelease, - OnFewPixels, - Axis -}; - -class Device; - -class ButtonAction -{ -public: - virtual ~ButtonAction() = default; - - Action type; - virtual ButtonAction* copy(Device* dev) = 0; - virtual void press() = 0; - virtual void release() = 0; -// ButtonAction(const ButtonAction &a, Device* d) : type (a.type), device (d) {} -// ButtonAction* create_instance(Device* d); -protected: - ButtonAction(Action a) : type (a) {}; - Device* device; -}; -class NoAction : public ButtonAction -{ -public: - NoAction() : ButtonAction(Action::None) {} - virtual NoAction* copy(Device* dev); - virtual void press() {} - virtual void release() {} -}; -class KeyAction : public ButtonAction -{ -public: - explicit KeyAction(std::vector k) : ButtonAction(Action::Keypress), keys (std::move(k)) {}; - virtual KeyAction* copy(Device* dev); - virtual void press(); - virtual void release(); -private: - std::vector keys; -}; -class Gesture -{ -public: - Gesture(ButtonAction* ba, GestureMode m, int pp=0, uint a=0, float am=1) - : action (ba), mode (m), per_pixel (pp), axis (a), axis_multiplier (am) + enum class Action { - } - Gesture(const Gesture &g, Device* dev) - : action (g.action->copy(dev)), mode (g.mode), per_pixel (g.per_pixel), axis (g.axis), axis_multiplier (g.axis_multiplier) + None, + Keypress, + Gestures, + CycleDPI, + ChangeDPI, + ToggleSmartshift, + ToggleHiresScroll + }; + enum class Direction { - } + None, + Up, + Down, + Left, + Right + }; + enum class GestureMode + { + NoPress, + OnRelease, + OnFewPixels, + Axis + }; - ButtonAction* action; - GestureMode mode; - int per_pixel; - int per_pixel_mod; - uint axis; - float axis_multiplier; -}; + class Device; -class GestureAction : public ButtonAction -{ -public: - GestureAction(std::map g) : ButtonAction(Action::Gestures), gestures (std::move(g)) {}; - std::map gestures; - virtual GestureAction* copy(Device* dev); - virtual void press(); - virtual void release(); - void move(HIDPP20::IReprogControlsV4::Move m); -private: - bool held; - int x = 0; - int y = 0; -}; -class SmartshiftAction : public ButtonAction -{ -public: - SmartshiftAction() : ButtonAction(Action::ToggleSmartshift) {}; - virtual SmartshiftAction* copy(Device* dev); - virtual void press(); - virtual void release() {} -}; -class HiresScrollAction : public ButtonAction -{ -public: - HiresScrollAction() : ButtonAction(Action::ToggleHiresScroll) {}; - virtual HiresScrollAction* copy(Device* dev); - virtual void press(); - virtual void release() {} -}; -class CycleDPIAction : public ButtonAction -{ -public: - CycleDPIAction(std::vector d) : ButtonAction(Action::CycleDPI), dpis (d) {}; - virtual CycleDPIAction* copy(Device* dev); - virtual void press(); - virtual void release() {} -private: - const std::vector dpis; -}; -class ChangeDPIAction : public ButtonAction -{ -public: - ChangeDPIAction(int i) : ButtonAction(Action::ChangeDPI), dpi_inc (i) {}; - virtual ChangeDPIAction* copy(Device* dev); - virtual void press(); - virtual void release() {} -private: - int dpi_inc; -}; + class ButtonAction + { + public: + virtual ~ButtonAction() = default; -#endif //ACTIONS_H + Action type; + virtual ButtonAction* copy(Device* dev) = 0; + virtual void press() = 0; + virtual void release() = 0; + // ButtonAction(const ButtonAction &a, Device* d) : type (a.type), device (d) {} + // ButtonAction* create_instance(Device* d); + protected: + ButtonAction(Action a) : type (a) {}; + Device* device; + }; + class NoAction : public ButtonAction + { + public: + NoAction() : ButtonAction(Action::None) {} + virtual NoAction* copy(Device* dev); + virtual void press() {} + virtual void release() {} + }; + class KeyAction : public ButtonAction + { + public: + explicit KeyAction(std::vector k) : ButtonAction(Action::Keypress), keys (std::move(k)) {}; + virtual KeyAction* copy(Device* dev); + virtual void press(); + virtual void release(); + private: + std::vector keys; + }; + class Gesture + { + public: + Gesture(ButtonAction* ba, GestureMode m, int pp=0, uint a=0, float am=1) + : action (ba), mode (m), per_pixel (pp), axis (a), axis_multiplier (am) + { + } + Gesture(const Gesture &g, Device* dev) + : action (g.action->copy(dev)), mode (g.mode), per_pixel (g.per_pixel), axis (g.axis), axis_multiplier (g.axis_multiplier) + { + } + + ButtonAction* action; + GestureMode mode; + int per_pixel; + int per_pixel_mod; + uint axis; + float axis_multiplier; + }; + + class GestureAction : public ButtonAction + { + public: + GestureAction(std::map g) : ButtonAction(Action::Gestures), gestures (std::move(g)) {}; + std::map gestures; + virtual GestureAction* copy(Device* dev); + virtual void press(); + virtual void release(); + void move(HIDPP20::IReprogControlsV4::Move m); + private: + bool held; + int x = 0; + int y = 0; + }; + class SmartshiftAction : public ButtonAction + { + public: + SmartshiftAction() : ButtonAction(Action::ToggleSmartshift) {}; + virtual SmartshiftAction* copy(Device* dev); + virtual void press(); + virtual void release() {} + }; + class HiresScrollAction : public ButtonAction + { + public: + HiresScrollAction() : ButtonAction(Action::ToggleHiresScroll) {}; + virtual HiresScrollAction* copy(Device* dev); + virtual void press(); + virtual void release() {} + }; + class CycleDPIAction : public ButtonAction + { + public: + CycleDPIAction(std::vector d) : ButtonAction(Action::CycleDPI), dpis (d) {}; + virtual CycleDPIAction* copy(Device* dev); + virtual void press(); + virtual void release() {} + private: + const std::vector dpis; + }; + class ChangeDPIAction : public ButtonAction + { + public: + ChangeDPIAction(int i) : ButtonAction(Action::ChangeDPI), dpi_inc (i) {}; + virtual ChangeDPIAction* copy(Device* dev); + virtual void press(); + virtual void release() {} + private: + int dpi_inc; + }; +} + +#endif //LOGID_ACTIONS_H diff --git a/src/logid/Configuration.cpp b/src/logid/Configuration.cpp index 41a7a85..f8c8502 100644 --- a/src/logid/Configuration.cpp +++ b/src/logid/Configuration.cpp @@ -10,6 +10,7 @@ #include "Configuration.h" #include "util.h" +using namespace logid; using namespace libconfig; Configuration::Configuration(const char *config_file) @@ -230,7 +231,7 @@ DeviceConfig::DeviceConfig(const libconfig::Setting &root) } } -ButtonAction* parse_action(Action type, const Setting* action_config, bool is_gesture) +ButtonAction* logid::parse_action(Action type, const Setting* action_config, bool is_gesture) { if(type == Action::None) return new NoAction(); if(type == Action::Keypress) diff --git a/src/logid/Configuration.h b/src/logid/Configuration.h index 8952424..463b51f 100644 --- a/src/logid/Configuration.h +++ b/src/logid/Configuration.h @@ -1,41 +1,44 @@ -#ifndef CONFIGURATION_H -#define CONFIGURATION_H +#ifndef LOGID_CONFIGURATION_H +#define LOGID_CONFIGURATION_H #include #include #include #include "Actions.h" -class DeviceConfig; -class ButtonAction; -enum class Action; - -class DeviceConfig +namespace logid { -public: - DeviceConfig(); - ~DeviceConfig(); - DeviceConfig(DeviceConfig* dc, Device* dev); - DeviceConfig(const libconfig::Setting& root); - const int* dpi = nullptr; - HIDPP20::ISmartShift::SmartshiftStatus* smartshift; - const uint8_t* hiresscroll = nullptr; - std::map actions; - const bool baseConfig = true; -}; + class DeviceConfig; + class ButtonAction; + enum class Action; -class Configuration -{ -public: - Configuration(const char* config_file); - Configuration() {} - std::map devices; -private: - libconfig::Config cfg; -}; + class DeviceConfig + { + public: + DeviceConfig(); + ~DeviceConfig(); + DeviceConfig(DeviceConfig* dc, Device* dev); + DeviceConfig(const libconfig::Setting& root); + const int* dpi = nullptr; + HIDPP20::ISmartShift::SmartshiftStatus* smartshift; + const uint8_t* hiresscroll = nullptr; + std::map actions; + const bool baseConfig = true; + }; -ButtonAction* parse_action(Action action, const libconfig::Setting* action_config, bool is_gesture=false); + class Configuration + { + public: + Configuration(const char* config_file); + Configuration() {} + std::map devices; + private: + libconfig::Config cfg; + }; -extern Configuration* global_config; + ButtonAction* parse_action(Action action, const libconfig::Setting* action_config, bool is_gesture=false); -#endif //CONFIGURATION_H \ No newline at end of file + extern Configuration* global_config; +} + +#endif //LOGID_CONFIGURATION_H \ No newline at end of file diff --git a/src/logid/Device.cpp b/src/logid/Device.cpp index 5b00304..1d269e6 100644 --- a/src/logid/Device.cpp +++ b/src/logid/Device.cpp @@ -21,6 +21,8 @@ #include "util.h" #include "EvdevDevice.h" +using namespace logid; + using namespace std::chrono_literals; Device::Device(std::string p, const HIDPP::DeviceIndex i) : path(std::move(p)), index (i) diff --git a/src/logid/Device.h b/src/logid/Device.h index 438a645..5963c89 100644 --- a/src/logid/Device.h +++ b/src/logid/Device.h @@ -1,5 +1,5 @@ -#ifndef DEVICE_H -#define DEVICE_H +#ifndef LOGID_DEVICE_H +#define LOGID_DEVICE_H #include "Actions.h" #include "DeviceFinder.h" @@ -13,145 +13,149 @@ #include #include -class EventListener; -class DeviceConfig; - -class Device +namespace logid { -public: - Device(std::string p, const HIDPP::DeviceIndex i); - ~Device(); + class EventListener; + class DeviceConfig; - std::string name; - - bool init(); - void configure(); - void reset(); - - void press_button(uint16_t cid); - void release_button(uint16_t cid); - void move_diverted(uint16_t cid, HIDPP20::IReprogControlsV4::Move move); - - void wait_for_receiver(); - void start(); - void stop(); - bool testConnection(); - - std::map get_features(); - - std::map features; - - const std::string path; - const HIDPP::DeviceIndex index; - HIDPP::Dispatcher* dispatcher; - HIDPP20::Device* hidpp_dev; - - std::mutex configuring; - std::atomic_bool disconnected; - bool initialized = false; - bool waiting_for_receiver = false; - -protected: - DeviceConfig* config; - EventListener* listener; - - void divert_buttons(); - void set_smartshift(HIDPP20::ISmartShift::SmartshiftStatus ops); - void set_hiresscroll(uint8_t flags); - void set_dpi(int dpi); -}; - -class EventHandler -{ -public: - virtual const HIDPP20::FeatureInterface *feature() const = 0; - virtual const std::vector featureIndices() const + class Device { - return {feature()->index()}; + public: + Device(std::string p, const HIDPP::DeviceIndex i); + ~Device(); + + std::string name; + + bool init(); + void configure(); + void reset(); + + void press_button(uint16_t cid); + void release_button(uint16_t cid); + void move_diverted(uint16_t cid, HIDPP20::IReprogControlsV4::Move move); + + void wait_for_receiver(); + void start(); + void stop(); + bool testConnection(); + + std::map get_features(); + + std::map features; + + const std::string path; + const HIDPP::DeviceIndex index; + HIDPP::Dispatcher* dispatcher; + HIDPP20::Device* hidpp_dev; + + std::mutex configuring; + std::atomic_bool disconnected; + bool initialized = false; + bool waiting_for_receiver = false; + + protected: + DeviceConfig* config; + EventListener* listener; + + void divert_buttons(); + void set_smartshift(HIDPP20::ISmartShift::SmartshiftStatus ops); + void set_hiresscroll(uint8_t flags); + void set_dpi(int dpi); }; - virtual void handleEvent (const HIDPP::Report &event) = 0; -}; -class ButtonHandler : public EventHandler -{ -public: - ButtonHandler (Device *d) : dev (d), _irc (HIDPP20::IReprogControls::auto_version(d->hidpp_dev)) { } - const HIDPP20::FeatureInterface *feature () const + + class EventHandler { - return &_irc; - } - void handleEvent (const HIDPP::Report &event); -protected: - Device* dev; - HIDPP20::IReprogControls _irc; - std::vector states; - std::vector new_states; -}; -class ReceiverHandler : public EventHandler -{ -public: - ReceiverHandler (Device *d) : dev (d) { } - const HIDPP20::FeatureInterface *feature () const + public: + virtual const HIDPP20::FeatureInterface *feature() const = 0; + virtual const std::vector featureIndices() const + { + return {feature()->index()}; + }; + virtual void handleEvent (const HIDPP::Report &event) = 0; + }; + class ButtonHandler : public EventHandler { - return nullptr; // This sounds like a horrible idea - } - virtual const std::vector featureIndices() const + public: + ButtonHandler (Device *d) : dev (d), _irc (HIDPP20::IReprogControls::auto_version(d->hidpp_dev)) { } + const HIDPP20::FeatureInterface *feature () const + { + return &_irc; + } + void handleEvent (const HIDPP::Report &event); + protected: + Device* dev; + HIDPP20::IReprogControls _irc; + std::vector states; + std::vector new_states; + }; + class ReceiverHandler : public EventHandler { - return HIDPP10::IReceiver::Events; - } - void handleEvent (const HIDPP::Report &event); -protected: - Device* dev; -}; -class WirelessStatusHandler : public EventHandler -{ -public: - WirelessStatusHandler (Device *d) : dev (d), _iws (d->hidpp_dev) { } - const HIDPP20::FeatureInterface *feature () const + public: + ReceiverHandler (Device *d) : dev (d) { } + const HIDPP20::FeatureInterface *feature () const + { + return nullptr; // This sounds like a horrible idea + } + virtual const std::vector featureIndices() const + { + return HIDPP10::IReceiver::Events; + } + void handleEvent (const HIDPP::Report &event); + protected: + Device* dev; + }; + class WirelessStatusHandler : public EventHandler { - return &_iws; - } - void handleEvent (const HIDPP::Report &event); -protected: - Device* dev; - HIDPP20::IWirelessDeviceStatus _iws; -}; + public: + WirelessStatusHandler (Device *d) : dev (d), _iws (d->hidpp_dev) { } + const HIDPP20::FeatureInterface *feature () const + { + return &_iws; + } + void handleEvent (const HIDPP::Report &event); + protected: + Device* dev; + HIDPP20::IWirelessDeviceStatus _iws; + }; -class EventListener -{ - HIDPP::Dispatcher *dispatcher; - HIDPP::DeviceIndex index; - std::map> handlers; - std::map iterators; -public: - EventListener (HIDPP::Dispatcher *dispatcher, HIDPP::DeviceIndex index): dispatcher (dispatcher), index (index) {} - - virtual void removeEventHandlers (); - virtual ~EventListener(); - virtual void addEventHandler (std::unique_ptr &&handler); - - virtual void start () = 0; - virtual void stop () = 0; - -protected: - virtual bool event (EventHandler* handler, const HIDPP::Report &report) = 0; -}; -class SimpleListener : public EventListener -{ - HIDPP::SimpleDispatcher *dispatcher; - -public: - SimpleListener (HIDPP::SimpleDispatcher* dispatcher, HIDPP::DeviceIndex index): - EventListener (dispatcher, index), - dispatcher (dispatcher) + class EventListener { - } + HIDPP::Dispatcher *dispatcher; + HIDPP::DeviceIndex index; + std::map> handlers; + std::map iterators; + public: + EventListener (HIDPP::Dispatcher *dispatcher, HIDPP::DeviceIndex index): dispatcher (dispatcher), index (index) {} - bool stopped = false; - virtual void start(); - virtual void stop(); + virtual void removeEventHandlers (); + virtual ~EventListener(); + virtual void addEventHandler (std::unique_ptr &&handler); -protected: - virtual bool event (EventHandler* handler, const HIDPP::Report &report); -}; + virtual void start () = 0; + virtual void stop () = 0; -#endif //DEVICE_H \ No newline at end of file + protected: + virtual bool event (EventHandler* handler, const HIDPP::Report &report) = 0; + }; + class SimpleListener : public EventListener + { + HIDPP::SimpleDispatcher *dispatcher; + + public: + SimpleListener (HIDPP::SimpleDispatcher* dispatcher, HIDPP::DeviceIndex index): + EventListener (dispatcher, index), + dispatcher (dispatcher) + { + } + + bool stopped = false; + virtual void start(); + virtual void stop(); + + protected: + virtual bool event (EventHandler* handler, const HIDPP::Report &report); + }; + +} + +#endif //LOGID_DEVICE_H \ No newline at end of file diff --git a/src/logid/DeviceFinder.cpp b/src/logid/DeviceFinder.cpp index 1127157..27b81dd 100644 --- a/src/logid/DeviceFinder.cpp +++ b/src/logid/DeviceFinder.cpp @@ -17,6 +17,8 @@ #define NON_WIRELESS_DEV(index) (index) == HIDPP::DefaultDevice ? "default" : "corderd" +using namespace logid; + void stopAndDeleteConnectedDevice (ConnectedDevice &connected_device) { if(!connected_device.device->waiting_for_receiver) diff --git a/src/logid/DeviceFinder.h b/src/logid/DeviceFinder.h index 06eb675..687b33d 100644 --- a/src/logid/DeviceFinder.h +++ b/src/logid/DeviceFinder.h @@ -1,5 +1,5 @@ -#ifndef DEVICEFINDER_H -#define DEVICEFINDER_H +#ifndef LOGID_DEVICEFINDER_H +#define LOGID_DEVICEFINDER_H #include #include @@ -15,30 +15,34 @@ #define MAX_CONNECTION_TRIES 10 #define TIME_BETWEEN_CONNECTION_TRIES 500ms -class Device; - -struct ConnectedDevice { - Device *device; - std::thread associatedThread; -}; - -class DeviceFinder : public HID::DeviceMonitor +namespace logid { -public: - ~DeviceFinder(); - Device* insertNewDevice (const std::string &path, HIDPP::DeviceIndex index); - Device* insertNewReceiverDevice (const std::string &path, HIDPP::DeviceIndex index); - void stopAndDeleteAllDevicesIn (const std::string &path); - void stopAndDeleteDevice (const std::string &path, HIDPP::DeviceIndex index); -protected: - void addDevice(const char* path); - void removeDevice(const char* path); -private: - std::mutex devices_mutex; - std::map> devices; -}; + class Device; -extern DeviceFinder* finder; + struct ConnectedDevice { + Device *device; + std::thread associatedThread; + }; -#endif //DEVICEFINDER_H \ No newline at end of file + class DeviceFinder : public HID::DeviceMonitor + { + public: + ~DeviceFinder(); + + Device* insertNewDevice (const std::string &path, HIDPP::DeviceIndex index); + Device* insertNewReceiverDevice (const std::string &path, HIDPP::DeviceIndex index); + void stopAndDeleteAllDevicesIn (const std::string &path); + void stopAndDeleteDevice (const std::string &path, HIDPP::DeviceIndex index); + protected: + void addDevice(const char* path); + void removeDevice(const char* path); + private: + std::mutex devices_mutex; + std::map> devices; + }; + + extern DeviceFinder* finder; +} + +#endif //LOGID_DEVICEFINDER_H \ No newline at end of file diff --git a/src/logid/EvdevDevice.cpp b/src/logid/EvdevDevice.cpp index 0ac3545..fa95cf0 100644 --- a/src/logid/EvdevDevice.cpp +++ b/src/logid/EvdevDevice.cpp @@ -4,6 +4,8 @@ #include "EvdevDevice.h" +using namespace logid; + EvdevDevice::EvdevDevice(const char* name) { device = libevdev_new(); diff --git a/src/logid/EvdevDevice.h b/src/logid/EvdevDevice.h index 0d7e78c..308ed85 100644 --- a/src/logid/EvdevDevice.h +++ b/src/logid/EvdevDevice.h @@ -1,20 +1,27 @@ -#ifndef EVDEVDEVICE_H -#define EVDEVDEVICE_H +#ifndef LOGID_EVDEVDEVICE_H +#define LOGID_EVDEVDEVICE_H #include #include -class EvdevDevice +namespace logid { -public: - EvdevDevice(const char* name); - ~EvdevDevice(); - void move_axis(unsigned int axis, int movement); - void send_event(unsigned int type, unsigned int code, int value); - libevdev* device; - libevdev_uinput* ui_device; -}; + class EvdevDevice + { + public: + EvdevDevice(const char *name); -extern EvdevDevice* global_evdev; + ~EvdevDevice(); -#endif //EVDEVDEVICE_H \ No newline at end of file + void move_axis(unsigned int axis, int movement); + + void send_event(unsigned int type, unsigned int code, int value); + + libevdev *device; + libevdev_uinput *ui_device; + }; + + extern EvdevDevice* global_evdev; +} + +#endif //LOGID_EVDEVDEVICE_H \ No newline at end of file diff --git a/src/logid/logid.cpp b/src/logid/logid.cpp index d08e95b..c6b2d6b 100644 --- a/src/logid/logid.cpp +++ b/src/logid/logid.cpp @@ -19,10 +19,12 @@ #define evdev_name "logid" #define DEFAULT_CONFIG_FILE "/etc/logid.cfg" -LogLevel global_verbosity = INFO; -Configuration* global_config; -EvdevDevice* global_evdev; -DeviceFinder* finder; +using namespace logid; + +LogLevel logid::global_verbosity = INFO; +Configuration* logid::global_config; +EvdevDevice* logid::global_evdev; +DeviceFinder* logid::finder; enum class Option { diff --git a/src/logid/util.cpp b/src/logid/util.cpp index 960cac0..194f3d9 100644 --- a/src/logid/util.cpp +++ b/src/logid/util.cpp @@ -7,7 +7,9 @@ #include "util.h" -void log_printf(LogLevel level, const char* format, ...) +using namespace logid; + +void logid::log_printf(LogLevel level, const char* format, ...) { if(global_verbosity > level) return; @@ -22,7 +24,7 @@ void log_printf(LogLevel level, const char* format, ...) fprintf(stream, "\n"); } -const char* level_prefix(LogLevel level) +const char* logid::level_prefix(LogLevel level) { if(level == DEBUG) return "DEBUG"; if(level == INFO) return "INFO" ; @@ -32,7 +34,7 @@ const char* level_prefix(LogLevel level) return "DEBUG"; } -Direction get_direction(int x, int y) +Direction logid::get_direction(int x, int y) { if(x == 0 && y == 0) return Direction::None; @@ -59,7 +61,7 @@ Direction get_direction(int x, int y) return Direction::None; } -Direction string_to_direction(std::string s) +Direction logid::string_to_direction(std::string s) { const char* original_str = s.c_str(); std::transform(s.begin(), s.end(), s.begin(), ::tolower); @@ -75,7 +77,7 @@ Direction string_to_direction(std::string s) throw std::invalid_argument(s + " is an invalid direction."); } -GestureMode string_to_gesturemode(std::string s) +GestureMode logid::string_to_gesturemode(std::string s) { const char* original_str = s.c_str(); std::transform(s.begin(), s.end(), s.begin(), ::tolower); @@ -93,7 +95,7 @@ GestureMode string_to_gesturemode(std::string s) return GestureMode::OnRelease; } -Action string_to_action(std::string s) +Action logid::string_to_action(std::string s) { std::string original_str = s; std::transform(s.begin(), s.end(), s.begin(), ::tolower); @@ -109,7 +111,7 @@ Action string_to_action(std::string s) throw std::invalid_argument(original_str + " is an invalid action."); } -LogLevel string_to_loglevel(std::string s) +LogLevel logid::string_to_loglevel(std::string s) { std::string original_str = s; std::transform(s.begin(), s.end(), s.begin(), ::tolower); diff --git a/src/logid/util.h b/src/logid/util.h index c4f0d99..6fd669e 100644 --- a/src/logid/util.h +++ b/src/logid/util.h @@ -1,26 +1,29 @@ -#ifndef UTIL_H -#define UTIL_H +#ifndef LOGID_UTIL_H +#define LOGID_UTIL_H #include "Actions.h" -enum LogLevel +namespace logid { - DEBUG, - INFO, - WARN, - ERROR -}; + enum LogLevel + { + DEBUG, + INFO, + WARN, + ERROR + }; -extern LogLevel global_verbosity; + extern LogLevel global_verbosity; -void log_printf(LogLevel level, const char* format, ...); + void log_printf(LogLevel level, const char* format, ...); -const char* level_prefix(LogLevel level); + const char* level_prefix(LogLevel level); -Direction get_direction(int x, int y); -Direction string_to_direction(std::string s); -GestureMode string_to_gesturemode(std::string s); -Action string_to_action(std::string s); -LogLevel string_to_loglevel(std::string s); + Direction get_direction(int x, int y); + Direction string_to_direction(std::string s); + GestureMode string_to_gesturemode(std::string s); + Action string_to_action(std::string s); + LogLevel string_to_loglevel(std::string s); +} -#endif //UTIL_H \ No newline at end of file +#endif //LOGID_UTIL_H \ No newline at end of file