Again, many things were done in this commit such as implementing an I/O queue, a mutex_queue, and implementing the hidpp::Report class. I'm expecting commits to be like this until I can get a clean codebase for the backend.master
parent
1de722b935
commit
6b895b3015
14 changed files with 442 additions and 55 deletions
@ -0,0 +1,6 @@ |
||||
#include "Error.h" |
||||
|
||||
const char *logid::backend::TimeoutError::what() noexcept |
||||
{ |
||||
return "Device timed out"; |
||||
} |
@ -0,0 +1,16 @@ |
||||
#ifndef LOGID_BACKEND_ERROR_H |
||||
#define LOGID_BACKEND_ERROR_H |
||||
|
||||
#include <stdexcept> |
||||
|
||||
namespace logid { |
||||
namespace backend { |
||||
class TimeoutError: public std::exception |
||||
{ |
||||
public: |
||||
TimeoutError() = default; |
||||
virtual const char* what() noexcept; |
||||
}; |
||||
}} |
||||
|
||||
#endif //LOGID_BACKEND_ERROR_H
|
@ -0,0 +1,15 @@ |
||||
#ifndef LOGID_BACKEND_DEFS_H |
||||
#define LOGID_BACKEND_DEFS_H |
||||
|
||||
#include <functional> |
||||
|
||||
namespace logid::backend |
||||
{ |
||||
struct RawEventHandler |
||||
{ |
||||
std::function<bool(std::vector<uint8_t>& )> condition; |
||||
std::function<void(std::vector<uint8_t>& )> callback; |
||||
}; |
||||
} |
||||
|
||||
#endif //LOGID_BACKEND_DEFS_H
|
@ -0,0 +1,24 @@ |
||||
#ifndef LOGID_HIDPP_DEFS_H |
||||
#define LOGID_HIDPP_DEFS_H |
||||
|
||||
#define LOGID_HIDPP_SOFTWARE_ID 1 |
||||
|
||||
namespace logid::backend::hidpp |
||||
{ |
||||
enum DeviceIndex: uint8_t |
||||
{ |
||||
DefaultDevice = 0, |
||||
WirelessDevice1 = 1, |
||||
WirelessDevice2 = 2, |
||||
WirelessDevice3 = 3, |
||||
WirelessDevice4 = 4, |
||||
WirelessDevice5 = 5, |
||||
WirelessDevice6 = 6, |
||||
CordedDevice = 0xff |
||||
}; |
||||
|
||||
static constexpr std::size_t ShortParamLength = 3; |
||||
static constexpr std::size_t LongParamLength = 16; |
||||
} |
||||
|
||||
#endif //LOGID_HIDPP_DEFS_H
|
@ -0,0 +1,37 @@ |
||||
#ifndef MUTEX_QUEUE_H |
||||
#define MUTEX_QUEUE_H |
||||
|
||||
#include <queue> |
||||
#include <mutex> |
||||
|
||||
template<typename data> |
||||
class mutex_queue |
||||
{ |
||||
public: |
||||
mutex_queue<data>() = default; |
||||
bool empty() |
||||
{ |
||||
std::lock_guard<std::mutex> lock(_mutex); |
||||
return _queue.empty(); |
||||
} |
||||
data& front() |
||||
{ |
||||
std::lock_guard<std::mutex> lock(_mutex); |
||||
return _queue.front(); |
||||
} |
||||
void push(const data& _data) |
||||
{ |
||||
std::lock_guard<std::mutex> lock(_mutex); |
||||
_queue.push(_data); |
||||
} |
||||
void pop() |
||||
{ |
||||
std::lock_guard<std::mutex> lock(_mutex); |
||||
_queue.pop(); |
||||
} |
||||
private: |
||||
std::queue<data> _queue; |
||||
std::mutex _mutex; |
||||
}; |
||||
|
||||
#endif //MUTEX_QUEUE_H
|
Loading…
Reference in new issue