1 #include "PrintAddOnServer.h"
6 #include "PrinterDriverAddOn.h"
7 #include "PrintAddOnServerProtocol.h"
9 static const bigtime_t kSeconds
= 1000000L;
10 static const bigtime_t kDeliveryTimeout
= 30 * kSeconds
;
11 static const bigtime_t kReplyTimeout
= B_INFINITE_TIMEOUT
;
14 PrintAddOnServer::PrintAddOnServer(const char* driver
)
18 fLaunchStatus
= Launch(fMessenger
);
22 PrintAddOnServer::~PrintAddOnServer()
24 if (fLaunchStatus
== B_OK
)
30 PrintAddOnServer::AddPrinter(const char* spoolFolderName
)
32 BMessage
message(kMessageAddPrinter
);
33 message
.AddString(kPrinterDriverAttribute
, Driver());
34 message
.AddString(kPrinterNameAttribute
, spoolFolderName
);
37 status_t result
= SendRequest(message
, reply
);
41 return GetResult(reply
);
46 PrintAddOnServer::ConfigPage(BDirectory
* spoolFolder
,
49 BMessage
message(kMessageConfigPage
);
50 message
.AddString(kPrinterDriverAttribute
, Driver());
51 AddDirectory(message
, kPrinterFolderAttribute
, spoolFolder
);
52 message
.AddMessage(kPrintSettingsAttribute
, settings
);
55 status_t result
= SendRequest(message
, reply
);
59 return GetResultAndUpdateSettings(reply
, settings
);
64 PrintAddOnServer::ConfigJob(BDirectory
* spoolFolder
,
67 BMessage
message(kMessageConfigJob
);
68 message
.AddString(kPrinterDriverAttribute
, Driver());
69 AddDirectory(message
, kPrinterFolderAttribute
, spoolFolder
);
70 message
.AddMessage(kPrintSettingsAttribute
, settings
);
73 status_t result
= SendRequest(message
, reply
);
77 return GetResultAndUpdateSettings(reply
, settings
);
82 PrintAddOnServer::DefaultSettings(BDirectory
* spoolFolder
,
85 BMessage
message(kMessageDefaultSettings
);
86 message
.AddString(kPrinterDriverAttribute
, Driver());
87 AddDirectory(message
, kPrinterFolderAttribute
, spoolFolder
);
90 status_t result
= SendRequest(message
, reply
);
94 return GetResultAndUpdateSettings(reply
, settings
);
99 PrintAddOnServer::TakeJob(const char* spoolFile
,
100 BDirectory
* spoolFolder
)
102 BMessage
message(kMessageTakeJob
);
103 message
.AddString(kPrinterDriverAttribute
, Driver());
104 message
.AddString(kPrintJobFileAttribute
, spoolFile
);
105 AddDirectory(message
, kPrinterFolderAttribute
, spoolFolder
);
108 status_t result
= SendRequest(message
, reply
);
112 return GetResult(reply
);
117 PrintAddOnServer::FindPathToDriver(const char* driver
, BPath
* path
)
119 return PrinterDriverAddOn::FindPathToDriver(driver
, path
);
124 PrintAddOnServer::Driver() const
126 return fDriver
.String();
131 PrintAddOnServer::Launch(BMessenger
& messenger
)
135 be_roster
->Launch(kPrintAddOnServerApplicationSignature
,
136 (BMessage
*)NULL
, &team
);
137 if (result
!= B_OK
) {
141 fMessenger
= BMessenger(kPrintAddOnServerApplicationSignature
, team
);
147 PrintAddOnServer::IsLaunched()
149 return fLaunchStatus
== B_OK
;
154 PrintAddOnServer::Quit()
156 if (fLaunchStatus
== B_OK
) {
157 fMessenger
.SendMessage(B_QUIT_REQUESTED
);
158 fLaunchStatus
= B_ERROR
;
164 PrintAddOnServer::AddDirectory(BMessage
& message
, const char* name
,
165 BDirectory
* directory
)
168 status_t result
= directory
->GetEntry(&entry
);
173 if (entry
.GetPath(&path
) != B_OK
)
176 message
.AddString(name
, path
.Path());
181 PrintAddOnServer::AddEntryRef(BMessage
& message
, const char* name
,
182 const entry_ref
* entryRef
)
184 BPath
path(entryRef
);
185 if (path
.InitCheck() != B_OK
)
188 message
.AddString(name
, path
.Path());
193 PrintAddOnServer::SendRequest(BMessage
& request
, BMessage
& reply
)
196 return fLaunchStatus
;
198 return fMessenger
.SendMessage(&request
, &reply
, kDeliveryTimeout
,
204 PrintAddOnServer::GetResult(BMessage
& reply
)
207 status_t result
= reply
.FindInt32(kPrintAddOnServerStatusAttribute
,
211 return static_cast<status_t
>(status
);
216 PrintAddOnServer::GetResultAndUpdateSettings(BMessage
& reply
, BMessage
* settings
)
218 BMessage newSettings
;
219 if (reply
.FindMessage(kPrintSettingsAttribute
, &newSettings
) == B_OK
)
220 *settings
= newSettings
;
222 settings
->PrintToStream();
224 return GetResult(reply
);