libprint: Fix using auto_ptr to array.
Change-Id: If22530aba951e2856fc03cf59de167353db42604 Reviewed-on: https://review.haiku-os.org/727 Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk> Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
parent
2c5c300420
commit
6d2736585e
@ -7,13 +7,14 @@
|
|||||||
#include "PrinterDriver.h"
|
#include "PrinterDriver.h"
|
||||||
|
|
||||||
#include <fs_attr.h> // for attr_info
|
#include <fs_attr.h> // for attr_info
|
||||||
|
#include <DataIO.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Node.h>
|
#include <Node.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
#include <StackOrHeapArray.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <memory> // for auto_ptr
|
|
||||||
|
|
||||||
#include "AboutBox.h"
|
#include "AboutBox.h"
|
||||||
#include "AddPrinterDlg.h"
|
#include "AddPrinterDlg.h"
|
||||||
@ -38,7 +39,7 @@ PrinterDriver::PrinterDriver(BNode* spoolFolder)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
PrinterDriver::~PrinterDriver()
|
PrinterDriver::~PrinterDriver()
|
||||||
{
|
{
|
||||||
delete fGraphicsDriver;
|
delete fGraphicsDriver;
|
||||||
fGraphicsDriver = NULL;
|
fGraphicsDriver = NULL;
|
||||||
@ -57,7 +58,7 @@ PrinterDriver::InstantiatePrinterData(BNode* node)
|
|||||||
return new PrinterData(node);
|
return new PrinterData(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PrinterDriver::InitPrinterDataAndCap() {
|
PrinterDriver::InitPrinterDataAndCap() {
|
||||||
fPrinterData = InstantiatePrinterData(fSpoolFolder);
|
fPrinterData = InstantiatePrinterData(fSpoolFolder);
|
||||||
fPrinterData->Load();
|
fPrinterData->Load();
|
||||||
@ -67,8 +68,8 @@ PrinterDriver::InitPrinterDataAndCap() {
|
|||||||
fPrinterCap = InstantiatePrinterCap(fPrinterData);
|
fPrinterCap = InstantiatePrinterCap(fPrinterData);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PrinterDriver::About()
|
PrinterDriver::About()
|
||||||
{
|
{
|
||||||
BString copyright;
|
BString copyright;
|
||||||
copyright = "libprint Copyright © 1999-2000 Y.Takagi\n";
|
copyright = "libprint Copyright © 1999-2000 Y.Takagi\n";
|
||||||
@ -79,7 +80,7 @@ PrinterDriver::About()
|
|||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
PrinterDriver::AddPrinter(char* printerName)
|
PrinterDriver::AddPrinter(char* printerName)
|
||||||
{
|
{
|
||||||
// print_server has created a spool folder with name printerName in
|
// print_server has created a spool folder with name printerName in
|
||||||
@ -110,7 +111,7 @@ PrinterDriver::AddPrinter(char* printerName)
|
|||||||
return printerName;
|
return printerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessage*
|
BMessage*
|
||||||
PrinterDriver::ConfigPage(BMessage* settings)
|
PrinterDriver::ConfigPage(BMessage* settings)
|
||||||
{
|
{
|
||||||
DBGMSG((">%s: config_page\n", GetDriverName()));
|
DBGMSG((">%s: config_page\n", GetDriverName()));
|
||||||
@ -128,7 +129,7 @@ PrinterDriver::ConfigPage(BMessage* settings)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessage*
|
BMessage*
|
||||||
PrinterDriver::ConfigJob(BMessage* settings)
|
PrinterDriver::ConfigJob(BMessage* settings)
|
||||||
{
|
{
|
||||||
DBGMSG((">%s: config_job\n", GetDriverName()));
|
DBGMSG((">%s: config_job\n", GetDriverName()));
|
||||||
@ -146,7 +147,7 @@ PrinterDriver::ConfigJob(BMessage* settings)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BMessage*
|
BMessage*
|
||||||
PrinterDriver::TakeJob(BFile* printJob, BMessage* settings)
|
PrinterDriver::TakeJob(BFile* printJob, BMessage* settings)
|
||||||
{
|
{
|
||||||
DBGMSG((">%s: take_job\n", GetDriverName()));
|
DBGMSG((">%s: take_job\n", GetDriverName()));
|
||||||
@ -171,18 +172,18 @@ PrinterDriver::TakeJob(BFile* printJob, BMessage* settings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read settings from spool folder attribute
|
// read settings from spool folder attribute
|
||||||
bool
|
bool
|
||||||
PrinterDriver::_ReadSettings(const char* attrName, BMessage* settings)
|
PrinterDriver::_ReadSettings(const char* attrName, BMessage* settings)
|
||||||
{
|
{
|
||||||
attr_info info;
|
attr_info info;
|
||||||
char* data;
|
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
|
|
||||||
settings->MakeEmpty();
|
settings->MakeEmpty();
|
||||||
|
|
||||||
if (fSpoolFolder->GetAttrInfo(attrName, &info) == B_OK && info.size > 0) {
|
if (fSpoolFolder->GetAttrInfo(attrName, &info) == B_OK && info.size > 0) {
|
||||||
data = new char[info.size];
|
BStackOrHeapArray<char, 0> data(info.size);
|
||||||
auto_ptr<char> _data(data);
|
if (!data.IsValid())
|
||||||
|
return false;
|
||||||
size = fSpoolFolder->ReadAttr(attrName, B_MESSAGE_TYPE, 0, data, info.size);
|
size = fSpoolFolder->ReadAttr(attrName, B_MESSAGE_TYPE, 0, data, info.size);
|
||||||
if (size == info.size && settings->Unflatten(data) == B_OK) {
|
if (size == info.size && settings->Unflatten(data) == B_OK) {
|
||||||
return true;
|
return true;
|
||||||
@ -192,25 +193,23 @@ PrinterDriver::_ReadSettings(const char* attrName, BMessage* settings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// write settings to spool folder attribute
|
// write settings to spool folder attribute
|
||||||
void
|
void
|
||||||
PrinterDriver::_WriteSettings(const char* attrName, BMessage* settings)
|
PrinterDriver::_WriteSettings(const char* attrName, BMessage* settings)
|
||||||
{
|
{
|
||||||
if (settings == NULL || settings->what != 'okok') return;
|
if (settings == NULL || settings->what != 'okok') return;
|
||||||
|
|
||||||
size_t size;
|
status_t status;
|
||||||
char* data;
|
BMallocIO data;
|
||||||
|
status = settings->Flatten(&data);
|
||||||
|
|
||||||
size = settings->FlattenedSize();
|
if (status == B_OK) {
|
||||||
data = new char[size];
|
fSpoolFolder->WriteAttr(attrName, B_MESSAGE_TYPE, 0, data.Buffer(),
|
||||||
auto_ptr<char> _data(data);
|
data.BufferLength());
|
||||||
|
|
||||||
if (data != NULL && settings->Flatten(data, size) == B_OK) {
|
|
||||||
fSpoolFolder->WriteAttr(attrName, B_MESSAGE_TYPE, 0, data, size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// read settings from spool folder attribute and merge them to current settings
|
// read settings from spool folder attribute and merge them to current settings
|
||||||
void
|
void
|
||||||
PrinterDriver::_MergeWithPreviousSettings(const char* attrName, BMessage* settings)
|
PrinterDriver::_MergeWithPreviousSettings(const char* attrName, BMessage* settings)
|
||||||
{
|
{
|
||||||
if (settings == NULL) return;
|
if (settings == NULL) return;
|
||||||
@ -222,9 +221,9 @@ PrinterDriver::_MergeWithPreviousSettings(const char* attrName, BMessage* settin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementation of PrinterDriverInstance
|
// Implementation of PrinterDriverInstance
|
||||||
|
|
||||||
class PrinterDriverInstance
|
class PrinterDriverInstance
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PrinterDriverInstance(BNode* spoolFolder = NULL);
|
PrinterDriverInstance(BNode* spoolFolder = NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user