xref: /haiku/src/servers/print/Printer.h (revision 3e216965baa8d58a67bf7372e2bfa13d999f5a9d)
1 /*
2  * Copyright 2001-2006, Haiku. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ithamar R. Adema
7  *		Michael Pfeiffer
8  */
9 #ifndef PRINTER_H
10 #define PRINTER_H
11 
12 class Printer;
13 
14 #include "BeUtils.h"
15 #include "ResourceManager.h"
16 #include "Jobs.h"
17 
18 	// BeOS API
19 #include <Directory.h>
20 #include <Handler.h>
21 #include <image.h>
22 #include <Locker.h>
23 #include <PrintJob.h>
24 #include <String.h>
25 
26 	// OpenTracker shared sources
27 #include "ObjectList.h"
28 
29 class SpoolFolder : public Folder {
30 protected:
31 	void Notify(Job* job, int kind);
32 
33 public:
34 	SpoolFolder(BLocker* locker, BLooper* looper, const BDirectory& spoolDir);
35 };
36 
37 /*****************************************************************************/
38 // Printer
39 //
40 // This class represents one printer definition. It is manages all actions &
41 // data related to that printer.
42 /*****************************************************************************/
43 class Printer : public BHandler, public Object
44 {
45 	typedef BHandler Inherited;
46 
47 public:
48 	Printer(const BDirectory* node, Resource* res);
49 	~Printer();
50 
51 		// Static helper functions
52 	static Printer* Find(const BString& name);
53 	static Printer* Find(node_ref* node);
54 	static Printer* At(int32 idx);
55 	static void Remove(Printer* printer);
56 	static int32 CountPrinters();
57 
58 	status_t Remove();
59 	status_t ConfigurePrinter();
60 	status_t ConfigureJob(BMessage& ioSettings);
61 	status_t ConfigurePage(BMessage& ioSettings);
62 	status_t GetDefaultSettings(BMessage& configuration);
63 
64 		// Try to start processing of next spooled job
65 	void HandleSpooledJob();
66 		// Abort print_thread without processing spooled job
67 	void AbortPrintThread();
68 
69 	void MessageReceived(BMessage* msg);
70 
71 		// Scripting support, see Printer.Scripting.cpp
72 	status_t GetSupportedSuites(BMessage* msg);
73 	void HandleScriptingCommand(BMessage* msg);
74 	BHandler* ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
75 								int32 form, const char* prop);
76 
77 	void GetName(BString& name);
78 	Resource* GetResource() { return fResource; }
79 
80 private:
81 	status_t LoadPrinterAddon(image_id& id);
82 	void AddCurrentPrinter(BMessage* m);
83 
84 	SpoolFolder fPrinter;      // the printer spooling directory
85 	Resource* fResource;       // the resource required for processing a print job
86 	bool fSinglePrintThread;   // is printer add-on allowed to process multiple print job at once
87 	Job* fJob;                 // the next job to process
88 	vint32 fProcessing;        // the current nmber of processing threads
89 	bool fAbort;	           // stop processing
90 
91 	static BObjectList<Printer> sPrinters;
92 
93 		// Accessor
94 	BDirectory* SpoolDir() { return fPrinter.GetSpoolDir(); }
95 
96 	void ResetJobStatus();
97 	bool HasCurrentPrinter(BString& name);
98 	bool MoveJob(const BString& name);
99 		// Get next spooled job if any
100 	bool FindSpooledJob();
101 	status_t PrintSpooledJob(BFile* spoolFile);
102 	void PrintThread(Job* job);
103 	static status_t print_thread(void* data);
104 	void StartPrintThread();
105 };
106 
107 #endif
108