* 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

View File

@ -79,14 +79,13 @@ public:
private:
USBPrinter *fPrinter;
USBPrinterRoster *fRoster;
};
// Set transport_features so we stay loaded
uint32 transport_features = B_TRANSPORT_IS_HOTPLUG;
USBPrinterRoster gUSBPrinterRoster;
USBPrinterRoster::USBPrinterRoster()
{
@ -233,8 +232,8 @@ USBPrinter::Read(void *buf, size_t size)
BDataIO *
instantiate_transport(BDirectory *printer, BMessage *msg)
{
USBTransport * transport = new USBTransport(printer, msg);
if (transport->InitCheck() == B_OK)
USBTransport *transport = new(std::nothrow) USBTransport(printer, msg);
if (transport != NULL && transport->InitCheck() == B_OK)
return transport;
delete transport;
@ -246,7 +245,10 @@ instantiate_transport(BDirectory *printer, BMessage *msg)
status_t
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;
if (printer->ReadAttrString("transport_address", &key) < 0)
if (printer->ReadAttrString("transport_address", &key) != B_OK)
return;
fPrinter = gUSBPrinterRoster.Printer(key.String());
if (!fPrinter)
fRoster = new(std::nothrow) USBPrinterRoster;
if (fRoster == NULL)
return;
fPrinter = fRoster->Printer(key.String());
if (fPrinter == NULL)
return;
// If caller doesn't care...
if (!msg)
if (msg == NULL)
return;
// Fill up the message
@ -274,7 +280,10 @@ USBTransport::USBTransport(BDirectory *printer, BMessage *msg)
USBTransport::~USBTransport()
{
gUSBPrinterRoster.Stop();
if (fRoster != NULL) {
fRoster->Stop();
delete fRoster;
}
}