Use safe thread class instead of std::thread

This commit is contained in:
pixl
2020-06-24 17:31:16 -04:00
parent d84363019b
commit 4ba9248038
7 changed files with 74 additions and 23 deletions

View File

@@ -18,6 +18,7 @@
#include <cassert>
#include <utility>
#include "../../util/thread.h"
#include "Device.h"
#include "Report.h"
#include "../hidpp20/features/Root.h"
@@ -182,7 +183,10 @@ Report Device::sendReport(Report& report)
void Device::listen()
{
if(!_raw_device->isListening())
std::thread{[=]() { _raw_device->listen(); }}.detach();
///TODO: Kill RawDevice?
thread::spawn({[raw=this->_raw_device]() {
raw->listen();
}});
// Pass all HID++ events with device index to this device.
std::shared_ptr<raw::RawEventHandler> handler;

View File

@@ -199,7 +199,7 @@ void Report::setType(Report::Type type)
_data[Offset::Type] = type;
}
hidpp::DeviceIndex Report::deviceIndex()
hidpp::DeviceIndex Report::deviceIndex() const
{
return static_cast<hidpp::DeviceIndex>(_data[Offset::DeviceIndex]);
}
@@ -261,6 +261,26 @@ void Report::setAddress(uint8_t address)
_data[Offset::Address] = address;
}
std::vector<uint8_t>::iterator Report::paramBegin()
{
return _data.begin() + Offset::Parameters;
}
std::vector<uint8_t>::iterator Report::paramEnd()
{
return _data.end();
}
std::vector<uint8_t>::const_iterator Report::paramBegin() const
{
return _data.begin() + Offset::Parameters;
}
std::vector<uint8_t>::const_iterator Report::paramEnd() const
{
return _data.end();
}
void Report::setParams(const std::vector<uint8_t>& _params)
{
assert(_params.size() <= _data.size()-HeaderLength);

View File

@@ -78,7 +78,7 @@ namespace hidpp
Report::Type type() const;
void setType(Report::Type type);
logid::backend::hidpp::DeviceIndex deviceIndex();
logid::backend::hidpp::DeviceIndex deviceIndex() const;
void setDeviceIndex(hidpp::DeviceIndex index);
uint8_t feature() const;
@@ -96,11 +96,10 @@ namespace hidpp
uint8_t address() const;
void setAddress(uint8_t address);
std::vector<uint8_t>::iterator paramBegin()
{
return _data.begin() + Offset::Parameters;
}
std::vector<uint8_t>::iterator paramEnd() { return _data.end(); }
std::vector<uint8_t>::iterator paramBegin();
std::vector<uint8_t>::iterator paramEnd();
std::vector<uint8_t>::const_iterator paramBegin() const;
std::vector<uint8_t>::const_iterator paramEnd() const;
void setParams(const std::vector<uint8_t>& _params);
struct Hidpp10Error