No comment

This commit is contained in:
Benjamin Höglinger-Stelzer
2019-04-22 12:13:45 +02:00
parent 9071d6c3af
commit 3f1286cbc9
8 changed files with 227 additions and 49 deletions

View File

@@ -0,0 +1,79 @@
#include "NotificationRequestPool.h"
NotificationRequestPool::NotificationRequestPool(
HANDLE bus,
const ULONG serial,
PFN_VIGEM_X360_NOTIFICATION callback) :
callback_(callback),
stop_(false)
{
for (auto& wait_handle : wait_handles_)
{
wait_handle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
XusbNotificationRequest req(bus, serial, wait_handle);
requests_.push_back(std::ref(req));
}
io_svc_.reset(new boost::asio::io_service());
worker_.reset(new boost::asio::io_service::work(*io_svc_));
worker_threads_.reset(new boost::thread_group());
thread_ = std::make_shared<boost::thread>(boost::ref(*this));
for (auto& request : requests_)
request.get().request_async();
}
NotificationRequestPool::~NotificationRequestPool()
{
for (auto& wait_handle : wait_handles_)
CloseHandle(wait_handle);
thread_->join();
}
void NotificationRequestPool::operator()()
{
boost::asio::io_service::strand strand(*io_svc_);
while (true)
{
const auto ret = WaitForMultipleObjects(
requests_.size(),
wait_handles_,
FALSE,
INFINITE
);
const auto index = ret - WAIT_OBJECT_0;
auto& req = requests_[index].get();
//const boost::function<void(
// PVIGEM_CLIENT,
// PVIGEM_TARGET,
// UCHAR,
// UCHAR,
// UCHAR
// )> pfn = callback_;
//strand.post(boost::bind(pfn,
// client,
// target,
// notify.LargeMotor,
// notify.SmallMotor,
// notify.LedNumber
//));
req.request_async();
boost::mutex::scoped_lock lock(m_);
if (stop_)
break;
}
}
void NotificationRequestPool::terminate()
{
boost::mutex::scoped_lock lock(m_);
stop_ = true;
}