* keep the USBPrinterRoster as a member or local to better control stop and deletion. Should fix #6916.

* style cleanup


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39685 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2010-11-30 20:09:58 +00:00
parent 150b717e5b
commit 25be3898d1
1 changed files with 22 additions and 13 deletions

View File

@ -79,14 +79,13 @@ public:
private: private:
USBPrinter *fPrinter; USBPrinter *fPrinter;
USBPrinterRoster *fRoster;
}; };
// Set transport_features so we stay loaded // Set transport_features so we stay loaded
uint32 transport_features = B_TRANSPORT_IS_HOTPLUG; uint32 transport_features = B_TRANSPORT_IS_HOTPLUG;
USBPrinterRoster gUSBPrinterRoster;
USBPrinterRoster::USBPrinterRoster() USBPrinterRoster::USBPrinterRoster()
{ {
@ -170,7 +169,7 @@ USBPrinterRoster::DeviceAdded(BUSBDevice *dev)
void void
USBPrinterRoster::DeviceRemoved(BUSBDevice* dev) USBPrinterRoster::DeviceRemoved(BUSBDevice *dev)
{ {
PrinterMap::Iterator iterator = fPrinters.GetIterator(); PrinterMap::Iterator iterator = fPrinters.GetIterator();
while (iterator.HasNext()) { while (iterator.HasNext()) {
@ -186,7 +185,7 @@ USBPrinterRoster::DeviceRemoved(BUSBDevice* dev)
status_t status_t
USBPrinterRoster::ListPrinters(BMessage* msg) USBPrinterRoster::ListPrinters(BMessage *msg)
{ {
PrinterMap::Iterator iterator = fPrinters.GetIterator(); PrinterMap::Iterator iterator = fPrinters.GetIterator();
while (iterator.HasNext()) { while (iterator.HasNext()) {
@ -233,8 +232,8 @@ USBPrinter::Read(void *buf, size_t size)
BDataIO * BDataIO *
instantiate_transport(BDirectory *printer, BMessage *msg) instantiate_transport(BDirectory *printer, BMessage *msg)
{ {
USBTransport * transport = new USBTransport(printer, msg); USBTransport *transport = new(std::nothrow) USBTransport(printer, msg);
if (transport->InitCheck() == B_OK) if (transport != NULL && transport->InitCheck() == B_OK)
return transport; return transport;
delete transport; delete transport;
@ -244,9 +243,12 @@ instantiate_transport(BDirectory *printer, BMessage *msg)
// List detected printers // List detected printers
status_t status_t
list_transport_ports(BMessage* msg) list_transport_ports(BMessage *msg)
{ {
return gUSBPrinterRoster.ListPrinters(msg); USBPrinterRoster roster;
status_t status = roster.ListPrinters(msg);
roster.Stop();
return status;
} }
@ -256,15 +258,19 @@ USBTransport::USBTransport(BDirectory *printer, BMessage *msg)
{ {
BString key; BString key;
if (printer->ReadAttrString("transport_address", &key) < 0) if (printer->ReadAttrString("transport_address", &key) != B_OK)
return; return;
fPrinter = gUSBPrinterRoster.Printer(key.String()); fRoster = new(std::nothrow) USBPrinterRoster;
if (!fPrinter) if (fRoster == NULL)
return;
fPrinter = fRoster->Printer(key.String());
if (fPrinter == NULL)
return; return;
// If caller doesn't care... // If caller doesn't care...
if (!msg) if (msg == NULL)
return; return;
// Fill up the message // Fill up the message
@ -274,7 +280,10 @@ USBTransport::USBTransport(BDirectory *printer, BMessage *msg)
USBTransport::~USBTransport() USBTransport::~USBTransport()
{ {
gUSBPrinterRoster.Stop(); if (fRoster != NULL) {
fRoster->Stop();
delete fRoster;
}
} }