diff options
| author | a1xd <[email protected]> | 2021-09-06 19:11:47 -0400 |
|---|---|---|
| committer | a1xd <[email protected]> | 2021-09-23 22:28:44 -0400 |
| commit | 8680805b267bf5280b8f446ed33ef07981ea5475 (patch) | |
| tree | ccf8f2cd368a5f6d1d87fb23934218946ff6e388 /common | |
| parent | change lookup impl to use binary search (diff) | |
| download | rawaccel-8680805b267bf5280b8f446ed33ef07981ea5475.tar.xz rawaccel-8680805b267bf5280b8f446ed33ef07981ea5475.zip | |
make profile count dynamic (unlimited)
Diffstat (limited to 'common')
| -rw-r--r-- | common/rawaccel-io.hpp | 50 | ||||
| -rw-r--r-- | common/rawaccel.hpp | 13 |
2 files changed, 51 insertions, 12 deletions
diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp index 57bf707..f368896 100644 --- a/common/rawaccel-io.hpp +++ b/common/rawaccel-io.hpp @@ -5,6 +5,8 @@ #include "rawaccel-error.hpp" #include "rawaccel.hpp" +#include <memory> + namespace rawaccel { inline void io_control(DWORD code, void* in, DWORD in_size, void* out, DWORD out_size) @@ -37,14 +39,54 @@ namespace rawaccel { } } - inline void read(io_t& args) + inline std::unique_ptr<std::byte[]> read() { - io_control(READ, NULL, 0, &args, sizeof(io_t)); + io_base base_data; + + io_control(READ, NULL, 0, &base_data, sizeof(io_base)); + + size_t size = sizeof(base_data); + + if (base_data.driver_data_size == 0) { + // driver has no data, but it's more useful to return something, + // so return a default driver_settings object along with base data + + size += sizeof(driver_settings); + base_data.driver_data_size = 1; + auto bytes = std::make_unique<std::byte[]>(size); + *reinterpret_cast<io_base*>(bytes.get()) = base_data; + *reinterpret_cast<driver_settings*>(bytes.get() + sizeof(io_base)) = {}; + return bytes; + } + else { + size += sizeof(driver_settings) * base_data.driver_data_size; + size += sizeof(device_settings) * base_data.device_data_size; + auto bytes = std::make_unique<std::byte[]>(size); + io_control(READ, NULL, 0, bytes.get(), DWORD(size)); + return bytes; + } + } + + // buffer must point to at least sizeof(io_base) bytes + inline void write(const void* buffer) + { + if (buffer == nullptr) throw io_error("write buffer is null"); + + auto* base_ptr = static_cast<const io_base*>(buffer); + auto size = sizeof(io_base); + size += base_ptr->driver_data_size * sizeof(driver_settings); + size += base_ptr->device_data_size * sizeof(device_settings); + + if (size > DWORD(-1)) throw io_error("write buffer is too large"); + + io_control(WRITE, const_cast<void*>(buffer), DWORD(size), NULL, 0); } - inline void write(const io_t& args) + inline void reset() { - io_control(WRITE, const_cast<io_t*>(&args), sizeof(io_t), NULL, 0); + io_base base_data{}; + // all driver/device data is cleared when a default io_base is passed + io_control(WRITE, &base_data, sizeof(io_base), NULL, 0); } inline version_t get_version() diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index b7e632b..c7bf33d 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -48,17 +48,14 @@ namespace rawaccel { settings.data.rot_direction = direction(settings.prof.degrees_rotation); } - inline constexpr unsigned DRIVER_CAPACITY = POOL_SIZE / sizeof(driver_settings); - inline constexpr unsigned DEVICE_CAPACITY = POOL_SIZE / sizeof(device_settings); - - struct io_t { + struct io_base { device_config default_dev_cfg; - unsigned driver_data_size; - unsigned device_data_size; - driver_settings driver_data[DRIVER_CAPACITY]; - device_settings device_data[DEVICE_CAPACITY]; + unsigned driver_data_size = 0; + unsigned device_data_size = 0; }; + static_assert(alignof(io_base) == alignof(driver_settings) && alignof(driver_settings) == alignof(device_settings)); + class modifier { public: #ifdef _KERNEL_MODE |