Use logid namespace

This commit is contained in:
PixlOne 2019-10-04 21:56:17 -04:00
parent 295a469505
commit 9272666ffe
13 changed files with 394 additions and 357 deletions

View File

@ -11,6 +11,8 @@
#include "util.h" #include "util.h"
#include "EvdevDevice.h" #include "EvdevDevice.h"
using namespace logid;
NoAction* NoAction::copy(Device *dev) NoAction* NoAction::copy(Device *dev)
{ {
auto action = new NoAction(); auto action = new NoAction();

View File

@ -1,11 +1,13 @@
#ifndef ACTIONS_H #ifndef LOGID_ACTIONS_H
#define ACTIONS_H #define LOGID_ACTIONS_H
#include "Device.h" #include "Device.h"
#include <map> #include <map>
#include <vector> #include <vector>
#include <hidpp20/IReprogControls.h> #include <hidpp20/IReprogControls.h>
namespace logid
{
enum class Action enum class Action
{ {
None, None,
@ -137,5 +139,6 @@ public:
private: private:
int dpi_inc; int dpi_inc;
}; };
}
#endif //ACTIONS_H #endif //LOGID_ACTIONS_H

View File

@ -10,6 +10,7 @@
#include "Configuration.h" #include "Configuration.h"
#include "util.h" #include "util.h"
using namespace logid;
using namespace libconfig; using namespace libconfig;
Configuration::Configuration(const char *config_file) 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::None) return new NoAction();
if(type == Action::Keypress) if(type == Action::Keypress)

View File

@ -1,11 +1,13 @@
#ifndef CONFIGURATION_H #ifndef LOGID_CONFIGURATION_H
#define CONFIGURATION_H #define LOGID_CONFIGURATION_H
#include <map> #include <map>
#include <libconfig.h++> #include <libconfig.h++>
#include <hidpp20/ISmartShift.h> #include <hidpp20/ISmartShift.h>
#include "Actions.h" #include "Actions.h"
namespace logid
{
class DeviceConfig; class DeviceConfig;
class ButtonAction; class ButtonAction;
enum class Action; enum class Action;
@ -37,5 +39,6 @@ private:
ButtonAction* parse_action(Action action, const libconfig::Setting* action_config, bool is_gesture=false); ButtonAction* parse_action(Action action, const libconfig::Setting* action_config, bool is_gesture=false);
extern Configuration* global_config; extern Configuration* global_config;
}
#endif //CONFIGURATION_H #endif //LOGID_CONFIGURATION_H

View File

@ -21,6 +21,8 @@
#include "util.h" #include "util.h"
#include "EvdevDevice.h" #include "EvdevDevice.h"
using namespace logid;
using namespace std::chrono_literals; using namespace std::chrono_literals;
Device::Device(std::string p, const HIDPP::DeviceIndex i) : path(std::move(p)), index (i) Device::Device(std::string p, const HIDPP::DeviceIndex i) : path(std::move(p)), index (i)

View File

@ -1,5 +1,5 @@
#ifndef DEVICE_H #ifndef LOGID_DEVICE_H
#define DEVICE_H #define LOGID_DEVICE_H
#include "Actions.h" #include "Actions.h"
#include "DeviceFinder.h" #include "DeviceFinder.h"
@ -13,6 +13,8 @@
#include <hidpp10/IReceiver.h> #include <hidpp10/IReceiver.h>
#include <hidpp20/IWirelessDeviceStatus.h> #include <hidpp20/IWirelessDeviceStatus.h>
namespace logid
{
class EventListener; class EventListener;
class DeviceConfig; class DeviceConfig;
@ -154,4 +156,6 @@ protected:
virtual bool event (EventHandler* handler, const HIDPP::Report &report); virtual bool event (EventHandler* handler, const HIDPP::Report &report);
}; };
#endif //DEVICE_H }
#endif //LOGID_DEVICE_H

View File

