mirror of
https://github.com/nefarius/ViGEmBus.git
synced 2025-08-10 00:52:17 +00:00
Removed obsolete files
Removed Vcpkg attributes from project file Removed Vcpkg instructions and cache from appveyor.yml
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
version: 1.16.{build}.0
|
||||
image: Visual Studio 2017
|
||||
before_build:
|
||||
- cmd: vcpkg integrate install
|
||||
- cmd: vcpkg install boost-asio:x86-windows-static
|
||||
- cmd: vcpkg install boost-asio:x64-windows-static
|
||||
build_script:
|
||||
- ps: .\build.ps1
|
||||
artifacts:
|
||||
- path: 'bin**\*.dll'
|
||||
cache:
|
||||
- c:\tools\vcpkg\installed\
|
||||
deploy:
|
||||
- provider: Environment
|
||||
name: BUILDBOT
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2019 Nefarius Software Solutions e.U. and Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "NotificationRequestPool.h"
|
||||
|
||||
void NotificationRequestPool::strand_dispatch_worker() const
|
||||
{
|
||||
io_svc_->run();
|
||||
}
|
||||
|
||||
NotificationRequestPool::NotificationRequestPool(
|
||||
PVIGEM_CLIENT client,
|
||||
PVIGEM_TARGET target
|
||||
) :
|
||||
client_(client),
|
||||
target_(target),
|
||||
stop_(false)
|
||||
{
|
||||
// prepare array of handles and request wrappers
|
||||
for (auto& wait_handle : wait_handles_)
|
||||
{
|
||||
// create auto-reset event
|
||||
wait_handle = CreateEvent(nullptr, FALSE, FALSE, nullptr);
|
||||
// create async pending I/O request wrapper
|
||||
requests_.push_back(std::make_unique<XusbNotificationRequest>(
|
||||
client_,
|
||||
target_,
|
||||
wait_handle
|
||||
));
|
||||
}
|
||||
|
||||
// init ASIO
|
||||
io_svc_.reset(new boost::asio::io_service());
|
||||
worker_.reset(new boost::asio::io_service::work(*io_svc_));
|
||||
|
||||
// launch notification completion thread
|
||||
thread_ = std::make_shared<boost::thread>(boost::ref(*this));
|
||||
|
||||
// launch boost I/O service dispatcher thread
|
||||
worker_thread_ = std::make_shared<boost::thread>(
|
||||
boost::bind(&NotificationRequestPool::strand_dispatch_worker, this));
|
||||
|
||||
// submit pending I/O to driver
|
||||
for (auto& request : requests_)
|
||||
request->request_async();
|
||||
}
|
||||
|
||||
NotificationRequestPool::~NotificationRequestPool() noexcept(false)
|
||||
{
|
||||
for (auto& wait_handle : wait_handles_)
|
||||
CloseHandle(wait_handle);
|
||||
|
||||
for (auto& request : requests_)
|
||||
request.reset();
|
||||
|
||||
io_svc_->stop();
|
||||
worker_thread_->join();
|
||||
}
|
||||
|
||||
void NotificationRequestPool::operator()()
|
||||
{
|
||||
// used to dispatch notification callback
|
||||
boost::asio::io_service::strand strand(*io_svc_);
|
||||
|
||||
while (true)
|
||||
{
|
||||
// wait for the first pending I/O to signal its event
|
||||
const auto ret = WaitForMultipleObjects(
|
||||
requests_.size(),
|
||||
wait_handles_,
|
||||
FALSE, // first one to be signaled wins
|
||||
25 // don't block indefinitely so worker can be canceled
|
||||
);
|
||||
|
||||
// timeout has occurred...
|
||||
if (ret == WAIT_TIMEOUT)
|
||||
{
|
||||
// ...check for termination request
|
||||
boost::mutex::scoped_lock lock(m_);
|
||||
if (stop_)
|
||||
// exits function (terminates thread)
|
||||
break;
|
||||
|
||||
// go for another round
|
||||
continue;
|
||||
}
|
||||
|
||||
// handles are closed...?
|
||||
if (ret == WAIT_FAILED)
|
||||
{
|
||||
// exits function (terminates thread)
|
||||
break;
|
||||
}
|
||||
|
||||
// index of the request which just got completed
|
||||
const auto index = ret - WAIT_OBJECT_0;
|
||||
// grab associated request
|
||||
const auto req = requests_[index].get();
|
||||
|
||||
// submit callback for async yet ordered invocation
|
||||
req->post(std::move(strand));
|
||||
|
||||
// submit another pending I/O
|
||||
req->request_async();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationRequestPool::terminate()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_);
|
||||
stop_ = true;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2019 Nefarius Software Solutions e.U. and Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <vector>
|
||||
#include "XusbNotificationRequest.h"
|
||||
#include "ViGEm/Client.h"
|
||||
#include "Internal.h"
|
||||
|
||||
|
||||
class NotificationRequestPool
|
||||
{
|
||||
static const int thread_count = 20;
|
||||
HANDLE wait_handles_[thread_count]{};
|
||||
|
||||
PVIGEM_CLIENT client_;
|
||||
PVIGEM_TARGET target_;
|
||||
|
||||
std::vector<std::unique_ptr<XusbNotificationRequest>> requests_;
|
||||
std::shared_ptr<boost::thread> thread_;
|
||||
boost::mutex m_;
|
||||
boost::condition_variable cv_;
|
||||
bool stop_;
|
||||
|
||||
boost::shared_ptr<boost::asio::io_service> io_svc_;
|
||||
boost::shared_ptr<boost::asio::io_service::work> worker_;
|
||||
std::shared_ptr<boost::thread> worker_thread_;
|
||||
|
||||
void strand_dispatch_worker() const;
|
||||
|
||||
public:
|
||||
NotificationRequestPool(
|
||||
PVIGEM_CLIENT client,
|
||||
PVIGEM_TARGET target
|
||||
);
|
||||
~NotificationRequestPool() noexcept(false);
|
||||
|
||||
void operator()();
|
||||
void terminate();
|
||||
};
|
||||
@@ -38,8 +38,6 @@
|
||||
<ProjectGuid>{7DB06674-1F4F-464B-8E1C-172E9587F9DC}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>ViGEmClient</RootNamespace>
|
||||
<VcpkgTriplet Condition="'$(Platform)'=='Win32'">x86-windows-static</VcpkgTriplet>
|
||||
<VcpkgTriplet Condition="'$(Platform)'=='x64'">x64-windows-static</VcpkgTriplet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(WindowsTargetPlatformVersion)'==''">
|
||||
<!-- Latest Target Version property -->
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2019 Nefarius Software Solutions e.U. and Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "XusbNotificationRequest.h"
|
||||
#include <winioctl.h>
|
||||
#include <ViGEm/Client.h>
|
||||
#include "Internal.h"
|
||||
#include <boost/bind/bind.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
|
||||
XusbNotificationRequest::XusbNotificationRequest(
|
||||
PVIGEM_CLIENT client,
|
||||
PVIGEM_TARGET target,
|
||||
HANDLE notification
|
||||
) : client_(client),
|
||||
target_(target),
|
||||
payload_(),
|
||||
overlapped_()
|
||||
{
|
||||
memset(&overlapped_, 0, sizeof(OVERLAPPED));
|
||||
overlapped_.hEvent = notification;
|
||||
XUSB_REQUEST_NOTIFICATION_INIT(&payload_, target_->SerialNo);
|
||||
}
|
||||
|
||||
bool XusbNotificationRequest::request_async()
|
||||
{
|
||||
// queue request in driver
|
||||
const auto ret = DeviceIoControl(
|
||||
client_->hBusDevice,
|
||||
IOCTL_XUSB_REQUEST_NOTIFICATION,
|
||||
&payload_,
|
||||
payload_.Size,
|
||||
&payload_,
|
||||
payload_.Size,
|
||||
nullptr,
|
||||
&overlapped_
|
||||
);
|
||||
|
||||
const auto error = GetLastError();
|
||||
|
||||
return (!ret && error == ERROR_IO_PENDING);
|
||||
}
|
||||
|
||||
void XusbNotificationRequest::post(boost::asio::io_service::strand strand)
|
||||
{
|
||||
// prepare queueing library caller notification callback
|
||||
const boost::function<void(
|
||||
PVIGEM_CLIENT,
|
||||
PVIGEM_TARGET,
|
||||
UCHAR,
|
||||
UCHAR,
|
||||
UCHAR)> pfn = PFN_VIGEM_X360_NOTIFICATION(target_->Notification);
|
||||
|
||||
// submit callback for async yet ordered invocation
|
||||
strand.post(boost::bind(pfn,
|
||||
client_,
|
||||
target_,
|
||||
payload_.LargeMotor,
|
||||
payload_.SmallMotor,
|
||||
payload_.LedNumber
|
||||
));
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017-2019 Nefarius Software Solutions e.U. and Contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Windows.h>
|
||||
#include "ViGEm/km/BusShared.h"
|
||||
#include <boost/asio.hpp>
|
||||
#include "ViGEm/Client.h"
|
||||
|
||||
class XusbNotificationRequest
|
||||
{
|
||||
PVIGEM_CLIENT client_;
|
||||
PVIGEM_TARGET target_;
|
||||
XUSB_REQUEST_NOTIFICATION payload_;
|
||||
OVERLAPPED overlapped_;
|
||||
|
||||
public:
|
||||
XusbNotificationRequest(PVIGEM_CLIENT client, PVIGEM_TARGET target, HANDLE notification);
|
||||
bool request_async();
|
||||
void post(boost::asio::io_service::strand strand);
|
||||
};
|
||||
Reference in New Issue
Block a user