Deamon management
This commit is contained in:
50
daemon/g910_device.h
Normal file
50
daemon/g910_device.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// gKeyMapper daemon - raw USB HID access to the keyboard's vendor interface.
|
||||
#ifndef GKEYMAPPER_DAEMON_GKEY_DEVICE_H
|
||||
#define GKEYMAPPER_DAEMON_GKEY_DEVICE_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "device_tables.h"
|
||||
|
||||
struct libusb_context;
|
||||
struct libusb_device_handle;
|
||||
|
||||
namespace gkeymapper::daemon {
|
||||
|
||||
class GKeyDevice {
|
||||
public:
|
||||
GKeyDevice() = default;
|
||||
~GKeyDevice();
|
||||
|
||||
GKeyDevice(const GKeyDevice&) = delete;
|
||||
GKeyDevice& operator=(const GKeyDevice&) = delete;
|
||||
|
||||
// Finds a supported keyboard, opens it and detaches the kernel driver from
|
||||
// the vendor interface. Returns false (and logs) if none is found.
|
||||
bool open();
|
||||
void close();
|
||||
bool is_open() const { return handle_ != nullptr; }
|
||||
|
||||
// Sends the "stop mapping G-keys to F-keys" command if the model needs it.
|
||||
bool disable_binding();
|
||||
|
||||
// Reads one interrupt report. Returns the number of bytes (>0), 0 on
|
||||
// timeout, or a negative value on error.
|
||||
int read_report(uint8_t* buffer, int length, int timeoutMs);
|
||||
|
||||
const DeviceProfile* profile() const { return profile_; }
|
||||
|
||||
private:
|
||||
bool find_endpoint();
|
||||
|
||||
libusb_context* context_ = nullptr;
|
||||
libusb_device_handle* handle_ = nullptr;
|
||||
const DeviceProfile* profile_ = nullptr;
|
||||
uint8_t endpoint_ = 0;
|
||||
int claimed_interface_ = -1;
|
||||
bool detached_kernel_driver_ = false;
|
||||
};
|
||||
|
||||
} // namespace gkeymapper::daemon
|
||||
|
||||
#endif // GKEYMAPPER_DAEMON_GKEY_DEVICE_H
|
||||
Reference in New Issue
Block a user