forked from tmackay/g13
-
Notifications
You must be signed in to change notification settings - Fork 0
/
g13_manager.hpp
107 lines (77 loc) · 3.25 KB
/
g13_manager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Created by khampf on 13-05-2020.
//
#ifndef G13_G13_MANAGER_HPP
#define G13_G13_MANAGER_HPP
#include "g13.hpp"
#include "g13_action.hpp"
#include "g13_device.hpp"
#include "g13_keys.hpp"
#include "g13_log.hpp"
#include "g13_manager.hpp"
#include <libusb-1.0/libusb.h>
#define CONTROL_DIR std::string("/tmp/")
/*!
* top level class, holds what would otherwise be in global variables
*/
namespace G13 {
class G13_Manager {
private:
G13_Manager();
// declarations
static bool running;
static std::map<std::string, std::string> stringConfigValues;
static libusb_context *libusbContext;
static std::vector<G13::G13_Device *> g13s;
static libusb_hotplug_callback_handle hotplug_cb_handle[3];
static std::map<G13_KEY_INDEX, std::string> g13_key_to_name;
static std::map<std::string, G13_KEY_INDEX> g13_name_to_key;
static std::map<LINUX_KEY_VALUE, std::string> input_key_to_name;
static std::map<std::string, LINUX_KEY_VALUE> input_name_to_key;
static libusb_device **devs;
static std::string logoFilename;
static const int class_id;
public:
static G13_Manager *
Instance(); // Singleton pattern instead of passing references around
// static const std::string &getLogoFilename();
static void setLogoFilename(const std::string &logoFilename);
[[nodiscard]] static int FindG13KeyValue(const std::string &keyname);
[[nodiscard]] static std::string FindG13KeyName(int v);
[[nodiscard]] static G13::LINUX_KEY_VALUE
FindInputKeyValue(const std::string &keyname);
[[nodiscard]] static std::string FindInputKeyName(G13::LINUX_KEY_VALUE v);
static int Run();
[[nodiscard]] static std::string
getStringConfigValue(const std::string &name);
static void setStringConfigValue(const std::string &name,
const std::string &value);
static std::string MakePipeName(G13::G13_Device *d, bool is_input);
static void start_logging();
[[maybe_unused]] static void
SetLogLevel(log4cpp::Priority::PriorityLevel lvl);
static void SetLogLevel(const std::string &level);
protected:
static void InitKeynames();
static void DisplayKeys();
static void DiscoverG13s(libusb_device **devs, ssize_t count);
static void Cleanup();
static void SignalHandler(int);
static void SetupDevice(G13::G13_Device *g13);
static int LIBUSB_CALL HotplugCallbackEnumerate(struct libusb_context *ctx,
struct libusb_device *dev,
libusb_hotplug_event event,
void *user_data);
static int LIBUSB_CALL HotplugCallbackInsert(struct libusb_context *ctx,
struct libusb_device *dev,
libusb_hotplug_event event,
void *user_data);
static int LIBUSB_CALL HotplugCallbackRemove(struct libusb_context *ctx,
struct libusb_device *dev,
libusb_hotplug_event event,
void *user_data);
static int OpenAndAddG13(libusb_device *dev);
static void ArmHotplugCallbacks();
};
} // namespace G13
#endif // G13_G13_MANAGER_HPP