* Moved printer driver add-on loading and hook function
invocation code from class Printer into new class PrinterDriverAddOn. Refactored code a little bit. * Removed duplicate code from class PrintServerApp and use methods from class Printer instead. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39319 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,6 +8,7 @@ AddResources print_server :
|
|||||||
;
|
;
|
||||||
|
|
||||||
Server print_server :
|
Server print_server :
|
||||||
|
PrinterDriverAddOn.cpp
|
||||||
PrintServerApp.cpp
|
PrintServerApp.cpp
|
||||||
PrintServerApp.R5.cpp
|
PrintServerApp.R5.cpp
|
||||||
PrintServerApp.Scripting.cpp
|
PrintServerApp.Scripting.cpp
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2008, Haiku. All rights reserved.
|
* Copyright 2001-2010, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -46,10 +46,6 @@ typedef struct _printer_data {
|
|||||||
} printer_data_t;
|
} printer_data_t;
|
||||||
|
|
||||||
|
|
||||||
typedef BMessage* (*config_func_t)(BNode*, const BMessage*);
|
|
||||||
typedef BMessage* (*take_job_func_t)(BFile*, BNode*, const BMessage*);
|
|
||||||
typedef char* (*add_printer_func_t)(const char* printer_name);
|
|
||||||
|
|
||||||
|
|
||||||
static const char* kSettingsName = "print_server_settings";
|
static const char* kSettingsName = "print_server_settings";
|
||||||
|
|
||||||
@@ -423,8 +419,8 @@ PrintServerApp::CreatePrinter(const char* printerName, const char* driverName,
|
|||||||
char type[B_MIME_TYPE_LENGTH];
|
char type[B_MIME_TYPE_LENGTH];
|
||||||
BNodeInfo(&printer).GetType(type);
|
BNodeInfo(&printer).GetType(type);
|
||||||
if (strcmp(PSRV_PRINTER_FILETYPE, type) == 0) {
|
if (strcmp(PSRV_PRINTER_FILETYPE, type) == 0) {
|
||||||
BPath tmp;
|
BPath path;
|
||||||
if (FindPrinterDriver(printerName, tmp) == B_OK) {
|
if (Printer::FindPathToDriver(printerName, &path) == B_OK) {
|
||||||
if (fDefaultPrinter) {
|
if (fDefaultPrinter) {
|
||||||
// the printer exists, but is not the default printer
|
// the printer exists, but is not the default printer
|
||||||
if (strcmp(fDefaultPrinter->Name(), printerName) != 0)
|
if (strcmp(fDefaultPrinter->Name(), printerName) != 0)
|
||||||
@@ -471,42 +467,20 @@ PrintServerApp::CreatePrinter(const char* printerName, const char* driverName,
|
|||||||
printer.WriteAttr(PSRV_PRINTER_ATTR_CNX, B_STRING_TYPE, 0, connection,
|
printer.WriteAttr(PSRV_PRINTER_ATTR_CNX, B_STRING_TYPE, 0, connection,
|
||||||
::strlen(connection) + 1);
|
::strlen(connection) + 1);
|
||||||
|
|
||||||
// Notify printer driver that a new printer definition node
|
rc = Printer::ConfigurePrinter(driverName, printerName);
|
||||||
// has been created.
|
if (rc == B_OK) {
|
||||||
image_id id = -1;
|
// Notify printer driver that a new printer definition node
|
||||||
add_printer_func_t func;
|
// has been created.
|
||||||
|
|
||||||
rc = FindPrinterDriver(driverName, path);
|
|
||||||
if (rc != B_OK)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
id = ::load_add_on(path.Path());
|
|
||||||
if (id <= 0) {
|
|
||||||
rc = B_ERROR;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = get_image_symbol(id, "add_printer", B_SYMBOL_TYPE_TEXT, (void**)&func);
|
|
||||||
if (rc != B_OK)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
// call the function and check its result
|
|
||||||
if ((*func)(printerName) == NULL)
|
|
||||||
rc = B_ERROR;
|
|
||||||
else
|
|
||||||
printer.WriteAttr(PSRV_PRINTER_ATTR_STATE, B_STRING_TYPE, 0, "free",
|
printer.WriteAttr(PSRV_PRINTER_ATTR_STATE, B_STRING_TYPE, 0, "free",
|
||||||
::strlen("free")+1);
|
::strlen("free")+1);
|
||||||
|
}
|
||||||
|
|
||||||
error:
|
|
||||||
if (rc != B_OK) {
|
if (rc != B_OK) {
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
if (printer.GetEntry(&entry) == B_OK)
|
if (printer.GetEntry(&entry) == B_OK)
|
||||||
entry.Remove();
|
entry.Remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id > 0)
|
|
||||||
::unload_add_on(id);
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,35 +624,6 @@ PrintServerApp::FindPrinterNode(const char* name, BNode& node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
|
||||||
// FindPrinterDriver(const char* name, BPath& outPath)
|
|
||||||
//
|
|
||||||
// Finds the path to a specific printer driver. It searches all 3
|
|
||||||
// places add-ons can be stored: the user's private directory, the
|
|
||||||
// directory common to all users, and the system directory, in that
|
|
||||||
// order.
|
|
||||||
//
|
|
||||||
// Parameters:
|
|
||||||
// name - Name of the printer driver to look for.
|
|
||||||
// outPath - BPath to store the path to the driver in.
|
|
||||||
//
|
|
||||||
// Returns:
|
|
||||||
// B_OK if the driver was found, otherwise an error code.
|
|
||||||
// ---------------------------------------------------------------
|
|
||||||
status_t
|
|
||||||
PrintServerApp::FindPrinterDriver(const char* name, BPath& outPath)
|
|
||||||
{
|
|
||||||
if (::TestForAddonExistence(name, B_USER_ADDONS_DIRECTORY, "Print", outPath)
|
|
||||||
!= B_OK
|
|
||||||
&& TestForAddonExistence(name, B_COMMON_ADDONS_DIRECTORY, "Print",
|
|
||||||
outPath) != B_OK)
|
|
||||||
return ::TestForAddonExistence(name, B_BEOS_ADDONS_DIRECTORY, "Print",
|
|
||||||
outPath);
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PrintServerApp::OpenSettings(BFile& file, const char* name,
|
PrintServerApp::OpenSettings(BFile& file, const char* name,
|
||||||
bool forReading)
|
bool forReading)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2007, Haiku. All rights reserved.
|
* Copyright 2001-2010, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -74,7 +74,6 @@ class PrintServerApp : public BApplication, public FolderListener {
|
|||||||
status_t RetrieveDefaultPrinter();
|
status_t RetrieveDefaultPrinter();
|
||||||
|
|
||||||
status_t FindPrinterNode(const char *name, BNode &node);
|
status_t FindPrinterNode(const char *name, BNode &node);
|
||||||
status_t FindPrinterDriver(const char *name, BPath &outPath);
|
|
||||||
|
|
||||||
// "Classic" BeOS R5 support, see PrintServerApp.R5.cpp
|
// "Classic" BeOS R5 support, see PrintServerApp.R5.cpp
|
||||||
static status_t async_thread(void *data);
|
static status_t async_thread(void *data);
|
||||||
|
|||||||
+52
-144
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2008, Haiku. All rights reserved.
|
* Copyright 2001-2010, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -8,8 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "Printer.h"
|
#include "Printer.h"
|
||||||
|
|
||||||
#include "pr_server.h"
|
|
||||||
#include "BeUtils.h"
|
#include "BeUtils.h"
|
||||||
|
#include "pr_server.h"
|
||||||
|
#include "PrinterDriverAddOn.h"
|
||||||
#include "PrintServerApp.h"
|
#include "PrintServerApp.h"
|
||||||
|
|
||||||
// posix
|
// posix
|
||||||
@@ -44,12 +45,6 @@ void SpoolFolder::Notify(Job* job, int kind)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
|
||||||
typedef BMessage* (*config_func_t)(BNode*, const BMessage*);
|
|
||||||
typedef BMessage* (*take_job_func_t)(BFile*, BNode*, const BMessage*);
|
|
||||||
typedef char* (*add_printer_func_t)(const char* printer_name);
|
|
||||||
typedef BMessage* (*default_settings_t)(BNode*);
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
BObjectList<Printer> Printer::sPrinters;
|
BObjectList<Printer> Printer::sPrinters;
|
||||||
|
|
||||||
@@ -182,34 +177,30 @@ status_t Printer::Remove()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
Printer::FindPathToDriver(const char* driverName, BPath* path)
|
||||||
|
{
|
||||||
|
return PrinterDriverAddOn::FindPathToDriver(driverName, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
// ConfigurePrinter
|
// ConfigurePrinter
|
||||||
//
|
//
|
||||||
// Handles calling the printer addon's add_printer function.
|
// Handles calling the printer addon's add_printer function.
|
||||||
//
|
//
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// none.
|
// driverName - the name of the printer driver add-on
|
||||||
|
// printerName - the name of the printer spool folder
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// B_OK if successful or errorcode otherwise.
|
// B_OK if successful or errorcode otherwise.
|
||||||
// ---------------------------------------------------------------
|
// ---------------------------------------------------------------
|
||||||
status_t Printer::ConfigurePrinter()
|
status_t Printer::ConfigurePrinter(const char* driverName,
|
||||||
|
const char* printerName)
|
||||||
{
|
{
|
||||||
status_t rc;
|
PrinterDriverAddOn addOn(driverName);
|
||||||
image_id id;
|
return addOn.AddPrinter(printerName);
|
||||||
if ((rc = LoadPrinterAddon(id)) == B_OK) {
|
|
||||||
// Addon was loaded, so try and get the add_printer symbol
|
|
||||||
add_printer_func_t func;
|
|
||||||
if (get_image_symbol(id, "add_printer", B_SYMBOL_TYPE_TEXT,
|
|
||||||
(void**)&func) == B_OK) {
|
|
||||||
// call the function and check its result
|
|
||||||
rc = ((*func)(Name()) == NULL) ? B_ERROR : B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
::unload_add_on(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -229,29 +220,17 @@ status_t Printer::ConfigurePrinter()
|
|||||||
status_t
|
status_t
|
||||||
Printer::ConfigurePage(BMessage& settings)
|
Printer::ConfigurePage(BMessage& settings)
|
||||||
{
|
{
|
||||||
status_t rc;
|
BString driver;
|
||||||
image_id id;
|
status_t result = GetDriverName(&driver);
|
||||||
if ((rc = LoadPrinterAddon(id)) == B_OK) {
|
if (result != B_OK)
|
||||||
// Addon was loaded, so try and get the config_page symbol
|
return result;
|
||||||
config_func_t func;
|
|
||||||
if ((rc=get_image_symbol(id, "config_page", B_SYMBOL_TYPE_TEXT,
|
|
||||||
(void**)&func)) == B_OK) {
|
|
||||||
// call the function and check its result
|
|
||||||
BMessage* new_settings = (*func)(SpoolDir(), &settings);
|
|
||||||
if (new_settings != NULL && new_settings->what != 'baad') {
|
|
||||||
settings = *new_settings;
|
|
||||||
settings.what = 'okok';
|
|
||||||
AddCurrentPrinter(settings);
|
|
||||||
} else {
|
|
||||||
rc = B_ERROR;
|
|
||||||
}
|
|
||||||
delete new_settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
::unload_add_on(id);
|
PrinterDriverAddOn addOn(driver.String());
|
||||||
|
result = addOn.ConfigPage(SpoolDir(), &settings);
|
||||||
|
if (result == B_OK) {
|
||||||
|
AddCurrentPrinter(settings);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -271,29 +250,17 @@ Printer::ConfigurePage(BMessage& settings)
|
|||||||
status_t
|
status_t
|
||||||
Printer::ConfigureJob(BMessage& settings)
|
Printer::ConfigureJob(BMessage& settings)
|
||||||
{
|
{
|
||||||
status_t rc;
|
BString driver;
|
||||||
image_id id;
|
status_t result = GetDriverName(&driver);
|
||||||
if ((rc = LoadPrinterAddon(id)) == B_OK) {
|
if (result != B_OK)
|
||||||
// Addon was loaded, so try and get the config_job symbol
|
return result;
|
||||||
config_func_t func;
|
|
||||||
if ((rc = get_image_symbol(id, "config_job", B_SYMBOL_TYPE_TEXT,
|
|
||||||
(void**)&func)) == B_OK) {
|
|
||||||
// call the function and check its result
|
|
||||||
BMessage* new_settings = (*func)(SpoolDir(), &settings);
|
|
||||||
if ((new_settings != NULL) && (new_settings->what != 'baad')) {
|
|
||||||
settings = *new_settings;
|
|
||||||
settings.what = 'okok';
|
|
||||||
AddCurrentPrinter(settings);
|
|
||||||
} else {
|
|
||||||
rc = B_ERROR;
|
|
||||||
}
|
|
||||||
delete new_settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
::unload_add_on(id);
|
PrinterDriverAddOn addOn(driver.String());
|
||||||
|
result = addOn.ConfigJob(SpoolDir(), &settings);
|
||||||
|
if (result == B_OK) {
|
||||||
|
AddCurrentPrinter(settings);
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -327,28 +294,17 @@ Printer::HandleSpooledJob()
|
|||||||
status_t
|
status_t
|
||||||
Printer::GetDefaultSettings(BMessage& settings)
|
Printer::GetDefaultSettings(BMessage& settings)
|
||||||
{
|
{
|
||||||
status_t rc;
|
BString driver;
|
||||||
image_id id;
|
status_t result = GetDriverName(&driver);
|
||||||
if ((rc = LoadPrinterAddon(id)) == B_OK) {
|
if (result != B_OK)
|
||||||
// Addon was loaded, so try and get the default_settings symbol
|
return result;
|
||||||
default_settings_t func;
|
|
||||||
if ((rc = get_image_symbol(id, "default_settings", B_SYMBOL_TYPE_TEXT,
|
|
||||||
(void**)&func)) == B_OK) {
|
|
||||||
// call the function and check its result
|
|
||||||
BMessage* new_settings = (*func)(SpoolDir());
|
|
||||||
if (new_settings) {
|
|
||||||
settings = *new_settings;
|
|
||||||
settings.what = 'okok';
|
|
||||||
AddCurrentPrinter(settings);
|
|
||||||
} else {
|
|
||||||
rc = B_ERROR;
|
|
||||||
}
|
|
||||||
delete new_settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
::unload_add_on(id);
|
PrinterDriverAddOn addOn(driver.String());
|
||||||
|
result = addOn.DefaultSettings(SpoolDir(), &settings);
|
||||||
|
if (result == B_OK) {
|
||||||
|
AddCurrentPrinter(settings);
|
||||||
}
|
}
|
||||||
return rc;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -359,42 +315,10 @@ Printer::AbortPrintThread()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
status_t
|
||||||
// LoadPrinterAddon
|
Printer::GetDriverName(BString* name)
|
||||||
//
|
|
||||||
// Try to load the printer addon into memory.
|
|
||||||
//
|
|
||||||
// Parameters:
|
|
||||||
// id - image_id set to the image id of the loaded addon.
|
|
||||||
//
|
|
||||||
// Returns:
|
|
||||||
// B_OK if successful or errorcode otherwise.
|
|
||||||
// ---------------------------------------------------------------
|
|
||||||
status_t
|
|
||||||
Printer::LoadPrinterAddon(image_id& id)
|
|
||||||
{
|
{
|
||||||
status_t rc;
|
return SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_DRV_NAME, name);
|
||||||
BString drName;
|
|
||||||
if ((rc = SpoolDir()->ReadAttrString(PSRV_PRINTER_ATTR_DRV_NAME, &drName)) == B_OK) {
|
|
||||||
// try to locate the driver
|
|
||||||
BPath path;
|
|
||||||
if ((rc= ::TestForAddonExistence(drName.String(), B_USER_ADDONS_DIRECTORY,
|
|
||||||
"Print", path)) != B_OK) {
|
|
||||||
if ((rc = ::TestForAddonExistence(drName.String(), B_COMMON_ADDONS_DIRECTORY,
|
|
||||||
"Print", path)) != B_OK) {
|
|
||||||
rc = ::TestForAddonExistence(drName.String(), B_BEOS_ADDONS_DIRECTORY,
|
|
||||||
"Print", path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the driver was found
|
|
||||||
if (rc == B_OK) {
|
|
||||||
// If we cannot load the addon
|
|
||||||
if ((id=::load_add_on(path.Path())) < 0)
|
|
||||||
rc = id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -556,29 +480,13 @@ Printer::FindSpooledJob()
|
|||||||
status_t
|
status_t
|
||||||
Printer::PrintSpooledJob(BFile* spoolFile)
|
Printer::PrintSpooledJob(BFile* spoolFile)
|
||||||
{
|
{
|
||||||
status_t rc;
|
BString driver;
|
||||||
image_id id;
|
status_t result = GetDriverName(&driver);
|
||||||
if ((rc = LoadPrinterAddon(id)) == B_OK) {
|
if (result != B_OK)
|
||||||
take_job_func_t func;
|
return result;
|
||||||
// Addon was loaded, so try and get the take_job symbol
|
|
||||||
if ((rc = get_image_symbol(id, "take_job", B_SYMBOL_TYPE_TEXT,
|
|
||||||
(void**)&func)) == B_OK) {
|
|
||||||
// This seems to be required for legacy?
|
|
||||||
// HP PCL3 add-on crashes without it!
|
|
||||||
BMessage params(B_REFS_RECEIVED);
|
|
||||||
params.AddInt32("file", (int32)spoolFile);
|
|
||||||
params.AddInt32("printer", (int32)SpoolDir());
|
|
||||||
// call the function and check its result
|
|
||||||
BMessage* result = (*func)(spoolFile, SpoolDir(), ¶ms);
|
|
||||||
|
|
||||||
if (result == NULL || result->what != 'okok')
|
PrinterDriverAddOn addOn(driver.String());
|
||||||
rc = B_ERROR;
|
return addOn.TakeJob(spoolFile, SpoolDir());
|
||||||
delete result;
|
|
||||||
}
|
|
||||||
|
|
||||||
::unload_add_on(id);
|
|
||||||
}
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2008, Haiku. All rights reserved.
|
* Copyright 2001-2010, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -62,7 +62,10 @@ public:
|
|||||||
static int32 CountPrinters();
|
static int32 CountPrinters();
|
||||||
|
|
||||||
status_t Remove();
|
status_t Remove();
|
||||||
status_t ConfigurePrinter();
|
static status_t FindPathToDriver(const char* driver,
|
||||||
|
BPath* path);
|
||||||
|
static status_t ConfigurePrinter(const char* driverName,
|
||||||
|
const char* printerName);
|
||||||
status_t ConfigureJob(BMessage& ioSettings);
|
status_t ConfigureJob(BMessage& ioSettings);
|
||||||
status_t ConfigurePage(BMessage& ioSettings);
|
status_t ConfigurePage(BMessage& ioSettings);
|
||||||
status_t GetDefaultSettings(BMessage& configuration);
|
status_t GetDefaultSettings(BMessage& configuration);
|
||||||
@@ -80,10 +83,9 @@ public:
|
|||||||
Resource* GetResource() { return fResource; }
|
Resource* GetResource() { return fResource; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t LoadPrinterAddon(image_id& id);
|
status_t GetDriverName(BString* name);
|
||||||
void AddCurrentPrinter(BMessage& message);
|
void AddCurrentPrinter(BMessage& message);
|
||||||
|
|
||||||
// Accessor
|
|
||||||
BDirectory* SpoolDir() { return fPrinter.GetSpoolDir(); }
|
BDirectory* SpoolDir() { return fPrinter.GetSpoolDir(); }
|
||||||
|
|
||||||
void ResetJobStatus();
|
void ResetJobStatus();
|
||||||
|
|||||||
@@ -0,0 +1,190 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2001-2010, Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Ithamar R. Adema
|
||||||
|
* Michael Pfeiffer
|
||||||
|
*/
|
||||||
|
#include "PrinterDriverAddOn.h"
|
||||||
|
|
||||||
|
#include "BeUtils.h"
|
||||||
|
#include "pr_server.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef BMessage* (*config_func_t)(BNode*, const BMessage*);
|
||||||
|
typedef BMessage* (*take_job_func_t)(BFile*, BNode*, const BMessage*);
|
||||||
|
typedef char* (*add_printer_func_t)(const char* printer_name);
|
||||||
|
typedef BMessage* (*default_settings_t)(BNode*);
|
||||||
|
|
||||||
|
static const char* kPrinterDriverFolderName = "Print";
|
||||||
|
|
||||||
|
|
||||||
|
PrinterDriverAddOn::PrinterDriverAddOn(const char* driver)
|
||||||
|
: fAddOnID(-1)
|
||||||
|
{
|
||||||
|
BPath path;
|
||||||
|
status_t result;
|
||||||
|
result = FindPathToDriver(driver, &path);
|
||||||
|
if (result != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fAddOnID = ::load_add_on(path.Path());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PrinterDriverAddOn::~PrinterDriverAddOn()
|
||||||
|
{
|
||||||
|
if (IsLoaded()) {
|
||||||
|
unload_add_on(fAddOnID);
|
||||||
|
fAddOnID = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
PrinterDriverAddOn::AddPrinter(const char* spoolFolderName)
|
||||||
|
{
|
||||||
|
if (!IsLoaded())
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
add_printer_func_t func;
|
||||||
|
status_t result = get_image_symbol(fAddOnID, "add_printer",
|
||||||
|
B_SYMBOL_TYPE_TEXT, (void**)&func);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if ((*func)(spoolFolderName) == NULL)
|
||||||
|
return B_ERROR;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
PrinterDriverAddOn::ConfigPage(BDirectory* spoolFolder, BMessage* settings)
|
||||||
|
{
|
||||||
|
if (!IsLoaded())
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
config_func_t func;
|
||||||
|
status_t result = get_image_symbol(fAddOnID, "config_page",
|
||||||
|
B_SYMBOL_TYPE_TEXT, (void**)&func);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
BMessage* newSettings = (*func)(spoolFolder, settings);
|
||||||
|
result = CopyValidSettings(settings, newSettings);
|
||||||
|
delete newSettings;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
PrinterDriverAddOn::ConfigJob(BDirectory* spoolFolder, BMessage* settings)
|
||||||
|
{
|
||||||
|
if (!IsLoaded())
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
config_func_t func;
|
||||||
|
status_t result = get_image_symbol(fAddOnID, "config_job",
|
||||||
|
B_SYMBOL_TYPE_TEXT, (void**)&func);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
BMessage* newSettings = (*func)(spoolFolder, settings);
|
||||||
|
result = CopyValidSettings(settings, newSettings);
|
||||||
|
delete newSettings;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
PrinterDriverAddOn::DefaultSettings(BDirectory* spoolFolder, BMessage* settings)
|
||||||
|
{
|
||||||
|
if (!IsLoaded())
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
default_settings_t func;
|
||||||
|
status_t result = get_image_symbol(fAddOnID, "default_settings",
|
||||||
|
B_SYMBOL_TYPE_TEXT, (void**)&func);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
BMessage* newSettings = (*func)(spoolFolder);
|
||||||
|
if (newSettings != NULL) {
|
||||||
|
*settings = *newSettings;
|
||||||
|
settings->what = 'okok';
|
||||||
|
} else
|
||||||
|
result = B_ERROR;
|
||||||
|
delete newSettings;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
PrinterDriverAddOn::TakeJob(BFile* spoolFile, BDirectory* spoolFolder)
|
||||||
|
{
|
||||||
|
if (!IsLoaded())
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
take_job_func_t func;
|
||||||
|
status_t result = get_image_symbol(fAddOnID, "take_job", B_SYMBOL_TYPE_TEXT,
|
||||||
|
(void**)&func);
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
// This seems to be required for legacy?
|
||||||
|
// HP PCL3 add-on crashes without it!
|
||||||
|
BMessage parameters(B_REFS_RECEIVED);
|
||||||
|
parameters.AddInt32("file", (int32)spoolFile);
|
||||||
|
parameters.AddInt32("printer", (int32)spoolFolder);
|
||||||
|
|
||||||
|
BMessage* message = (*func)(spoolFile, spoolFolder, ¶meters);
|
||||||
|
if (message == NULL || message->what != 'okok')
|
||||||
|
result = B_ERROR;
|
||||||
|
delete message;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
PrinterDriverAddOn::FindPathToDriver(const char* driver, BPath* path)
|
||||||
|
{
|
||||||
|
status_t result;
|
||||||
|
result = ::TestForAddonExistence(driver, B_USER_ADDONS_DIRECTORY,
|
||||||
|
kPrinterDriverFolderName, *path);
|
||||||
|
if (result == B_OK)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
result = ::TestForAddonExistence(driver, B_COMMON_ADDONS_DIRECTORY,
|
||||||
|
kPrinterDriverFolderName, *path);
|
||||||
|
if (result == B_OK)
|
||||||
|
return B_OK;
|
||||||
|
|
||||||
|
result = ::TestForAddonExistence(driver, B_BEOS_ADDONS_DIRECTORY,
|
||||||
|
kPrinterDriverFolderName, *path);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
PrinterDriverAddOn::IsLoaded() const
|
||||||
|
{
|
||||||
|
return fAddOnID > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
PrinterDriverAddOn::CopyValidSettings(BMessage* settings, BMessage* newSettings)
|
||||||
|
{
|
||||||
|
if (newSettings != NULL && newSettings->what != 'baad') {
|
||||||
|
*settings = *newSettings;
|
||||||
|
settings->what = 'okok';
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2001-2010, Haiku, Inc. All rights reserved.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Ithamar R. Adema
|
||||||
|
* Michael Pfeiffer
|
||||||
|
*/
|
||||||
|
#ifndef PRINTER_DRIVER_ADD_ON_H
|
||||||
|
#define PRINTER_DRIVER_ADD_ON_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <Directory.h>
|
||||||
|
#include <File.h>
|
||||||
|
#include <image.h>
|
||||||
|
#include <Message.h>
|
||||||
|
#include <Path.h>
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
class PrinterDriverAddOn
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PrinterDriverAddOn(const char* driver);
|
||||||
|
~PrinterDriverAddOn();
|
||||||
|
|
||||||
|
status_t AddPrinter(const char* spoolFolderName);
|
||||||
|
status_t ConfigPage(BDirectory* spoolFolder,
|
||||||
|
BMessage* settings);
|
||||||
|
status_t ConfigJob(BDirectory* spoolFolder,
|
||||||
|
BMessage* settings);
|
||||||
|
status_t DefaultSettings(BDirectory* spoolFolder,
|
||||||
|
BMessage* settings);
|
||||||
|
status_t TakeJob(BFile* spoolFile,
|
||||||
|
BDirectory* spoolFolder);
|
||||||
|
|
||||||
|
static status_t FindPathToDriver(const char* driver, BPath* path);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool IsLoaded() const;
|
||||||
|
status_t CopyValidSettings(BMessage* settings,
|
||||||
|
BMessage* newSettings);
|
||||||
|
|
||||||
|
image_id fAddOnID;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user