[haiku-commits] haiku: hrev44100 - src/add-ons/print/transports/usb_port

hrev44100 adds 1 changeset to branch 'master'
old head: 408c7ab11d7dbbbce4c098d83e40db1a3da1c873
new head: 91bc46351227de038ed70b89d94048801bb1f429

----------------------------------------------------------------------------

91bc463: USB transport addon: support for alternate interfaces.
  
  * Tested with a Profilic USB-Parallel adapter and a Laserjet printer.

                                   [ Jérôme Duval <jerome.duval@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev44100
Commit:      91bc46351227de038ed70b89d94048801bb1f429
URL:         http://cgit.haiku-os.org/haiku/commit/?id=91bc463
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Thu May  3 20:22:33 2012 UTC

----------------------------------------------------------------------------

1 file changed, 39 insertions(+), 31 deletions(-)
.../print/transports/usb_port/USBTransport.cpp     |   70 +++++++++-------

----------------------------------------------------------------------------

diff --git a/src/add-ons/print/transports/usb_port/USBTransport.cpp 
b/src/add-ons/print/transports/usb_port/USBTransport.cpp
index d69e7dc..e2e3975 100644
--- a/src/add-ons/print/transports/usb_port/USBTransport.cpp
+++ b/src/add-ons/print/transports/usb_port/USBTransport.cpp
@@ -112,29 +112,37 @@ USBPrinterRoster::DeviceAdded(BUSBDevice *dev)
 
        // Try to find a working printer interface in this device
        if (config) {
-               for (uint32 idx = 0; printer == NULL && idx < 
config->CountInterfaces(); idx++) {
+               for (uint32 idx = 0; printer == NULL
+                       && idx < config->CountInterfaces(); idx++) {
                        const BUSBInterface *interface = 
config->InterfaceAt(idx);
-                       if (interface->Class() == PRINTER_INTERFACE_CLASS
-                               && interface->Subclass() == 
PRINTER_INTERFACE_SUBCLASS
-                               && (interface->Protocol() == PIT_UNIDIRECTIONAL
-                               || interface->Protocol() == PIT_BIDIRECTIONAL
-                               ||  interface->Protocol() == 
PIT_1284_4_COMPATIBLE)) {
-                               // Found a usable Printer interface!
-                               for (uint32 endpointIdx = 0; endpointIdx < 
interface->CountEndpoints(); endpointIdx++) {
-                                       const BUSBEndpoint *endpoint = 
interface->EndpointAt(endpointIdx);
-                                       if (!endpoint->IsBulk())
-                                               continue;
-
-                                       if (endpoint->IsInput())
-                                               in = endpoint;
-                                       else if (endpoint->IsOutput())
-                                               out = endpoint;
-
-                                       if (!in || !out)
-                                               continue;
-
-                                       printer = interface;
-                                       break;
+                       for (uint32 alt = 0; alt < 
interface->CountAlternates(); alt++) {
+                               const BUSBInterface *alternate = 
interface->AlternateAt(alt);
+                               if (alternate->Class() == 
PRINTER_INTERFACE_CLASS
+                                       && alternate->Subclass() == 
PRINTER_INTERFACE_SUBCLASS
+                                       && (alternate->Protocol() == 
PIT_UNIDIRECTIONAL
+                                       || alternate->Protocol() == 
PIT_BIDIRECTIONAL
+                                       ||  alternate->Protocol() == 
PIT_1284_4_COMPATIBLE)) {
+                                       // Found a usable Printer interface!
+                                       for (uint32 endpointIdx = 0;
+                                               endpointIdx < 
alternate->CountEndpoints();
+                                               endpointIdx++) {
+                                               const BUSBEndpoint *endpoint =
+                                                       
alternate->EndpointAt(endpointIdx);
+                                               if (!endpoint->IsBulk())
+                                                       continue;
+
+                                               if (endpoint->IsInput())
+                                                       in = endpoint;
+                                               else if (endpoint->IsOutput())
+                                                       out = endpoint;
+
+                                               if (!in || !out)
+                                                       continue;
+
+                                               printer = alternate;
+                                               
((BUSBInterface*)interface)->SetAlternate(alt);
+                                               break;
+                                       }
                                }
                        }
                }
@@ -168,7 +176,7 @@ USBPrinterRoster::DeviceAdded(BUSBDevice *dev)
 }
 
 
-void 
+void
 USBPrinterRoster::DeviceRemoved(BUSBDevice *dev)
 {
        PrinterMap::Iterator iterator = fPrinters.GetIterator();
@@ -184,7 +192,7 @@ USBPrinterRoster::DeviceRemoved(BUSBDevice *dev)
 }
 
 
-status_t 
+status_t
 USBPrinterRoster::ListPrinters(BMessage *msg)
 {
        PrinterMap::Iterator iterator = fPrinters.GetIterator();
@@ -206,7 +214,7 @@ USBPrinter::USBPrinter(const BString& id, const BString& 
name,
 
 
 //TODO: see usb_printer.cpp for error handling during read/write!
-ssize_t 
+ssize_t
 USBPrinter::Write(const void *buf, size_t size)
 {
        if (!buf || size <= 0)
@@ -229,20 +237,20 @@ USBPrinter::Read(void *buf, size_t size)
 
 // Implementation of transport add-on interface
 
-BDataIO * 
-instantiate_transport(BDirectory *printer, BMessage *msg) 
+BDataIO *
+instantiate_transport(BDirectory *printer, BMessage *msg)
 {
        USBTransport *transport = new(std::nothrow) USBTransport(printer, msg);
        if (transport != NULL && transport->InitCheck() == B_OK)
                return transport;
-       
-       delete transport; 
+
+       delete transport;
        return NULL;
 }
 
 
 // List detected printers
-status_t 
+status_t
 list_transport_ports(BMessage *msg)
 {
        USBPrinterRoster roster;
@@ -253,7 +261,7 @@ list_transport_ports(BMessage *msg)
 
 
 // Implementation of USBTransport
-USBTransport::USBTransport(BDirectory *printer, BMessage *msg) 
+USBTransport::USBTransport(BDirectory *printer, BMessage *msg)
        : fPrinter(NULL)
 {
        BString key;


Other related posts:

  • » [haiku-commits] haiku: hrev44100 - src/add-ons/print/transports/usb_port - korli