mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-09 05:27:58 +00:00
OS X fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "IHIDDevice.hpp"
|
||||
#include "inputdev/CDeviceToken.hpp"
|
||||
#include "inputdev/CDeviceBase.hpp"
|
||||
#include "boo/inputdev/DeviceToken.hpp"
|
||||
#include "boo/inputdev/DeviceBase.hpp"
|
||||
#include <IOKit/hid/IOHIDLib.h>
|
||||
#include <IOKit/usb/IOUSBLib.h>
|
||||
#include <IOKit/IOCFPlugIn.h>
|
||||
@@ -9,10 +9,10 @@
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CHIDDeviceIOKit final : public IHIDDevice
|
||||
class HIDDeviceIOKit : public IHIDDevice
|
||||
{
|
||||
CDeviceToken& m_token;
|
||||
CDeviceBase& m_devImp;
|
||||
DeviceToken& m_token;
|
||||
DeviceBase& m_devImp;
|
||||
|
||||
IOUSBInterfaceInterface** m_usbIntf = NULL;
|
||||
uint8_t m_usbIntfInPipe = 0;
|
||||
@@ -47,7 +47,7 @@ class CHIDDeviceIOKit final : public IHIDDevice
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _threadProcUSBLL(CHIDDeviceIOKit* device)
|
||||
static void _threadProcUSBLL(HIDDeviceIOKit* device)
|
||||
{
|
||||
char thrName[128];
|
||||
snprintf(thrName, 128, "%s Transfer Thread", device->m_token.getProductName().c_str());
|
||||
@@ -174,7 +174,7 @@ class CHIDDeviceIOKit final : public IHIDDevice
|
||||
|
||||
}
|
||||
|
||||
static void _threadProcBTLL(CHIDDeviceIOKit* device)
|
||||
static void _threadProcBTLL(HIDDeviceIOKit* device)
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(device->m_initMutex);
|
||||
|
||||
@@ -191,7 +191,7 @@ class CHIDDeviceIOKit final : public IHIDDevice
|
||||
|
||||
}
|
||||
|
||||
static void _threadProcHID(CHIDDeviceIOKit* device)
|
||||
static void _threadProcHID(HIDDeviceIOKit* device)
|
||||
{
|
||||
std::unique_lock<std::mutex> lk(device->m_initMutex);
|
||||
|
||||
@@ -219,26 +219,29 @@ class CHIDDeviceIOKit final : public IHIDDevice
|
||||
|
||||
public:
|
||||
|
||||
CHIDDeviceIOKit(CDeviceToken& token, CDeviceBase& devImp)
|
||||
HIDDeviceIOKit(DeviceToken& token, DeviceBase& devImp)
|
||||
: m_token(token),
|
||||
m_devImp(devImp),
|
||||
m_devPath(token.getDevicePath())
|
||||
{
|
||||
devImp.m_hidDev = this;
|
||||
std::unique_lock<std::mutex> lk(m_initMutex);
|
||||
CDeviceToken::TDeviceType dType = token.getDeviceType();
|
||||
if (dType == CDeviceToken::DEVTYPE_USB)
|
||||
DeviceToken::TDeviceType dType = token.getDeviceType();
|
||||
if (dType == DeviceToken::DEVTYPE_USB)
|
||||
m_thread = new std::thread(_threadProcUSBLL, this);
|
||||
else if (dType == CDeviceToken::DEVTYPE_BLUETOOTH)
|
||||
else if (dType == DeviceToken::DEVTYPE_BLUETOOTH)
|
||||
m_thread = new std::thread(_threadProcBTLL, this);
|
||||
else if (dType == CDeviceToken::DEVTYPE_GENERICHID)
|
||||
else if (dType == DeviceToken::DEVTYPE_GENERICHID)
|
||||
m_thread = new std::thread(_threadProcHID, this);
|
||||
else
|
||||
throw std::runtime_error("invalid token supplied to device constructor");
|
||||
{
|
||||
fprintf(stderr, "invalid token supplied to device constructor\n");
|
||||
return;
|
||||
}
|
||||
m_initCond.wait(lk);
|
||||
}
|
||||
|
||||
~CHIDDeviceIOKit()
|
||||
~HIDDeviceIOKit()
|
||||
{
|
||||
m_runningTransferLoop = false;
|
||||
m_thread->join();
|
||||
@@ -248,9 +251,9 @@ public:
|
||||
|
||||
};
|
||||
|
||||
IHIDDevice* IHIDDeviceNew(CDeviceToken& token, CDeviceBase& devImp)
|
||||
IHIDDevice* IHIDDeviceNew(DeviceToken& token, DeviceBase& devImp)
|
||||
{
|
||||
return new CHIDDeviceIOKit(token, devImp);
|
||||
return new HIDDeviceIOKit(token, devImp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "IHIDListener.hpp"
|
||||
#include "inputdev/CDeviceFinder.hpp"
|
||||
#include "boo/inputdev/IHIDListener.hpp"
|
||||
#include "boo/inputdev/DeviceFinder.hpp"
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <IOKit/hid/IOHIDLib.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
@@ -52,16 +52,16 @@ static bool getUSBStringDescriptor(IOUSBDeviceInterface182** usbDevice, UInt8 id
|
||||
return true;
|
||||
}
|
||||
|
||||
class CHIDListenerIOKit final : public IHIDListener
|
||||
class HIDListenerIOKit : public IHIDListener
|
||||
{
|
||||
CDeviceFinder& m_finder;
|
||||
DeviceFinder& m_finder;
|
||||
|
||||
CFRunLoopRef m_listenerRunLoop;
|
||||
IONotificationPortRef m_llPort;
|
||||
io_iterator_t m_llAddNotif, m_llRemoveNotif;
|
||||
bool m_scanningEnabled;
|
||||
|
||||
static void devicesConnectedUSBLL(CHIDListenerIOKit* listener,
|
||||
static void devicesConnectedUSBLL(HIDListenerIOKit* listener,
|
||||
io_iterator_t iterator)
|
||||
{
|
||||
io_object_t obj;
|
||||
@@ -83,14 +83,20 @@ class CHIDListenerIOKit final : public IHIDListener
|
||||
IOReturn err;
|
||||
err = IOCreatePlugInInterfaceForService(obj, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &devServ, &score);
|
||||
if (err != kIOReturnSuccess)
|
||||
throw std::runtime_error("unable to open IOKit plugin interface");
|
||||
{
|
||||
fprintf(stderr, "unable to open IOKit plugin interface\n");
|
||||
return;
|
||||
}
|
||||
|
||||
IOUSBDeviceInterface182 **dev;
|
||||
err = (*devServ)->QueryInterface(devServ,
|
||||
CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID182),
|
||||
(LPVOID*)&dev);
|
||||
if (err != kIOReturnSuccess)
|
||||
throw std::runtime_error("unable to open IOKit device interface");
|
||||
{
|
||||
fprintf(stderr, "unable to open IOKit device interface\n");
|
||||
return;
|
||||
}
|
||||
|
||||
UInt16 vid, pid;
|
||||
(*dev)->GetDeviceVendor(dev, &vid);
|
||||
@@ -105,8 +111,8 @@ class CHIDListenerIOKit final : public IHIDListener
|
||||
getUSBStringDescriptor(dev, vstridx, vstr);
|
||||
getUSBStringDescriptor(dev, pstridx, pstr);
|
||||
|
||||
if (!listener->m_finder._insertToken(CDeviceToken(CDeviceToken::DEVTYPE_USB,
|
||||
vid, pid, vstr, pstr, devPath)))
|
||||
if (!listener->m_finder._insertToken(DeviceToken(DeviceToken::DEVTYPE_USB,
|
||||
vid, pid, vstr, pstr, devPath)))
|
||||
{
|
||||
/* Matched-insertion failed; see if generic HID interface is available */
|
||||
/* TODO: Do */
|
||||
@@ -120,7 +126,7 @@ class CHIDListenerIOKit final : public IHIDListener
|
||||
|
||||
}
|
||||
|
||||
static void devicesDisconnectedUSBLL(CHIDListenerIOKit* listener,
|
||||
static void devicesDisconnectedUSBLL(HIDListenerIOKit* listener,
|
||||
io_iterator_t iterator)
|
||||
{
|
||||
if (CFRunLoopGetCurrent() != listener->m_listenerRunLoop)
|
||||
@@ -144,7 +150,7 @@ class CHIDListenerIOKit final : public IHIDListener
|
||||
}
|
||||
|
||||
public:
|
||||
CHIDListenerIOKit(CDeviceFinder& finder)
|
||||
HIDListenerIOKit(DeviceFinder& finder)
|
||||
: m_finder(finder)
|
||||
{
|
||||
|
||||
@@ -174,7 +180,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
~CHIDListenerIOKit()
|
||||
~HIDListenerIOKit()
|
||||
{
|
||||
CFRunLoopRemoveSource(m_listenerRunLoop, IONotificationPortGetRunLoopSource(m_llPort), kCFRunLoopDefaultMode);
|
||||
IOObjectRelease(m_llAddNotif);
|
||||
@@ -209,9 +215,9 @@ public:
|
||||
|
||||
};
|
||||
|
||||
IHIDListener* IHIDListenerNew(CDeviceFinder& finder)
|
||||
IHIDListener* IHIDListenerNew(DeviceFinder& finder)
|
||||
{
|
||||
return new CHIDListenerIOKit(finder);
|
||||
return new HIDListenerIOKit(finder);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user