xref: /haiku/src/servers/print/Printer.h (revision 746cac055adc6ac3308c7bc2d29040fb95689cc9)
1 /*
2  * Copyright 2001-2008, 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 
30 class SpoolFolder : public Folder {
31 protected:
32 	void Notify(Job* job, int kind);
33 
34 public:
35 	SpoolFolder(BLocker* locker, BLooper* looper, const BDirectory& spoolDir);
36 };
37 
38 
39 /*****************************************************************************/
40 // Printer
41 //
42 // This class represents one printer definition. It is manages all actions &
43 // data related to that printer.
44 /*****************************************************************************/
45 class Printer : public BHandler, public Object
46 {
47 	typedef BHandler Inherited;
48 public:
49 								Printer(const BDirectory* node, Resource* res);
50 	virtual						~Printer();
51 
52 	virtual	void				MessageReceived(BMessage* message);
53 	virtual	status_t			GetSupportedSuites(BMessage* msg);
54 	virtual	BHandler*			ResolveSpecifier(BMessage* msg, int32 index,
55 									BMessage* spec, int32 form, const char* prop);
56 
57 			// Static helper functions
58 	static	Printer*			Find(const BString& name);
59 	static	Printer*			Find(node_ref* node);
60 	static	Printer*			At(int32 idx);
61 	static	void				Remove(Printer* printer);
62 	static	int32				CountPrinters();
63 
64 			status_t			Remove();
65 			status_t			ConfigurePrinter();
66 			status_t			ConfigureJob(BMessage& ioSettings);
67 			status_t			ConfigurePage(BMessage& ioSettings);
68 			status_t			GetDefaultSettings(BMessage& configuration);
69 
70 			// Try to start processing of next spooled job
71 			void				HandleSpooledJob();
72 
73 			// Abort print_thread without processing spooled job
74 			void				AbortPrintThread();
75 
76 			// Scripting support, see Printer.Scripting.cpp
77 			void				HandleScriptingCommand(BMessage* msg);
78 
79 			void				GetName(BString& name);
80 			Resource*			GetResource() { return fResource; }
81 
82 private:
83 			status_t			LoadPrinterAddon(image_id& id);
84 			void				AddCurrentPrinter(BMessage& message);
85 
86 			// Accessor
87 			BDirectory*			SpoolDir() { return fPrinter.GetSpoolDir(); }
88 
89 			void				ResetJobStatus();
90 			bool				HasCurrentPrinter(BString& name);
91 			bool				MoveJob(const BString& name);
92 
93 			// Get next spooled job if any
94 			bool				FindSpooledJob();
95 			status_t			PrintSpooledJob(BFile* spoolFile);
96 			void				PrintThread(Job* job);
97 
98 	static	status_t			print_thread(void* data);
99 			void				StartPrintThread();
100 
101 private:
102 			// the printer spooling directory
103 			SpoolFolder			fPrinter;
104 			// the resource required for processing a print job
105 			Resource*			fResource;
106 			// is printer add-on allowed to process multiple print job at once
107 			bool				fSinglePrintThread;
108 			// the next job to process
109 			Job*				fJob;
110 			// the current nmber of processing threads
111 			vint32				fProcessing;
112 			// stop processing
113 			bool				fAbort;
114 	static	BObjectList<Printer> sPrinters;
115 };
116 
117 #endif
118