MCPcopy Create free account
hub / github.com/OpenPrinting/cups / copy_printer_interface_deviceid

Function copy_printer_interface_deviceid

backend/usb-darwin.c:1552–1598  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1550}
1551
1552static CFStringRef copy_printer_interface_deviceid(printer_interface_t printer, UInt8 alternateSetting)
1553{
1554 // I have tried to make this function as neat as I can, but the possibility of needing to resend
1555 // a request to get the entire string makes it hideous...
1556 //
1557 // We package the job of sending a request up into the block (^sendRequest), which takes the size
1558 // it should allocate for the message buffer. It frees the current buffer if one is set and
1559 // allocates one of the specified size, then performs the request. We can then easily retry by
1560 // calling the block again if we fail to get the whole string the first time around.
1561
1562 #define kUSBPrintClassGetDeviceID 0
1563 #define kDefaultNoDataTimeout 5000L
1564 #define pack_device_id_wIndex(intf, alt) ((UInt16)((((UInt16)(intf)) << 8) | ((UInt8)(alt))))
1565
1566 if (printer == NULL)
1567 return NULL;
1568
1569
1570 IOReturn err = kIOReturnError;
1571 UInt8 configurationIndex = 0;
1572 UInt8 interfaceNumber = 0;
1573 size_t bufferLength = 256;
1574 CFStringRef ret = NULL;
1575
1576 if ((*printer)->GetConfigurationValue( printer, &configurationIndex) == kIOReturnSuccess &&
1577 (*printer)->GetInterfaceNumber( printer, &interfaceNumber) == kIOReturnSuccess)
1578 {
1579 __block IOUSBDevRequestTO request;
1580 IOReturn (^sendRequest)(size_t) = ^ (size_t size)
1581 {
1582 if (request.pData)
1583 {
1584 free(request.pData);
1585 request.wLength = 0;
1586 request.pData = NULL;
1587 }
1588
1589 IOReturn berr = kIOReturnError;
1590 char *buffer = malloc(size);
1591 if (buffer == NULL)
1592 return kIOReturnNoMemory;
1593
1594 request.wLength = HostToUSBWord(size);
1595 request.pData = buffer;
1596 berr = (*printer)->ControlRequestTO(printer, 0, &request);
1597 return berr;
1598 };
1599
1600 /* This request takes the 0 based configuration index. IOKit returns a 1 based configuration index */
1601 configurationIndex -= 1;

Callers 3

list_device_cbFunction · 0.85
find_device_cbFunction · 0.85
get_device_idFunction · 0.85

Calls 1

ifFunction · 0.50

Tested by

no test coverage detected