本文整理汇总了C++中HIDDevice::InitCheck方法的典型用法代码示例。如果您正苦于以下问题:C++ HIDDevice::InitCheck方法的具体用法?C++ HIDDevice::InitCheck怎么用?C++ HIDDevice::InitCheck使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HIDDevice
的用法示例。
在下文中一共展示了HIDDevice::InitCheck方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: new
status_t
usb_hid_device_added(usb_device device, void **cookie)
{
TRACE("device_added()\n");
const usb_device_descriptor *deviceDescriptor
= gUSBModule->get_device_descriptor(device);
TRACE("vendor id: 0x%04x; product id: 0x%04x\n",
deviceDescriptor->vendor_id, deviceDescriptor->product_id);
// wacom devices are handled by the dedicated wacom driver
if (deviceDescriptor->vendor_id == USB_VENDOR_WACOM)
return B_ERROR;
const usb_configuration_info *config
= gUSBModule->get_nth_configuration(device, USB_DEFAULT_CONFIGURATION);
if (config == NULL) {
TRACE_ALWAYS("cannot get default configuration\n");
return B_ERROR;
}
// ensure default configuration is set
status_t result = gUSBModule->set_configuration(device, config);
if (result != B_OK) {
TRACE_ALWAYS("set_configuration() failed 0x%08lx\n", result);
return result;
}
// refresh config
config = gUSBModule->get_configuration(device);
if (config == NULL) {
TRACE_ALWAYS("cannot get current configuration\n");
return B_ERROR;
}
bool devicesFound = false;
int32 parentCookie = atomic_add(&sParentCookie, 1);
for (size_t i = 0; i < config->interface_count; i++) {
const usb_interface_info *interface = config->interface[i].active;
uint8 interfaceClass = interface->descr->interface_class;
TRACE("interface %lu: class: %u; subclass: %u; protocol: %u\n",
i, interfaceClass, interface->descr->interface_subclass,
interface->descr->interface_protocol);
if (interfaceClass == USB_INTERFACE_CLASS_HID) {
mutex_lock(&sDriverLock);
HIDDevice *hidDevice
= new(std::nothrow) HIDDevice(device, config, i);
if (hidDevice != NULL && hidDevice->InitCheck() == B_OK) {
hidDevice->SetParentCookie(parentCookie);
for (uint32 i = 0;; i++) {
ProtocolHandler *handler = hidDevice->ProtocolHandlerAt(i);
if (handler == NULL)
break;
// As devices can be un- and replugged at will, we cannot
// simply rely on a device count. If there is just one
// keyboard, this does not mean that it uses the 0 name.
// There might have been two keyboards and the one using 0
// might have been unplugged. So we just generate names
// until we find one that is not currently in use.
int32 index = 0;
char pathBuffer[128];
const char *basePath = handler->BasePath();
while (true) {
sprintf(pathBuffer, "%s%ld", basePath, index++);
if (gDeviceList->FindDevice(pathBuffer) == NULL) {
// this name is still free, use it
handler->SetPublishPath(strdup(pathBuffer));
break;
}
}
gDeviceList->AddDevice(handler->PublishPath(), handler);
devicesFound = true;
}
} else
delete hidDevice;
mutex_unlock(&sDriverLock);
}
}
if (!devicesFound)
return B_ERROR;
*cookie = (void *)parentCookie;
return B_OK;
}
示例2: new
status_t
usb_hid_device_added(usb_device device, void **cookie)
{
TRACE("device_added()\n");
const usb_device_descriptor *deviceDescriptor
= gUSBModule->get_device_descriptor(device);
TRACE("vendor id: 0x%04x; product id: 0x%04x\n",
deviceDescriptor->vendor_id, deviceDescriptor->product_id);
for (int32 i = 0; i < gBlackListedDeviceCount; i++) {
usb_support_descriptor &entry = gBlackListedDevices[i];
if ((entry.vendor != 0
&& deviceDescriptor->vendor_id != entry.vendor)
|| (entry.product != 0
&& deviceDescriptor->product_id != entry.product)) {
continue;
}
return B_ERROR;
}
const usb_configuration_info *config
= gUSBModule->get_nth_configuration(device, USB_DEFAULT_CONFIGURATION);
if (config == NULL) {
TRACE_ALWAYS("cannot get default configuration\n");
return B_ERROR;
}
// ensure default configuration is set
status_t result = gUSBModule->set_configuration(device, config);
if (result != B_OK) {
TRACE_ALWAYS("set_configuration() failed 0x%08" B_PRIx32 "\n", result);
return result;
}
// refresh config
config = gUSBModule->get_configuration(device);
if (config == NULL) {
TRACE_ALWAYS("cannot get current configuration\n");
return B_ERROR;
}
bool devicesFound = false;
int32 parentCookie = atomic_add(&sParentCookie, 1);
for (size_t i = 0; i < config->interface_count; i++) {
const usb_interface_info *interface = config->interface[i].active;
uint8 interfaceClass = interface->descr->interface_class;
TRACE("interface %" B_PRIuSIZE ": class: %u; subclass: %u; protocol: "
"%u\n", i, interfaceClass, interface->descr->interface_subclass,
interface->descr->interface_protocol);
// check for quirky devices first
int32 quirkyIndex = -1;
for (int32 j = 0; j < gQuirkyDeviceCount; j++) {
usb_hid_quirky_device &quirky = gQuirkyDevices[j];
if ((quirky.vendor_id != 0
&& deviceDescriptor->vendor_id != quirky.vendor_id)
|| (quirky.product_id != 0
&& deviceDescriptor->product_id != quirky.product_id)
|| (quirky.device_class != 0
&& interfaceClass != quirky.device_class)
|| (quirky.device_subclass != 0
&& interface->descr->interface_subclass
!= quirky.device_subclass)
|| (quirky.device_protocol != 0
&& interface->descr->interface_protocol
!= quirky.device_protocol)) {
continue;
}
quirkyIndex = j;
break;
}
if (quirkyIndex >= 0 || interfaceClass == USB_INTERFACE_CLASS_HID) {
mutex_lock(&sDriverLock);
HIDDevice *hidDevice
= new(std::nothrow) HIDDevice(device, config, i, quirkyIndex);
if (hidDevice != NULL && hidDevice->InitCheck() == B_OK) {
hidDevice->SetParentCookie(parentCookie);
for (uint32 i = 0;; i++) {
ProtocolHandler *handler = hidDevice->ProtocolHandlerAt(i);
if (handler == NULL)
break;
// As devices can be un- and replugged at will, we cannot
// simply rely on a device count. If there is just one
// keyboard, this does not mean that it uses the 0 name.
// There might have been two keyboards and the one using 0
// might have been unplugged. So we just generate names
// until we find one that is not currently in use.
int32 index = 0;
char pathBuffer[128];
const char *basePath = handler->BasePath();
while (true) {
sprintf(pathBuffer, "%s%" B_PRId32, basePath, index++);
if (gDeviceList->FindDevice(pathBuffer) == NULL) {
//.........这里部分代码省略.........