* Added application print_server_add_on that is used
by the print_server to run a printer driver add-on.
This makes the print_server
1) resistant to add-on crashes
2) and memory leaks in add-ons
3) license of an add-on cannot influence the
license of the print_server since it does not
directly load the add-on anymore; might be
an issue with GPL printer drivers like Gutenprint
Transport add-ons directly loaded by the print_server
should be moved outside the print_server too.
Right now I am not aware that the transport add-ons
in the repository have any of the issues.
The Gutenprint driver has 2 + 3 that was the main
motivation to implement that now.
Disabled for now until the launch issue is resolved.
BRoster does not find the application by its
signature until it is opened in Tracker once.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39346 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -47,7 +47,7 @@ SYSTEM_BIN = "[" addattr alert arp base64 basename bash bc beep bootman bzip2
|
||||
netcat netstat nl nohup notify nproc
|
||||
od open
|
||||
passwd paste patch pathchk pc ping ping6 play playfile playsound playwav
|
||||
pr prio printenv printf profile ps ptx pwd
|
||||
pr prio printenv printf print_server_add_on profile ps ptx pwd
|
||||
query quit
|
||||
rc readlink ReadOnlyBootPrompt reindex release renice rlog rm rmattr
|
||||
rmindex rmdir roster route
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2010 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Pfeiffer
|
||||
*/
|
||||
#ifndef PRINT_SERVER_ADD_ON_H
|
||||
#define PRINT_SERVER_ADD_ON_H
|
||||
|
||||
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <Message.h>
|
||||
#include <Messenger.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
class PrintServerAddOn
|
||||
{
|
||||
public:
|
||||
PrintServerAddOn(const char* driver);
|
||||
virtual ~PrintServerAddOn();
|
||||
|
||||
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(const char* spoolFile,
|
||||
BDirectory* spoolFolder);
|
||||
|
||||
static status_t FindPathToDriver(const char* driver, BPath* path);
|
||||
|
||||
private:
|
||||
const char* Driver() const;
|
||||
|
||||
status_t Launch(BMessenger& messenger);
|
||||
bool IsLaunched();
|
||||
void Quit();
|
||||
|
||||
void AddDirectory(BMessage& message, const char* name,
|
||||
BDirectory* directory);
|
||||
void AddEntryRef(BMessage& message, const char* name,
|
||||
const entry_ref* entryRef);
|
||||
status_t SendRequest(BMessage& request, BMessage& reply);
|
||||
status_t GetResult(BMessage& reply);
|
||||
status_t GetResultAndUpdateSettings(BMessage& reply,
|
||||
BMessage* settings);
|
||||
|
||||
BString fDriver;
|
||||
status_t fLaunchStatus;
|
||||
BMessenger fMessenger;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2010 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Pfeiffer
|
||||
*/
|
||||
#ifndef PRINT_SERVER_ADD_ON_PROTOCOL_H
|
||||
#define PRINT_SERVER_ADD_ON_PROTOCOL_H
|
||||
|
||||
extern const char* kPrintServerAddOnApplicationSignature;
|
||||
|
||||
extern const char* kPrintServerAddOnStatusAttribute;
|
||||
extern const char* kPrinterDriverAttribute;
|
||||
extern const char* kPrinterNameAttribute;
|
||||
extern const char* kPrinterFolderAttribute;
|
||||
extern const char* kPrintJobFileAttribute;
|
||||
extern const char* kPrintSettingsAttribute;
|
||||
|
||||
enum {
|
||||
// message constants for the five corresponding
|
||||
// printer driver add-on hook functions
|
||||
kMessageAddPrinter = 'PSad',
|
||||
// Request:
|
||||
// BString kPrinterDriverAttribute
|
||||
// BString kPrinterNameAttribute
|
||||
// Reply:
|
||||
// int32 kPrintServerAddOnStatusAttribute
|
||||
|
||||
kMessageConfigPage = 'PScp',
|
||||
// Request:
|
||||
// BString kPrinterDriverAttribute
|
||||
// BString kPrinterFolderAttribute
|
||||
// BMessage kPrintSettingsAttribute
|
||||
// Reply:
|
||||
// int32 kPrintServerAddOnStatusAttribute
|
||||
// BMessage kPrintSettingsAttribute (if status is B_OK)
|
||||
|
||||
kMessageConfigJob = 'PScj',
|
||||
// Request:
|
||||
// BString kPrinterDriverAttribute
|
||||
// BString kPrinterFolderAttribute
|
||||
// BMessage kPrintSettingsAttribute
|
||||
// Reply:
|
||||
// int32 kPrintServerAddOnStatusAttribute
|
||||
// BMessage kPrintSettingsAttribute (if status is B_OK)
|
||||
|
||||
kMessageDefaultSettings = 'PSds',
|
||||
// Request:
|
||||
// BString kPrinterDriverAttribute
|
||||
// BString kPrinterFolderAttribute
|
||||
// Reply:
|
||||
// int32 kPrintServerAddOnStatusAttribute
|
||||
// BMessage kPrintSettingsAttribute (if status is B_OK)
|
||||
|
||||
kMessageTakeJob = 'PStj',
|
||||
// Request:
|
||||
// BString kPrinterDriverAttribute
|
||||
// BString kPrintJobFileAttribute
|
||||
// BString kPrinterFolderAttribute
|
||||
// Reply:
|
||||
// int32 kPrintServerAddOnStatusAttribute
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
|
||||
#include <Directory.h>
|
||||
#include <File.h>
|
||||
#include <image.h>
|
||||
#include <Message.h>
|
||||
#include <Path.h>
|
||||
@@ -31,7 +30,7 @@ public:
|
||||
BMessage* settings);
|
||||
status_t DefaultSettings(BDirectory* spoolFolder,
|
||||
BMessage* settings);
|
||||
status_t TakeJob(BFile* spoolFile,
|
||||
status_t TakeJob(const char* spoolFile,
|
||||
BDirectory* spoolFolder);
|
||||
|
||||
static status_t FindPathToDriver(const char* driver, BPath* path);
|
||||
@@ -259,6 +259,7 @@ SubInclude HAIKU_TOP src bin patch ;
|
||||
SubInclude HAIKU_TOP src bin pc ;
|
||||
SubInclude HAIKU_TOP src bin pcmcia-cs ;
|
||||
SubInclude HAIKU_TOP src bin playsound ;
|
||||
SubInclude HAIKU_TOP src bin printserveraddon ;
|
||||
SubInclude HAIKU_TOP src bin rc ;
|
||||
SubInclude HAIKU_TOP src bin rmd160 ;
|
||||
SubInclude HAIKU_TOP src bin screen_blanker ;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
SubDir HAIKU_TOP src bin printserveraddon ;
|
||||
|
||||
UsePrivateHeaders shared print ;
|
||||
|
||||
AddResources print_server_add_on :
|
||||
print_server_add_on.rdef
|
||||
;
|
||||
|
||||
Application print_server_add_on :
|
||||
PrintServerAddOnApplication.cpp
|
||||
;
|
||||
|
||||
LinkAgainst print_server_add_on :
|
||||
be
|
||||
root
|
||||
libprintutils.a
|
||||
$(HAIKU_LOCALE_LIBS)
|
||||
$(TARGET_LIBSUPC++)
|
||||
;
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Copyright 2010 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Pfeiffer
|
||||
*/
|
||||
#include "PrintServerAddOnApplication.h"
|
||||
|
||||
#include <PrinterDriverAddOn.h>
|
||||
|
||||
#include <String.h>
|
||||
|
||||
PrintServerAddOnApplication::PrintServerAddOnApplication(const char* signature)
|
||||
:
|
||||
BApplication(signature)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOnApplication::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case kMessageAddPrinter:
|
||||
AddPrinter(message);
|
||||
break;
|
||||
|
||||
case kMessageConfigPage:
|
||||
ConfigPage(message);
|
||||
break;
|
||||
|
||||
case kMessageConfigJob:
|
||||
ConfigJob(message);
|
||||
break;
|
||||
|
||||
case kMessageDefaultSettings:
|
||||
DefaultSettings(message);
|
||||
break;
|
||||
|
||||
case kMessageTakeJob:
|
||||
TakeJob(message);
|
||||
break;
|
||||
|
||||
default:
|
||||
BApplication::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOnApplication::AddPrinter(BMessage* message)
|
||||
{
|
||||
BString driver;
|
||||
BString name;
|
||||
if (message->FindString(kPrinterDriverAttribute, &driver) != B_OK
|
||||
|| message->FindString(kPrinterNameAttribute, &name) != B_OK) {
|
||||
SendReply(message, B_BAD_VALUE);
|
||||
return;
|
||||
}
|
||||
|
||||
status_t status = AddPrinter(driver.String(), name.String());
|
||||
SendReply(message, status);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOnApplication::AddPrinter(const char* driver,
|
||||
const char* spoolFolderName)
|
||||
{
|
||||
PrinterDriverAddOn addOn(driver);
|
||||
return addOn.AddPrinter(spoolFolderName);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOnApplication::ConfigPage(BMessage* message)
|
||||
{
|
||||
BString driver;
|
||||
BString folder;
|
||||
BMessage settings;
|
||||
if (message->FindString(kPrinterDriverAttribute, &driver) != B_OK
|
||||
|| message->FindString(kPrinterFolderAttribute, &folder) != B_OK
|
||||
|| message->FindMessage(kPrintSettingsAttribute, &settings) != B_OK) {
|
||||
SendReply(message, B_BAD_VALUE);
|
||||
return;
|
||||
}
|
||||
|
||||
BDirectory spoolFolder(folder.String());
|
||||
status_t status = ConfigPage(driver.String(), &spoolFolder, &settings);
|
||||
|
||||
if (status != B_OK)
|
||||
SendReply(message, status);
|
||||
else {
|
||||
BMessage reply(B_REPLY);
|
||||
reply.AddMessage(kPrintSettingsAttribute, &settings);
|
||||
SendReply(message, &reply);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOnApplication::ConfigPage(const char* driver,
|
||||
BDirectory* spoolFolder, BMessage* settings)
|
||||
{
|
||||
PrinterDriverAddOn addOn(driver);
|
||||
return addOn.ConfigPage(spoolFolder, settings);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOnApplication::ConfigJob(BMessage* message)
|
||||
{
|
||||
BString driver;
|
||||
BString folder;
|
||||
BMessage settings;
|
||||
if (message->FindString(kPrinterDriverAttribute, &driver) != B_OK
|
||||
|| message->FindString(kPrinterFolderAttribute, &folder) != B_OK
|
||||
|| message->FindMessage(kPrintSettingsAttribute, &settings) != B_OK) {
|
||||
SendReply(message, B_BAD_VALUE);
|
||||
return;
|
||||
}
|
||||
|
||||
BDirectory spoolFolder(folder.String());
|
||||
status_t status = ConfigJob(driver.String(), &spoolFolder, &settings);
|
||||
|
||||
if (status != B_OK)
|
||||
SendReply(message, status);
|
||||
else {
|
||||
BMessage reply(B_REPLY);
|
||||
reply.AddMessage(kPrintSettingsAttribute, &settings);
|
||||
SendReply(message, &reply);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOnApplication::ConfigJob(const char* driver,
|
||||
BDirectory* spoolFolder,
|
||||
BMessage* settings)
|
||||
{
|
||||
PrinterDriverAddOn addOn(driver);
|
||||
return addOn.ConfigJob(spoolFolder, settings);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOnApplication::DefaultSettings(BMessage* message)
|
||||
{
|
||||
BString driver;
|
||||
BString folder;
|
||||
if (message->FindString(kPrinterDriverAttribute, &driver) != B_OK
|
||||
|| message->FindString(kPrinterFolderAttribute, &folder) != B_OK) {
|
||||
SendReply(message, B_BAD_VALUE);
|
||||
return;
|
||||
}
|
||||
|
||||
BMessage settings;
|
||||
BDirectory spoolFolder(folder.String());
|
||||
status_t status = DefaultSettings(driver.String(), &spoolFolder, &settings);
|
||||
|
||||
if (status != B_OK)
|
||||
SendReply(message, status);
|
||||
else {
|
||||
BMessage reply(B_REPLY);
|
||||
reply.AddMessage(kPrintSettingsAttribute, &settings);
|
||||
SendReply(message, &reply);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOnApplication::DefaultSettings(const char* driver,
|
||||
BDirectory* spoolFolder, BMessage* settings)
|
||||
{
|
||||
PrinterDriverAddOn addOn(driver);
|
||||
return addOn.DefaultSettings(spoolFolder, settings);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOnApplication::TakeJob(BMessage* message)
|
||||
{
|
||||
BString driver;
|
||||
BString folder;
|
||||
BString jobFile;
|
||||
if (message->FindString(kPrinterDriverAttribute, &driver) != B_OK
|
||||
|| message->FindString(kPrinterFolderAttribute, &folder) != B_OK
|
||||
|| message->FindString(kPrintJobFileAttribute, &jobFile) != B_OK) {
|
||||
SendReply(message, B_BAD_VALUE);
|
||||
return;
|
||||
}
|
||||
|
||||
BDirectory spoolFolder(folder.String());
|
||||
status_t status = TakeJob(driver.String(), jobFile.String(),
|
||||
&spoolFolder);
|
||||
SendReply(message, status);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOnApplication::TakeJob(const char* driver, const char* spoolFile,
|
||||
BDirectory* spoolFolder)
|
||||
{
|
||||
PrinterDriverAddOn addOn(driver);
|
||||
return addOn.TakeJob(spoolFile, spoolFolder);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOnApplication::SendReply(BMessage* message, status_t status)
|
||||
{
|
||||
BMessage reply(B_REPLY);
|
||||
reply.AddInt32(kPrintServerAddOnStatusAttribute, status);
|
||||
message->SendReply(&reply);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOnApplication::SendReply(BMessage* message, BMessage* reply)
|
||||
{
|
||||
reply->AddInt32(kPrintServerAddOnStatusAttribute, B_OK);
|
||||
message->SendReply(reply);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
PrintServerAddOnApplication application(
|
||||
kPrintServerAddOnApplicationSignature);
|
||||
application.Run();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Michael Pfeiffer
|
||||
*/
|
||||
#ifndef PRINT_SERVER_ADD_ON_H
|
||||
#define PRINT_SERVER_ADD_ON_H
|
||||
|
||||
#include <Application.h>
|
||||
#include <Directory.h>
|
||||
#include <File.h>
|
||||
#include <Message.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
#include <PrintServerAddOnProtocol.h>
|
||||
|
||||
|
||||
class PrintServerAddOnApplication : public BApplication
|
||||
{
|
||||
public:
|
||||
PrintServerAddOnApplication(const char* signature);
|
||||
void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
void AddPrinter(BMessage* message);
|
||||
status_t AddPrinter(const char* driver,
|
||||
const char* spoolFolderName);
|
||||
|
||||
void ConfigPage(BMessage* message);
|
||||
status_t ConfigPage(const char* driver,
|
||||
BDirectory* spoolFolder,
|
||||
BMessage* settings);
|
||||
|
||||
void ConfigJob(BMessage* message);
|
||||
status_t ConfigJob(const char* driver,
|
||||
BDirectory* spoolFolder,
|
||||
BMessage* settings);
|
||||
|
||||
void DefaultSettings(BMessage* message);
|
||||
status_t DefaultSettings(const char* driver,
|
||||
BDirectory* spoolFolder,
|
||||
BMessage* settings);
|
||||
|
||||
void TakeJob(BMessage* message);
|
||||
status_t TakeJob(const char* driver,
|
||||
const char* spoolFile,
|
||||
BDirectory* spoolFolder);
|
||||
|
||||
void SendReply(BMessage* message, status_t status);
|
||||
void SendReply(BMessage* message, BMessage* reply);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,65 @@
|
||||
|
||||
resource app_signature "application/x-vnd.haiku-print-server-add-on";
|
||||
|
||||
resource app_version {
|
||||
major = 1,
|
||||
middle = 0,
|
||||
minor = 0,
|
||||
|
||||
variety = B_APPV_BETA,
|
||||
internal = 0,
|
||||
|
||||
short_info = "print_server_add_on",
|
||||
long_info = "print_server_add_on ©2010 Haiku"
|
||||
};
|
||||
|
||||
resource app_flags B_MULTIPLE_LAUNCH | B_BACKGROUND_APP;
|
||||
|
||||
resource vector_icon {
|
||||
$"6E636966160500020016023A3D24339506B715A93DDB134A79084A1A1100D7FF"
|
||||
$"B80594020016023A3D24339506B715A93DDB134A79084A1A1100D2FF8505C402"
|
||||
$"0016023A692E36692FBA2ECD3E2ECC4B89A4496318005CFF83020016023C8000"
|
||||
$"0000000000003C00004AC00049000000F4FFDB03A9FF00020106033C00000000"
|
||||
$"000000003C00004680004680000B9EEDFF2567CEFFFF0473B3020106033C0000"
|
||||
$"0000000000003C000046800046800000B9FF97BE05D65EFF04994304016E0500"
|
||||
$"02001602B76E71BBF8593D1210B8A7674742A04ABEFB00AEFFE1053802001603"
|
||||
$"373333B9333339333337333348E54F4B555400FFBFE5FF9B0200160336C6F3B9"
|
||||
$"284239E397376BB94A71BE484A25005346B5FFFF02001602B500003A6000BA60"
|
||||
$"00B500004A2E244AB9D001C0FF9A020116023AA41339C70ABC27003D026E4ACA"
|
||||
$"B74AC8AB0183FFAD020106023600000000000000003700004A10004AB0000035"
|
||||
$"FF06FB1E9303020106023600000000000000003700004A10004AB00000FFE3E3"
|
||||
$"FFDD05050101000073020116023E1E41BC9E393B21B93C88A64824E3485D8500"
|
||||
$"90FF3C150A044C60516060505C4E0A0651365A395A504C5E425842400A084C44"
|
||||
$"4C5EC3AECB26C3AEC72A4450C159C9CB425842400A04C1EFC6634450C159C9CB"
|
||||
$"C1DDCA180A04C317C6E8C1EFC663C1DDCA18C315CACE0A04C3AECB26C3AEC72A"
|
||||
$"C317C6E8C315CACE0A0451365A394C4442400A044C445A395A504C5E0A044846"
|
||||
$"48484AC3234AC2570404BE404A3246324A323E4236423C423237320606BE023A"
|
||||
$"5F485C46584C5E5656525A5656604C58483A0608EFB6302E302E25372248223A"
|
||||
$"2248465A4A59485B4A59584B41573E583F563D543C0608AAFF503A4E3C323134"
|
||||
$"2F302E302E25372248223A2248465A465A464C543C4A46543C0205573E583F56"
|
||||
$"3D543C543C4A46465A464C465A4A59485B4A4F5841523F584106033B4A594A4F"
|
||||
$"4A59584B58415841523F0A04264842564252264406057A0322513A5E42543C58"
|
||||
$"425452B77BC261B77BC261254A0802285038580A06542A3C22353135324C3B4C"
|
||||
$"3A0202404A3E4C4248434D454B414F020332332B3332334B3E4B3E453E354744"
|
||||
$"4E26401B0A0A0109124000000000000000003FB6DB4200004324920117840004"
|
||||
$"0A0001091001178400040A0A0100023F48D60000000000003F48D6C928D6C7DD"
|
||||
$"690A000101123F48D60000000000003F48D6C938D6C7E56901178500040A0101"
|
||||
$"02023F48D60000000000003F48D6C938D6C7E5690A020103023F48D600000000"
|
||||
$"00003F48D6C938D6C7E5690A030104023F48D60000000000003F48D6C938D6C7"
|
||||
$"E5690A040105023F48D60000000000003F48D6C938D6C7E5690A060106023F48"
|
||||
$"D60000000000003F48D6C938D6C7E5690A050107023F48D60000000000003F48"
|
||||
$"D6C938D6C7E5690A030108123F48D60000000000003F48D6C938D6C7E5690117"
|
||||
$"8100040A070108023F48D60000000000003F48D6C938D6C7E5690A14010A023E"
|
||||
$"932D0000000000003E932D48D9A548A3D70A0B030B1012123E932D0000000000"
|
||||
$"003E932D48D9A548A3D701178600040A0C010C023E932D0000000000003E932D"
|
||||
$"48D9A548A3D70A0B010F123E932D0000000000003E932D48D9A548A3D7011782"
|
||||
$"00040A0D010F023E932D0000000000003E932D48D9A548A3D70A0E0110023E93"
|
||||
$"2D0000000000003E932D48D9A548A3D70A0F0112023E932D0000000000003E93"
|
||||
$"2D48D9A548A3D70A10010D023E932D0000000000003E932D48D9A548A3D70A11"
|
||||
$"010E023E932D0000000000003E932D48D9A548A3D70A130113023E932D000000"
|
||||
$"0000003E932D4940A54851710A120113023E932D0000000000003E932D4902D8"
|
||||
$"48B8700A0B0111123E932D0000000000003E932D492C0B48517101178100040A"
|
||||
$"0B0111123E932D0000000000003E932D4902D8487AA401178100040A0B01111A"
|
||||
$"3E932D0000000000003E932D48D9A548A3D715FF01178100040A150114023E93"
|
||||
$"2D0000000000003E932D48D9A548A3D7"
|
||||
};
|
||||
@@ -9,7 +9,10 @@ StaticLibrary libprintutils.a :
|
||||
BeUtilsTranslation.cpp
|
||||
FolderWatcher.cpp
|
||||
Jobs.cpp
|
||||
PicturePrinter.cpp
|
||||
PrintTransport.cpp
|
||||
PictureIterator.cpp
|
||||
PicturePrinter.cpp
|
||||
PrinterDriverAddOn.cpp
|
||||
PrintTransport.cpp
|
||||
PrintServerAddOn.cpp
|
||||
PrintServerAddOnProtocol.cpp
|
||||
;
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
#include "PrintServerAddOn.h"
|
||||
|
||||
#include <Entry.h>
|
||||
#include <Roster.h>
|
||||
|
||||
#include "PrinterDriverAddOn.h"
|
||||
#include "PrintServerAddOnProtocol.h"
|
||||
|
||||
static const bigtime_t kSeconds = 1000000L;
|
||||
static const bigtime_t kDeliveryTimeout = 30 * kSeconds;
|
||||
static const bigtime_t kReplyTimeout = B_INFINITE_TIMEOUT;
|
||||
|
||||
|
||||
PrintServerAddOn::PrintServerAddOn(const char* driver)
|
||||
:
|
||||
fDriver(driver)
|
||||
{
|
||||
fLaunchStatus = Launch(fMessenger);
|
||||
}
|
||||
|
||||
|
||||
PrintServerAddOn::~PrintServerAddOn()
|
||||
{
|
||||
if (fLaunchStatus == B_OK)
|
||||
Quit();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOn::AddPrinter(const char* spoolFolderName)
|
||||
{
|
||||
BMessage message(kMessageAddPrinter);
|
||||
message.AddString(kPrinterDriverAttribute, Driver());
|
||||
message.AddString(kPrinterNameAttribute, spoolFolderName);
|
||||
|
||||
BMessage reply;
|
||||
status_t result = SendRequest(message, reply);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
return GetResult(reply);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOn::ConfigPage(BDirectory* spoolFolder,
|
||||
BMessage* settings)
|
||||
{
|
||||
BMessage message(kMessageConfigPage);
|
||||
message.AddString(kPrinterDriverAttribute, Driver());
|
||||
AddDirectory(message, kPrinterFolderAttribute, spoolFolder);
|
||||
message.AddMessage(kPrintSettingsAttribute, settings);
|
||||
|
||||
BMessage reply;
|
||||
status_t result = SendRequest(message, reply);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
return GetResultAndUpdateSettings(reply, settings);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOn::ConfigJob(BDirectory* spoolFolder,
|
||||
BMessage* settings)
|
||||
{
|
||||
BMessage message(kMessageConfigJob);
|
||||
message.AddString(kPrinterDriverAttribute, Driver());
|
||||
AddDirectory(message, kPrinterFolderAttribute, spoolFolder);
|
||||
message.AddMessage(kPrintSettingsAttribute, settings);
|
||||
|
||||
BMessage reply;
|
||||
status_t result = SendRequest(message, reply);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
return GetResultAndUpdateSettings(reply, settings);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOn::DefaultSettings(BDirectory* spoolFolder,
|
||||
BMessage* settings)
|
||||
{
|
||||
BMessage message(kMessageDefaultSettings);
|
||||
message.AddString(kPrinterDriverAttribute, Driver());
|
||||
AddDirectory(message, kPrinterFolderAttribute, spoolFolder);
|
||||
|
||||
BMessage reply;
|
||||
status_t result = SendRequest(message, reply);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
return GetResultAndUpdateSettings(reply, settings);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOn::TakeJob(const char* spoolFile,
|
||||
BDirectory* spoolFolder)
|
||||
{
|
||||
BMessage message(kMessageTakeJob);
|
||||
message.AddString(kPrinterDriverAttribute, Driver());
|
||||
message.AddString(kPrintJobFileAttribute, spoolFile);
|
||||
AddDirectory(message, kPrinterFolderAttribute, spoolFolder);
|
||||
|
||||
BMessage reply;
|
||||
status_t result = SendRequest(message, reply);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
return GetResult(reply);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOn::FindPathToDriver(const char* driver, BPath* path)
|
||||
{
|
||||
return PrinterDriverAddOn::FindPathToDriver(driver, path);
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
PrintServerAddOn::Driver() const
|
||||
{
|
||||
return fDriver.String();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOn::Launch(BMessenger& messenger)
|
||||
{
|
||||
team_id team;
|
||||
status_t result =
|
||||
be_roster->Launch(kPrintServerAddOnApplicationSignature,
|
||||
(BMessage*)NULL, &team);
|
||||
if (result != B_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
fMessenger = BMessenger(kPrintServerAddOnApplicationSignature, team);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
PrintServerAddOn::IsLaunched()
|
||||
{
|
||||
return fLaunchStatus == B_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOn::Quit()
|
||||
{
|
||||
if (fLaunchStatus == B_OK) {
|
||||
fMessenger.SendMessage(B_QUIT_REQUESTED);
|
||||
fLaunchStatus = B_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOn::AddDirectory(BMessage& message, const char* name,
|
||||
BDirectory* directory)
|
||||
{
|
||||
BEntry entry;
|
||||
status_t result = directory->GetEntry(&entry);
|
||||
if (result != B_OK)
|
||||
return;
|
||||
|
||||
BPath path;
|
||||
if (entry.GetPath(&path) != B_OK)
|
||||
return;
|
||||
|
||||
message.AddString(name, path.Path());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PrintServerAddOn::AddEntryRef(BMessage& message, const char* name,
|
||||
const entry_ref* entryRef)
|
||||
{
|
||||
BPath path(entryRef);
|
||||
if (path.InitCheck() != B_OK)
|
||||
return;
|
||||
|
||||
message.AddString(name, path.Path());
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOn::SendRequest(BMessage& request, BMessage& reply)
|
||||
{
|
||||
if (!IsLaunched())
|
||||
return fLaunchStatus;
|
||||
|
||||
return fMessenger.SendMessage(&request, &reply, kDeliveryTimeout,
|
||||
kReplyTimeout);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOn::GetResult(BMessage& reply)
|
||||
{
|
||||
int32 status;
|
||||
status_t result = reply.FindInt32(kPrintServerAddOnStatusAttribute,
|
||||
&status);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
return static_cast<status_t>(status);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
PrintServerAddOn::GetResultAndUpdateSettings(BMessage& reply, BMessage* settings)
|
||||
{
|
||||
BMessage newSettings;
|
||||
if (reply.FindMessage(kPrintSettingsAttribute, &newSettings) == B_OK)
|
||||
*settings = newSettings;
|
||||
|
||||
settings->PrintToStream();
|
||||
|
||||
return GetResult(reply);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "PrintServerAddOnProtocol.h"
|
||||
|
||||
const char* kPrintServerAddOnApplicationSignature =
|
||||
"application/x-vnd.haiku-print-server-add-on";
|
||||
|
||||
const char* kPrintServerAddOnStatusAttribute = "status";
|
||||
const char* kPrinterDriverAttribute = "driver";
|
||||
const char* kPrinterNameAttribute = "name";
|
||||
const char* kPrinterFolderAttribute = "folder";
|
||||
const char* kPrintJobFileAttribute = "job";
|
||||
const char* kPrintSettingsAttribute = "settings";
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
#include "PrinterDriverAddOn.h"
|
||||
|
||||
#include <File.h>
|
||||
|
||||
#include "BeUtils.h"
|
||||
#include "pr_server.h"
|
||||
|
||||
@@ -21,7 +23,8 @@ static const char* kPrinterDriverFolderName = "Print";
|
||||
|
||||
|
||||
PrinterDriverAddOn::PrinterDriverAddOn(const char* driver)
|
||||
: fAddOnID(-1)
|
||||
:
|
||||
fAddOnID(-1)
|
||||
{
|
||||
BPath path;
|
||||
status_t result;
|
||||
@@ -125,11 +128,12 @@ PrinterDriverAddOn::DefaultSettings(BDirectory* spoolFolder, BMessage* settings)
|
||||
|
||||
|
||||
status_t
|
||||
PrinterDriverAddOn::TakeJob(BFile* spoolFile, BDirectory* spoolFolder)
|
||||
PrinterDriverAddOn::TakeJob(const char* spoolFile, BDirectory* spoolFolder)
|
||||
{
|
||||
if (!IsLoaded())
|
||||
return B_ERROR;
|
||||
|
||||
BFile file(spoolFile, B_READ_WRITE);
|
||||
take_job_func_t func;
|
||||
status_t result = get_image_symbol(fAddOnID, "take_job", B_SYMBOL_TYPE_TEXT,
|
||||
(void**)&func);
|
||||
@@ -139,10 +143,10 @@ PrinterDriverAddOn::TakeJob(BFile* spoolFile, BDirectory* spoolFolder)
|
||||
// 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("file", (int32)&file);
|
||||
parameters.AddInt32("printer", (int32)spoolFolder);
|
||||
|
||||
BMessage* message = (*func)(spoolFile, spoolFolder, ¶meters);
|
||||
BMessage* message = (*func)(&file, spoolFolder, ¶meters);
|
||||
if (message == NULL || message->what != 'okok')
|
||||
result = B_ERROR;
|
||||
delete message;
|
||||
@@ -8,7 +8,6 @@ AddResources print_server :
|
||||
;
|
||||
|
||||
Server print_server :
|
||||
PrinterDriverAddOn.cpp
|
||||
PrintServerApp.cpp
|
||||
PrintServerApp.R5.cpp
|
||||
PrintServerApp.Scripting.cpp
|
||||
|
||||
@@ -10,7 +10,13 @@
|
||||
|
||||
#include "BeUtils.h"
|
||||
#include "pr_server.h"
|
||||
#include "PrinterDriverAddOn.h"
|
||||
// TODO enable when issue launching print_server_add_on is resolved
|
||||
#if 0
|
||||
# include "PrintServerAddOn.h"
|
||||
#else
|
||||
# include "PrinterDriverAddOn.h"
|
||||
# define PrintServerAddOn PrinterDriverAddOn
|
||||
#endif
|
||||
#include "PrintServerApp.h"
|
||||
|
||||
// posix
|
||||
@@ -180,7 +186,7 @@ status_t Printer::Remove()
|
||||
status_t
|
||||
Printer::FindPathToDriver(const char* driverName, BPath* path)
|
||||
{
|
||||
return PrinterDriverAddOn::FindPathToDriver(driverName, path);
|
||||
return PrintServerAddOn::FindPathToDriver(driverName, path);
|
||||
}
|
||||
|
||||
|
||||
@@ -199,7 +205,7 @@ Printer::FindPathToDriver(const char* driverName, BPath* path)
|
||||
status_t Printer::ConfigurePrinter(const char* driverName,
|
||||
const char* printerName)
|
||||
{
|
||||
PrinterDriverAddOn addOn(driverName);
|
||||
PrintServerAddOn addOn(driverName);
|
||||
return addOn.AddPrinter(printerName);
|
||||
}
|
||||
|
||||
@@ -225,7 +231,7 @@ Printer::ConfigurePage(BMessage& settings)
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
PrinterDriverAddOn addOn(driver.String());
|
||||
PrintServerAddOn addOn(driver.String());
|
||||
result = addOn.ConfigPage(SpoolDir(), &settings);
|
||||
if (result == B_OK) {
|
||||
AddCurrentPrinter(settings);
|
||||
@@ -255,7 +261,7 @@ Printer::ConfigureJob(BMessage& settings)
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
PrinterDriverAddOn addOn(driver.String());
|
||||
PrintServerAddOn addOn(driver.String());
|
||||
result = addOn.ConfigJob(SpoolDir(), &settings);
|
||||
if (result == B_OK) {
|
||||
AddCurrentPrinter(settings);
|
||||
@@ -299,7 +305,7 @@ Printer::GetDefaultSettings(BMessage& settings)
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
PrinterDriverAddOn addOn(driver.String());
|
||||
PrintServerAddOn addOn(driver.String());
|
||||
result = addOn.DefaultSettings(SpoolDir(), &settings);
|
||||
if (result == B_OK) {
|
||||
AddCurrentPrinter(settings);
|
||||
@@ -472,20 +478,20 @@ Printer::FindSpooledJob()
|
||||
// the spool file as argument.
|
||||
//
|
||||
// Parameters:
|
||||
// spoolFile - the spool file.
|
||||
// spoolFile - the path to the spool file.
|
||||
//
|
||||
// Returns:
|
||||
// B_OK if successful.
|
||||
// ---------------------------------------------------------------
|
||||
status_t
|
||||
Printer::PrintSpooledJob(BFile* spoolFile)
|
||||
Printer::PrintSpooledJob(const char* spoolFile)
|
||||
{
|
||||
BString driver;
|
||||
status_t result = GetDriverName(&driver);
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
PrinterDriverAddOn addOn(driver.String());
|
||||
PrintServerAddOn addOn(driver.String());
|
||||
return addOn.TakeJob(spoolFile, SpoolDir());
|
||||
}
|
||||
|
||||
@@ -507,10 +513,17 @@ Printer::PrintThread(Job* job)
|
||||
bool failed = true;
|
||||
// Can we continue?
|
||||
if (!fAbort) {
|
||||
BFile jobFile(&job->EntryRef(), B_READ_WRITE);
|
||||
BPath path;
|
||||
bool canOpenFile;
|
||||
{
|
||||
BEntry entry(&job->EntryRef());
|
||||
path.SetTo(&entry);
|
||||
BFile jobFile(path.Path(), B_READ_WRITE);
|
||||
canOpenFile = jobFile.InitCheck() == B_OK;
|
||||
}
|
||||
// Tell the printer to print the spooled job
|
||||
if (jobFile.InitCheck() == B_OK && PrintSpooledJob(&jobFile) == B_OK) {
|
||||
// Remove spool file if printing was successfull.
|
||||
if (canOpenFile && PrintSpooledJob(path.Path()) == B_OK) {
|
||||
// Remove spool file if printing was successful.
|
||||
job->Remove(); failed = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ private:
|
||||
|
||||
// Get next spooled job if any
|
||||
bool FindSpooledJob();
|
||||
status_t PrintSpooledJob(BFile* spoolFile);
|
||||
status_t PrintSpooledJob(const char* spoolFile);
|
||||
void PrintThread(Job* job);
|
||||
|
||||
static status_t print_thread(void* data);
|
||||
|
||||
Reference in New Issue
Block a user