1 /* 2 * Copyright 2001-2010, 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 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 static status_t FindPathToDriver(const char* driver, 66 BPath* path); 67 static status_t ConfigurePrinter(const char* driverName, 68 const char* printerName); 69 status_t ConfigureJob(BMessage& ioSettings); 70 status_t ConfigurePage(BMessage& ioSettings); 71 status_t GetDefaultSettings(BMessage& configuration); 72 73 // Try to start processing of next spooled job 74 void HandleSpooledJob(); 75 76 // Abort print_thread without processing spooled job 77 void AbortPrintThread(); 78 79 // Scripting support, see Printer.Scripting.cpp 80 void HandleScriptingCommand(BMessage* msg); 81 82 void GetName(BString& name); GetResource()83 Resource* GetResource() { return fResource; } 84 85 private: 86 status_t GetDriverName(BString* name); 87 void AddCurrentPrinter(BMessage& message); 88 SpoolDir()89 BDirectory* SpoolDir() { return fPrinter.GetSpoolDir(); } 90 91 void ResetJobStatus(); 92 bool HasCurrentPrinter(BString& name); 93 bool MoveJob(const BString& name); 94 95 // Get next spooled job if any 96 bool FindSpooledJob(); 97 status_t PrintSpooledJob(const char* spoolFile); 98 void PrintThread(Job* job); 99 100 static status_t print_thread(void* data); 101 void StartPrintThread(); 102 103 private: 104 // the printer spooling directory 105 SpoolFolder fPrinter; 106 // the resource required for processing a print job 107 Resource* fResource; 108 // is printer add-on allowed to process multiple print job at once 109 bool fSinglePrintThread; 110 // the next job to process 111 Job* fJob; 112 // the current nmber of processing threads 113 int32 fProcessing; 114 // stop processing 115 bool fAbort; 116 static BObjectList<Printer> sPrinters; 117 }; 118 119 #endif 120