xref: /haiku/src/servers/print/PrintServerApp.h (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
1 /*****************************************************************************/
2 // print_server Background Application.
3 //
4 // Version: 1.0.0d1
5 //
6 // The print_server manages the communication between applications and the
7 // printer and transport drivers.
8 //
9 // Authors
10 //   Ithamar R. Adema
11 //   Michael Pfeiffer
12 //
13 // This application and all source files used in its construction, except
14 // where noted, are licensed under the MIT License, and have been written
15 // and are:
16 //
17 // Copyright (c) 2001, 2002 OpenBeOS Project
18 //
19 // Permission is hereby granted, free of charge, to any person obtaining a
20 // copy of this software and associated documentation files (the "Software"),
21 // to deal in the Software without restriction, including without limitation
22 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
23 // and/or sell copies of the Software, and to permit persons to whom the
24 // Software is furnished to do so, subject to the following conditions:
25 //
26 // The above copyright notice and this permission notice shall be included
27 // in all copies or substantial portions of the Software.
28 //
29 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
32 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35 // DEALINGS IN THE SOFTWARE.
36 /*****************************************************************************/
37 
38 #ifndef PRINTSERVERAPP_H
39 #define PRINTSERVERAPP_H
40 
41 #include "ResourceManager.h"
42 #include "Settings.h"
43 #include "FolderWatcher.h"
44 
45 class PrintServerApp;
46 
47 #include <Application.h>
48 #include <Bitmap.h>
49 #include <OS.h>
50 #include <String.h>
51 
52 // global BLocker for synchronisation
53 extern BLocker* gLock;
54 
55 /*****************************************************************************/
56 // PrintServerApp
57 //
58 // Application class for print_server.
59 /*****************************************************************************/
60 class Printer;
61 class PrintServerApp : public BApplication, public FolderListener
62 {
63 	typedef BApplication Inherited;
64 public:
65 	PrintServerApp(status_t* err);
66 	~PrintServerApp();
67 
68 	void Acquire();
69 	void Release();
70 
71 	bool QuitRequested();
72 	void MessageReceived(BMessage* msg);
73 	void NotifyPrinterDeletion(Printer* printer);
74 
75 		// Scripting support, see PrintServerApp.Scripting.cpp
76 	status_t GetSupportedSuites(BMessage* msg);
77 	void HandleScriptingCommand(BMessage* msg);
78 	Printer* GetPrinterFromSpecifier(BMessage* msg);
79 	BHandler* ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec,
80 								int32 form, const char* prop);
81 private:
82 	bool OpenSettings(BFile& file, const char* name, bool forReading);
83 	void LoadSettings();
84 	void SaveSettings();
85 
86 	status_t SetupPrinterList();
87 
88 	void     HandleSpooledJobs();
89 
90 	status_t SelectPrinter(const char* printerName);
91 	status_t CreatePrinter(	const char* printerName, const char* driverName,
92 							const char* connection, const char* transportName,
93 							const char* transportPath);
94 
95 	void     RegisterPrinter(BDirectory* node);
96 	void     UnregisterPrinter(Printer* printer);
97 	// FolderListener
98 	void     EntryCreated(node_ref* node, entry_ref* entry);
99 	void     EntryRemoved(node_ref* node);
100 	void     AttributeChanged(node_ref* node);
101 
102 	status_t StoreDefaultPrinter();
103 	status_t RetrieveDefaultPrinter();
104 
105 	status_t FindPrinterNode(const char* name, BNode& node);
106 	status_t FindPrinterDriver(const char* name, BPath& outPath);
107 
108 	ResourceManager fResourceManager;
109 	Printer* fDefaultPrinter;
110 	BBitmap* fSelectedIconMini;
111 	BBitmap* fSelectedIconLarge;
112 	vint32   fReferences;
113 	sem_id   fHasReferences;
114 	Settings*fSettings;
115 	bool     fUseConfigWindow;
116 	FolderWatcher* fFolder;
117 
118 		// "Classic" BeOS R5 support, see PrintServerApp.R5.cpp
119 	static status_t async_thread(void* data);
120 	void AsyncHandleMessage(BMessage* msg);
121 	void Handle_BeOSR5_Message(BMessage* msg);
122 
123 };
124 
125 #endif
126