Clean up.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1198 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+58
-32
@@ -39,6 +39,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// BeOS
|
// BeOS
|
||||||
|
#include <be/kernel/fs_attr.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
#include <Node.h>
|
#include <Node.h>
|
||||||
@@ -50,46 +51,42 @@ Job::Job(const BEntry& job, BHandler* handler)
|
|||||||
: fHandler(handler)
|
: fHandler(handler)
|
||||||
, fTime(-1)
|
, fTime(-1)
|
||||||
, fStatus(kUnknown)
|
, fStatus(kUnknown)
|
||||||
|
, fValid(false)
|
||||||
, fPrinter(NULL)
|
, fPrinter(NULL)
|
||||||
{
|
{
|
||||||
// store light weight versions of BEntry and BNode
|
// store light weight versions of BEntry and BNode
|
||||||
job.GetRef(&fEntry);
|
job.GetRef(&fEntry);
|
||||||
job.GetNodeRef(&fNode);
|
job.GetNodeRef(&fNode);
|
||||||
|
|
||||||
|
fValid = IsValidJobFile();
|
||||||
|
|
||||||
BNode node(&job);
|
BNode node(&job);
|
||||||
if (node.InitCheck() != B_OK) return;
|
if (node.InitCheck() != B_OK) return;
|
||||||
|
|
||||||
BNodeInfo info(&node);
|
|
||||||
char mimeType[256];
|
|
||||||
BString status;
|
BString status;
|
||||||
|
// read status attribute
|
||||||
// Is job a spool file?
|
if (node.ReadAttrString(PSRV_SPOOL_ATTR_STATUS, &status) != B_OK) {
|
||||||
if (info.InitCheck() == B_OK /*&&
|
status = "";
|
||||||
info.GetType(mimeType) == B_OK &&
|
|
||||||
strcmp(mimeType, PSRV_SPOOL_FILETYPE) == 0 &&
|
|
||||||
node.ReadAttr(PSRV_SPOOL_ATTR_STATUS, B_STRING_TYPE, 0, status, sizeof(status))*/) {
|
|
||||||
if (node.ReadAttrString(PSRV_SPOOL_ATTR_STATUS, &status) != B_OK) {
|
|
||||||
status = "";
|
|
||||||
}
|
|
||||||
// read status attribute
|
|
||||||
UpdateStatus(status.String());
|
|
||||||
// Now get file name and creation time from file name
|
|
||||||
fTime = 0;
|
|
||||||
BEntry entry(job);
|
|
||||||
char name[B_FILE_NAME_LENGTH];
|
|
||||||
if (entry.InitCheck() == B_OK && entry.GetName(name) == B_OK) {
|
|
||||||
fName = name;
|
|
||||||
// search for last '@' in file name
|
|
||||||
char* p = NULL, *c = name;
|
|
||||||
while ((c = strchr(c, '@')) != NULL) {
|
|
||||||
p = c; c ++;
|
|
||||||
}
|
|
||||||
// and get time from file name
|
|
||||||
fTime = atoi(p+1);
|
|
||||||
}
|
|
||||||
// start watching if everything is ok
|
|
||||||
StartNodeWatching();
|
|
||||||
}
|
}
|
||||||
|
UpdateStatus(status.String());
|
||||||
|
|
||||||
|
// Now get file name and creation time from file name
|
||||||
|
fTime = 0;
|
||||||
|
BEntry entry(job);
|
||||||
|
char name[B_FILE_NAME_LENGTH];
|
||||||
|
if (entry.InitCheck() == B_OK && entry.GetName(name) == B_OK) {
|
||||||
|
fName = name;
|
||||||
|
// search for last '@' in file name
|
||||||
|
char* p = NULL, *c = name;
|
||||||
|
while ((c = strchr(c, '@')) != NULL) {
|
||||||
|
p = c; c ++;
|
||||||
|
}
|
||||||
|
// and get time from file name
|
||||||
|
fTime = atoi(p+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// start watching the node
|
||||||
|
StartNodeWatching();
|
||||||
}
|
}
|
||||||
|
|
||||||
// conversion from string representation of status to JobStatus constant
|
// conversion from string representation of status to JobStatus constant
|
||||||
@@ -108,6 +105,32 @@ void Job::UpdateStatusAttribute(const char* status) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Job::HasAttribute(BNode* n, const char* name) {
|
||||||
|
attr_info info;
|
||||||
|
return n->GetAttrInfo(name, &info) == B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Job::IsValidJobFile() {
|
||||||
|
BNode node(&fEntry);
|
||||||
|
if (node.InitCheck() != B_OK) return false;
|
||||||
|
|
||||||
|
BNodeInfo info(&node);
|
||||||
|
char mimeType[256];
|
||||||
|
|
||||||
|
// Is job a spool file?
|
||||||
|
return (info.InitCheck() == B_OK &&
|
||||||
|
info.GetType(mimeType) == B_OK &&
|
||||||
|
strcmp(mimeType, PSRV_SPOOL_FILETYPE) == 0) &&
|
||||||
|
HasAttribute(&node, PSRV_SPOOL_ATTR_MIMETYPE) &&
|
||||||
|
HasAttribute(&node, PSRV_SPOOL_ATTR_PAGECOUNT) &&
|
||||||
|
HasAttribute(&node, PSRV_SPOOL_ATTR_DESCRIPTION) &&
|
||||||
|
HasAttribute(&node, PSRV_SPOOL_ATTR_PRINTER) &&
|
||||||
|
HasAttribute(&node, PSRV_SPOOL_ATTR_STATUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set status of object and optionally write to attribute of node
|
// Set status of object and optionally write to attribute of node
|
||||||
void Job::SetStatus(JobStatus s, bool writeToNode) {
|
void Job::SetStatus(JobStatus s, bool writeToNode) {
|
||||||
fStatus = s;
|
fStatus = s;
|
||||||
@@ -122,6 +145,7 @@ void Job::SetStatus(JobStatus s, bool writeToNode) {
|
|||||||
|
|
||||||
// Synchronize file attribute with member variable
|
// Synchronize file attribute with member variable
|
||||||
void Job::UpdateAttribute() {
|
void Job::UpdateAttribute() {
|
||||||
|
fValid = fValid || IsValidJobFile();
|
||||||
BNode node(&fEntry);
|
BNode node(&fEntry);
|
||||||
BString status;
|
BString status;
|
||||||
if (node.InitCheck() == B_OK &&
|
if (node.InitCheck() == B_OK &&
|
||||||
@@ -155,7 +179,7 @@ bool Folder::AddJob(BEntry& entry) {
|
|||||||
Job* job = new Job(entry, this);
|
Job* job = new Job(entry, this);
|
||||||
if (job->InitCheck() == B_OK) {
|
if (job->InitCheck() == B_OK) {
|
||||||
fJobs.AddItem(job);
|
fJobs.AddItem(job);
|
||||||
if (job->IsWaiting()) NotifyPrinter();
|
if (job->IsValid() && job->IsWaiting()) NotifyPrinter();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
job->Release();
|
job->Release();
|
||||||
@@ -203,7 +227,7 @@ void Folder::AttributeChanged(BMessage* msg) {
|
|||||||
Job* job = Find(node);
|
Job* job = Find(node);
|
||||||
if (job) {
|
if (job) {
|
||||||
job->UpdateAttribute();
|
job->UpdateAttribute();
|
||||||
if (job->IsWaiting()) NotifyPrinter();
|
if (job->IsValid() && job->IsWaiting()) NotifyPrinter();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +322,9 @@ void Folder::MessageReceived(BMessage* msg) {
|
|||||||
Job* Folder::GetNextJob() {
|
Job* Folder::GetNextJob() {
|
||||||
for (int i = 0; i < fJobs.CountItems(); i ++) {
|
for (int i = 0; i < fJobs.CountItems(); i ++) {
|
||||||
Job* job = fJobs.ItemAt(i);
|
Job* job = fJobs.ItemAt(i);
|
||||||
if (job->IsWaiting()) {
|
if (job->IsValid() && job->IsWaiting()) {
|
||||||
|
/*fJobs.RemoveItem(job);
|
||||||
|
job->StopNodeWatching();*/
|
||||||
job->Acquire(); return job;
|
job->Acquire(); return job;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-13
@@ -41,35 +41,39 @@
|
|||||||
#include <StorageDefs.h>
|
#include <StorageDefs.h>
|
||||||
|
|
||||||
enum JobStatus {
|
enum JobStatus {
|
||||||
kWaiting,
|
kWaiting, // to be processed
|
||||||
kProcessing,
|
kProcessing, // processed by a printer add-on
|
||||||
kFailed,
|
kFailed, // failed to process the job file
|
||||||
kUnknown,
|
kUnknown, // other
|
||||||
};
|
};
|
||||||
|
|
||||||
class Printer;
|
class Printer;
|
||||||
|
|
||||||
class Job : public Object {
|
class Job : public Object {
|
||||||
private:
|
private:
|
||||||
BHandler* fHandler;
|
BHandler* fHandler; // the handler that watches the node of the job file
|
||||||
BString fName;
|
BString fName; // the name of the job file
|
||||||
node_ref fNode;
|
long fTime; // the time encoded in the file name
|
||||||
entry_ref fEntry;
|
node_ref fNode; // the node of the job file
|
||||||
JobStatus fStatus;
|
entry_ref fEntry; // the entry of the job file
|
||||||
long fTime;
|
JobStatus fStatus; // the status of the job file
|
||||||
Printer* fPrinter;
|
bool fValid; // is this a valid job file?
|
||||||
|
Printer* fPrinter; // the printer that processes this job
|
||||||
|
|
||||||
void UpdateStatus(const char* status);
|
void UpdateStatus(const char* status);
|
||||||
void UpdateStatusAttribute(const char* status);
|
void UpdateStatusAttribute(const char* status);
|
||||||
|
bool HasAttribute(BNode* node, const char* name);
|
||||||
|
bool IsValidJobFile();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Job(const BEntry& entry, BHandler* handler);
|
Job(const BEntry& entry, BHandler* handler);
|
||||||
|
|
||||||
status_t InitCheck() const { return fTime >= 0 ? B_OK : B_ERROR; }
|
status_t InitCheck() const { return fTime >= 0 ? B_OK : B_ERROR; }
|
||||||
|
|
||||||
// accessors
|
// accessors
|
||||||
const BString& Name() const { return fName; }
|
const BString& Name() const { return fName; }
|
||||||
JobStatus Status() const { return fStatus; }
|
JobStatus Status() const { return fStatus; }
|
||||||
|
bool IsValid() const { return fValid; }
|
||||||
long Time() const { return fTime; }
|
long Time() const { return fTime; }
|
||||||
const node_ref& NodeRef() const { return fNode; }
|
const node_ref& NodeRef() const { return fNode; }
|
||||||
const entry_ref& EntryRef() const { return fEntry; }
|
const entry_ref& EntryRef() const { return fEntry; }
|
||||||
|
|||||||
@@ -281,6 +281,9 @@ status_t PrintServerApp::SetupPrinterList()
|
|||||||
void
|
void
|
||||||
PrintServerApp::MessageReceived(BMessage* msg)
|
PrintServerApp::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
|
fprintf(stdout, "PrintServerApp\n");
|
||||||
|
msg->PrintToStream();
|
||||||
|
fflush(stdout);
|
||||||
switch(msg->what) {
|
switch(msg->what) {
|
||||||
case PSRV_GET_ACTIVE_PRINTER:
|
case PSRV_GET_ACTIVE_PRINTER:
|
||||||
case PSRV_MAKE_PRINTER_ACTIVE_QUIETLY:
|
case PSRV_MAKE_PRINTER_ACTIVE_QUIETLY:
|
||||||
|
|||||||
Reference in New Issue
Block a user