* Fix coding style issues.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36134 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -31,11 +31,12 @@
|
|||||||
#define PIT_1284_4_COMPATIBLE 0x03
|
#define PIT_1284_4_COMPATIBLE 0x03
|
||||||
#define PIT_VENDOR_SPECIFIC 0xff
|
#define PIT_VENDOR_SPECIFIC 0xff
|
||||||
|
|
||||||
|
|
||||||
class USBPrinter
|
class USBPrinter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
USBPrinter(const BString& id, const BString& name,
|
USBPrinter(const BString& id, const BString& name,
|
||||||
const BUSBInterface *intf, const BUSBEndpoint* in, const BUSBEndpoint* out);
|
const BUSBInterface *interface, const BUSBEndpoint* in, const BUSBEndpoint* out);
|
||||||
|
|
||||||
ssize_t Write(const void *buf, size_t size);
|
ssize_t Write(const void *buf, size_t size);
|
||||||
ssize_t Read(void *buf, size_t size);
|
ssize_t Read(void *buf, size_t size);
|
||||||
@@ -85,11 +86,13 @@ uint32 transport_features = B_TRANSPORT_IS_HOTPLUG;
|
|||||||
|
|
||||||
USBPrinterRoster gUSBPrinterRoster;
|
USBPrinterRoster gUSBPrinterRoster;
|
||||||
|
|
||||||
|
|
||||||
USBPrinterRoster::USBPrinterRoster()
|
USBPrinterRoster::USBPrinterRoster()
|
||||||
{
|
{
|
||||||
Start();
|
Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
USBPrinter *USBPrinterRoster::Printer(const BString& key)
|
USBPrinter *USBPrinterRoster::Printer(const BString& key)
|
||||||
{
|
{
|
||||||
if (fPrinters.ContainsKey(key.String()))
|
if (fPrinters.ContainsKey(key.String()))
|
||||||
@@ -98,36 +101,37 @@ USBPrinter *USBPrinterRoster::Printer(const BString& key)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t USBPrinterRoster::DeviceAdded(BUSBDevice* dev)
|
status_t USBPrinterRoster::DeviceAdded(BUSBDevice* dev)
|
||||||
{
|
{
|
||||||
const BUSBConfiguration *cfg = dev->ActiveConfiguration();
|
const BUSBConfiguration *config = dev->ActiveConfiguration();
|
||||||
const BUSBEndpoint *in = NULL, *out = NULL;
|
const BUSBEndpoint *in = NULL, *out = NULL;
|
||||||
const BUSBInterface *printer = NULL;
|
const BUSBInterface *printer = NULL;
|
||||||
|
|
||||||
// Try to find a working printer interface in this device
|
// Try to find a working printer interface in this device
|
||||||
if (cfg) {
|
if (config) {
|
||||||
for (uint32 idx=0; printer == NULL && idx < cfg->CountInterfaces(); idx++) {
|
for (uint32 idx = 0; printer == NULL && idx < config->CountInterfaces(); idx++) {
|
||||||
const BUSBInterface *intf=cfg->InterfaceAt(idx);
|
const BUSBInterface *interface = config->InterfaceAt(idx);
|
||||||
if (intf->Class() == PRINTER_INTERFACE_CLASS &&
|
if (interface->Class() == PRINTER_INTERFACE_CLASS &&
|
||||||
intf->Subclass() == PRINTER_INTERFACE_SUBCLASS &&
|
interface->Subclass() == PRINTER_INTERFACE_SUBCLASS &&
|
||||||
(intf->Protocol() == PIT_UNIDIRECTIONAL ||
|
(interface->Protocol() == PIT_UNIDIRECTIONAL ||
|
||||||
intf->Protocol() == PIT_BIDIRECTIONAL ||
|
interface->Protocol() == PIT_BIDIRECTIONAL ||
|
||||||
intf->Protocol() == PIT_1284_4_COMPATIBLE)) {
|
interface->Protocol() == PIT_1284_4_COMPATIBLE)) {
|
||||||
// Found a usable Printer interface!
|
// Found a usable Printer interface!
|
||||||
for (uint32 eptidx=0; eptidx < intf->CountEndpoints(); eptidx++) {
|
for (uint32 endpointIdx = 0; endpointIdx < interface->CountEndpoints(); endpointIdx++) {
|
||||||
const BUSBEndpoint *ept = intf->EndpointAt(eptidx);
|
const BUSBEndpoint *endpoint = interface->EndpointAt(endpointIdx);
|
||||||
if (!ept->IsBulk())
|
if (!endpoint->IsBulk())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (ept->IsInput())
|
if (endpoint->IsInput())
|
||||||
in = ept;
|
in = endpoint;
|
||||||
else if (ept->IsOutput())
|
else if (endpoint->IsOutput())
|
||||||
out = ept;
|
out = endpoint;
|
||||||
|
|
||||||
if (!in || !out)
|
if (!in || !out)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
printer = intf;
|
printer = interface;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,29 +142,30 @@ status_t USBPrinterRoster::DeviceAdded(BUSBDevice* dev)
|
|||||||
// We found a working printer interface, lets determine a unique ID
|
// We found a working printer interface, lets determine a unique ID
|
||||||
// for it now, and a user identification for display in the Printers
|
// for it now, and a user identification for display in the Printers
|
||||||
// preference.
|
// preference.
|
||||||
BString port_id = dev->SerialNumberString();
|
BString portId = dev->SerialNumberString();
|
||||||
if (!port_id.Length()) {
|
if (!portId.Length()) {
|
||||||
// No persistent unique ID available, use the vendor/product
|
// No persistent unique ID available, use the vendor/product
|
||||||
// ID for now. This will be unique as long as no two similar
|
// ID for now. This will be unique as long as no two similar
|
||||||
// devices are attached.
|
// devices are attached.
|
||||||
port_id << dev->VendorID() << "/" << dev->ProductID();
|
portId << dev->VendorID() << "/" << dev->ProductID();
|
||||||
}
|
}
|
||||||
|
|
||||||
BString port_name = dev->ManufacturerString();
|
BString portName = dev->ManufacturerString();
|
||||||
if (port_name.Length())
|
if (portName.Length())
|
||||||
port_name << " ";
|
portName << " ";
|
||||||
port_name << dev->ProductString();
|
portName << dev->ProductString();
|
||||||
|
|
||||||
//TODO: Do we want to use usb.ids to find proper name if strings
|
//TODO: Do we want to use usb.ids to find proper name if strings
|
||||||
// are not supplied by USB?
|
// are not supplied by USB?
|
||||||
|
|
||||||
fPrinters.Put(port_id.String(), new USBPrinter(port_id, port_name,
|
fPrinters.Put(portId.String(), new USBPrinter(portId, portName,
|
||||||
printer, in, out));
|
printer, in, out));
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void USBPrinterRoster::DeviceRemoved(BUSBDevice* dev)
|
void USBPrinterRoster::DeviceRemoved(BUSBDevice* dev)
|
||||||
{
|
{
|
||||||
PrinterMap::Iterator iterator = fPrinters.GetIterator();
|
PrinterMap::Iterator iterator = fPrinters.GetIterator();
|
||||||
@@ -229,12 +234,14 @@ instantiate_transport(BDirectory *printer, BMessage *msg)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// List detected printers
|
// List detected printers
|
||||||
status_t list_transport_ports(BMessage* msg)
|
status_t list_transport_ports(BMessage* msg)
|
||||||
{
|
{
|
||||||
return gUSBPrinterRoster.ListPrinters(msg);
|
return gUSBPrinterRoster.ListPrinters(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Implementation of USBTransport
|
// Implementation of USBTransport
|
||||||
USBTransport::USBTransport(BDirectory *printer, BMessage *msg)
|
USBTransport::USBTransport(BDirectory *printer, BMessage *msg)
|
||||||
: fPrinter(NULL)
|
: fPrinter(NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user