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 "EvdevDevice.h"
using namespace logid;
NoAction* NoAction::copy(Device *dev)
{
auto action = new NoAction();

View File

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

View File

@ -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)

View File

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

View File

@ -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)

View File

@ -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,6 +13,8 @@
#include <hidpp10/IReceiver.h>
#include <hidpp20/IWirelessDeviceStatus.h>
namespace logid
{
class EventListener;
class DeviceConfig;
@ -154,4 +156,6 @@ protected:
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"
using namespace logid;
void stopAndDeleteConnectedDevice (ConnectedDevice &connected_device)
{
if(!connected_device.device->waiting_for_receiver)

View File

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

View File

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

View File

@ -1,20 +1,27 @@
#ifndef EVDEVDEVICE_H
#define EVDEVDEVICE_H
#ifndef LOGID_EVDEVDEVICE_H
#define LOGID_EVDEVDEVICE_H
#include <libevdev/libevdev.h>
#include <libevdev/libevdev-uinput.h>
namespace logid
{
class EvdevDevice
{
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;
};
extern EvdevDevice* global_evdev;
}
#endif //EVDEVDEVICE_H
#endif //LOGID_EVDEVDEVICE_H

View File

@ -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
{

View File

@ -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);

View File

@ -1,8 +1,10 @@
#ifndef UTIL_H
#define UTIL_H
#ifndef LOGID_UTIL_H
#define LOGID_UTIL_H
#include "Actions.h"
namespace logid
{
enum LogLevel
{
DEBUG,
@ -22,5 +24,6 @@ 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
#endif //LOGID_UTIL_H