@ -17,6 +17,8 @@
#define NON_WIRELESS_DEV(index) (index) == HIDPP::DefaultDevice ? "default" : "corderd" #define NON_WIRELESS_DEV(index) (index) == HIDPP::DefaultDevice ? "default" : "corderd"
using namespace logid;
void stopAndDeleteConnectedDevice (ConnectedDevice &connected_device) void stopAndDeleteConnectedDevice (ConnectedDevice &connected_device)
{ {
if(!connected_device.device->waiting_for_receiver) if(!connected_device.device->waiting_for_receiver)

View File

@ -1,5 +1,5 @@
#ifndef DEVICEFINDER_H #ifndef LOGID_DEVICEFINDER_H
#define DEVICEFINDER_H #define LOGID_DEVICEFINDER_H
#include <hid/DeviceMonitor.h> #include <hid/DeviceMonitor.h>
#include <hidpp/SimpleDispatcher.h> #include <hidpp/SimpleDispatcher.h>
@ -15,6 +15,9 @@
#define MAX_CONNECTION_TRIES 10 #define MAX_CONNECTION_TRIES 10
#define TIME_BETWEEN_CONNECTION_TRIES 500ms #define TIME_BETWEEN_CONNECTION_TRIES 500ms
namespace logid
{
class Device; class Device;
struct ConnectedDevice { struct ConnectedDevice {
@ -40,5 +43,6 @@ private:
}; };
extern DeviceFinder* finder; extern DeviceFinder* finder;
}
#endif //DEVICEFINDER_H #endif //LOGID_DEVICEFINDER_H

View File

@ -4,6 +4,8 @@
#include "EvdevDevice.h" #include "EvdevDevice.h"
using namespace logid;
EvdevDevice::EvdevDevice(const char* name) EvdevDevice::EvdevDevice(const char* name)
{ {
device = libevdev_new(); device = libevdev_new();

View File

@ -1,20 +1,27 @@
#ifndef EVDEVDEVICE_H #ifndef LOGID_EVDEVDEVICE_H
#define EVDEVDEVICE_H #define LOGID_EVDEVDEVICE_H
#include <libevdev/libevdev.h> #include <libevdev/libevdev.h>
#include <libevdev/libevdev-uinput.h> #include <libevdev/libevdev-uinput.h>
namespace logid
{
class EvdevDevice class EvdevDevice
{ {
public: public:
EvdevDevice(const char *name); EvdevDevice(const char *name);
~EvdevDevice(); ~EvdevDevice();
void move_axis(unsigned int axis, int movement); void move_axis(unsigned int axis, int movement);
void send_event(unsigned int type, unsigned int code, int value); void send_event(unsigned int type, unsigned int code, int value);
libevdev *device; libevdev *device;
libevdev_uinput *ui_device; libevdev_uinput *ui_device;
}; };
extern EvdevDevice* global_evdev; extern EvdevDevice* global_evdev;
}
#endif //EVDEVDEVICE_H #endif //LOGID_EVDEVDEVICE_H

View File

@ -19,10 +19,12 @@
#define evdev_name "logid" #define evdev_name "logid"
#define DEFAULT_CONFIG_FILE "/etc/logid.cfg" #define DEFAULT_CONFIG_FILE "/etc/logid.cfg"
LogLevel global_verbosity = INFO; using namespace logid;
Configuration* global_config;
EvdevDevice* global_evdev; LogLevel logid::global_verbosity = INFO;
DeviceFinder* finder; Configuration* logid::global_config;
EvdevDevice* logid::global_evdev;
DeviceFinder* logid::finder;
enum class Option enum class Option
{ {

View File

@ -7,7 +7,9 @@
#include "util.h" #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; if(global_verbosity > level) return;
@ -22,7 +24,7 @@ void log_printf(LogLevel level, const char* format, ...)
fprintf(stream, "\n"); fprintf(stream, "\n");
} }
const char* level_prefix(LogLevel level) const char* logid::level_prefix(LogLevel level)
{ {
if(level == DEBUG) return "DEBUG"; if(level == DEBUG) return "DEBUG";
if(level == INFO) return "INFO" ; if(level == INFO) return "INFO" ;
@ -32,7 +34,7 @@ const char* level_prefix(LogLevel level)
return "DEBUG"; 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; if(x == 0 && y == 0) return Direction::None;
@ -59,7 +61,7 @@ Direction get_direction(int x, int y)
return Direction::None; 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(); const char* original_str = s.c_str();
std::transform(s.begin(), s.end(), s.begin(), ::tolower); 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."); 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(); const char* original_str = s.c_str();
std::transform(s.begin(), s.end(), s.begin(), ::tolower); std::transform(s.begin(), s.end(), s.begin(), ::tolower);
@ -93,7 +95,7 @@ GestureMode string_to_gesturemode(std::string s)
return GestureMode::OnRelease; return GestureMode::OnRelease;
} }
Action string_to_action(std::string s) Action logid::string_to_action(std::string s)
{ {
std::string original_str = s; std::string original_str = s;
std::transform(s.begin(), s.end(), s.begin(), ::tolower); 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."); 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::string original_str = s;
std::transform(s.begin(), s.end(), s.begin(), ::tolower); std::transform(s.begin(), s.end(), s.begin(), ::tolower);

View File

@ -1,8 +1,10 @@
#ifndef UTIL_H #ifndef LOGID_UTIL_H
#define UTIL_H #define LOGID_UTIL_H
#include "Actions.h" #include "Actions.h"
namespace logid
{
enum LogLevel enum LogLevel
{ {
DEBUG, DEBUG,
@ -22,5 +24,6 @@ Direction string_to_direction(std::string s);
GestureMode string_to_gesturemode(std::string s); GestureMode string_to_gesturemode(std::string s);
Action string_to_action(std::string s); Action string_to_action(std::string s);
LogLevel string_to_loglevel(std::string s); LogLevel string_to_loglevel(std::string s);
}
#endif //UTIL_H #endif //LOGID_UTIL_H