2015-08-18 22:43:30 +00:00
|
|
|
#include "boo/inputdev/DeviceSignature.hpp"
|
|
|
|
#include "boo/inputdev/DeviceToken.hpp"
|
|
|
|
#include "boo/inputdev/GenericPad.hpp"
|
2015-04-30 07:01:55 +00:00
|
|
|
#include "IHIDDevice.hpp"
|
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
namespace boo {
|
2015-04-30 07:01:55 +00:00
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
extern const DeviceSignature BOO_DEVICE_SIGS[];
|
2015-04-30 07:01:55 +00:00
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
bool DeviceSignature::DeviceMatchToken(const DeviceToken& token, const TDeviceSignatureSet& sigSet) {
|
|
|
|
if (token.getDeviceType() == DeviceType::HID) {
|
|
|
|
uint64_t genPadHash = dev_typeid(GenericPad);
|
|
|
|
bool hasGenericPad = false;
|
|
|
|
for (const DeviceSignature* sig : sigSet) {
|
|
|
|
if (sig->m_vid == token.getVendorId() && sig->m_pid == token.getProductId() && sig->m_type != DeviceType::HID)
|
|
|
|
return false;
|
|
|
|
if (sig->m_typeHash == genPadHash)
|
|
|
|
hasGenericPad = true;
|
2015-04-30 07:01:55 +00:00
|
|
|
}
|
2018-12-08 05:17:51 +00:00
|
|
|
return hasGenericPad;
|
|
|
|
}
|
|
|
|
for (const DeviceSignature* sig : sigSet) {
|
|
|
|
if (sig->m_vid == token.getVendorId() && sig->m_pid == token.getProductId())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-04-30 07:01:55 +00:00
|
|
|
}
|
|
|
|
|
2017-09-15 17:20:52 +00:00
|
|
|
std::shared_ptr<IHIDDevice> IHIDDeviceNew(DeviceToken& token, const std::shared_ptr<DeviceBase>& devImp);
|
2018-12-08 05:17:51 +00:00
|
|
|
std::shared_ptr<DeviceBase> DeviceSignature::DeviceNew(DeviceToken& token) {
|
|
|
|
std::shared_ptr<DeviceBase> retval;
|
2015-04-30 23:17:46 +00:00
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
/* Perform signature-matching to find the appropriate device-factory */
|
|
|
|
const DeviceSignature* foundSig = nullptr;
|
|
|
|
const DeviceSignature* sigIter = BOO_DEVICE_SIGS;
|
|
|
|
unsigned targetVid = token.getVendorId();
|
|
|
|
unsigned targetPid = token.getProductId();
|
|
|
|
while (sigIter->m_name) {
|
|
|
|
if (sigIter->m_vid == targetVid && sigIter->m_pid == targetPid) {
|
|
|
|
foundSig = sigIter;
|
|
|
|
break;
|
2015-04-30 07:01:55 +00:00
|
|
|
}
|
2018-12-08 05:17:51 +00:00
|
|
|
++sigIter;
|
|
|
|
}
|
|
|
|
if (!foundSig) {
|
|
|
|
/* Try Generic HID devices */
|
|
|
|
if (token.getDeviceType() == DeviceType::HID) {
|
|
|
|
retval = std::make_shared<GenericPad>(&token);
|
|
|
|
if (!retval)
|
|
|
|
return nullptr;
|
2017-05-07 21:24:00 +00:00
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
retval->m_hidDev = IHIDDeviceNew(token, retval);
|
|
|
|
if (!retval->m_hidDev)
|
2017-05-07 21:24:00 +00:00
|
|
|
return nullptr;
|
2018-12-08 05:17:51 +00:00
|
|
|
retval->m_hidDev->_startThread();
|
|
|
|
|
|
|
|
return retval;
|
2017-05-07 21:24:00 +00:00
|
|
|
}
|
2015-04-30 07:01:55 +00:00
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (foundSig->m_type != DeviceType::None && foundSig->m_type != token.getDeviceType())
|
|
|
|
return nullptr;
|
2015-04-30 07:01:55 +00:00
|
|
|
|
2018-12-08 05:17:51 +00:00
|
|
|
retval = foundSig->m_factory(&token);
|
|
|
|
if (!retval)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
retval->m_hidDev = IHIDDeviceNew(token, retval);
|
|
|
|
if (!retval->m_hidDev)
|
|
|
|
return nullptr;
|
|
|
|
retval->m_hidDev->_startThread();
|
|
|
|
|
|
|
|
return retval;
|
2015-04-30 07:01:55 +00:00
|
|
|
}
|
2018-12-08 05:17:51 +00:00
|
|
|
|
|
|
|
} // namespace boo
|