1/*
2 * Copyright 2001-2015, Haiku, Inc. 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 _PRINT_SERVER_APP_H
10#define _PRINT_SERVER_APP_H
11
12
13#include <Bitmap.h>
14#include <Catalog.h>
15#include <OS.h>
16#include <Server.h>
17#include <String.h>
18
19#include "FolderWatcher.h"
20#include "ResourceManager.h"
21#include "Settings.h"
22
23
24class Printer;
25class Transport;
26
27
28// The global BLocker for synchronisation.
29extern BLocker *gLock;
30
31
32// The print_server application.
33class PrintServerApp : public BServer, public FolderListener {
34private:
35		typedef BServer Inherited;
36
37public:
38								PrintServerApp(status_t* error);
39								~PrintServerApp();
40
41			void				Acquire();
42			void				Release();
43
44	virtual	bool				QuitRequested();
45	virtual	void				MessageReceived(BMessage* msg);
46			void				NotifyPrinterDeletion(Printer* printer);
47
48	// Scripting support, see PrintServerApp.Scripting.cpp
49	virtual	status_t			GetSupportedSuites(BMessage* msg);
50			void				HandleScriptingCommand(BMessage* msg);
51			Printer*			GetPrinterFromSpecifier(BMessage* msg);
52			Transport*			GetTransportFromSpecifier(BMessage* msg);
53	virtual	BHandler*			ResolveSpecifier(BMessage* msg, int32 index,
54									BMessage* specifier, int32 form,
55									const char* property);
56
57private:
58			bool				OpenSettings(BFile& file, const char* name,
59									bool forReading);
60			void				LoadSettings();
61			void				SaveSettings();
62
63			status_t			SetupPrinterList();
64
65			void				HandleSpooledJobs();
66
67			status_t			SelectPrinter(const char* printerName);
68			status_t			CreatePrinter(const char* printerName,
69									const char* driverName,
70									const char* connection,
71									const char* transportName,
72									const char* transportPath);
73
74			void				RegisterPrinter(BDirectory* node);
75			void				UnregisterPrinter(Printer* printer);
76
77	// FolderListener
78			void				EntryCreated(node_ref* node, entry_ref* entry);
79			void				EntryRemoved(node_ref* node);
80			void				AttributeChanged(node_ref* node);
81
82			status_t			StoreDefaultPrinter();
83			status_t			RetrieveDefaultPrinter();
84
85			status_t			FindPrinterNode(const char* name, BNode& node);
86
87		// "Classic" BeOS R5 support, see PrintServerApp.R5.cpp
88	static	status_t			async_thread(void* data);
89			void				AsyncHandleMessage(BMessage* msg);
90			void				Handle_BeOSR5_Message(BMessage* msg);
91
92private:
93			ResourceManager		fResourceManager;
94			Printer*			fDefaultPrinter;
95			size_t				fIconSize;
96			uint8*				fSelectedIcon;
97			int32				fReferences;
98			sem_id				fHasReferences;
99			Settings*			fSettings;
100			bool				fUseConfigWindow;
101			FolderWatcher*		fFolder;
102};
103
104
105#endif	// _PRINT_SERVER_APP_H
106