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 PRINTER_H 39 #define PRINTER_H 40 41 class Printer; 42 43 #include "BeUtils.h" 44 #include "ResourceManager.h" 45 #include "Jobs.h" 46 47 // BeOS API 48 #include <Directory.h> 49 #include <Handler.h> 50 #include <image.h> 51 #include <Locker.h> 52 #include <PrintJob.h> 53 #include <String.h> 54 55 // OpenTracker shared sources 56 #include "ObjectList.h" 57 58 class SpoolFolder : public Folder { 59 protected: 60 void Notify(Job* job, int kind); 61 62 public: 63 SpoolFolder(BLocker* locker, BLooper* looper, const BDirectory& spoolDir); 64 }; 65 66 /*****************************************************************************/ 67 // Printer 68 // 69 // This class represents one printer definition. It is manages all actions & 70 // data related to that printer. 71 /*****************************************************************************/ 72 class Printer : public BHandler, public Object 73 { 74 typedef BHandler Inherited; 75 76 public: 77 Printer(const BDirectory* node, Resource* res); 78 ~Printer(); 79 80 // Static helper functions 81 static Printer* Find(const BString& name); 82 static Printer* Find(node_ref* node); 83 static Printer* At(int32 idx); 84 static void Remove(Printer* printer); 85 static int32 CountPrinters(); 86 87 status_t Remove(); 88 status_t ConfigurePrinter(); 89 status_t ConfigureJob(BMessage& ioSettings); 90 status_t ConfigurePage(BMessage& ioSettings); 91 status_t GetDefaultSettings(BMessage& configuration); 92 93 // Try to start processing of next spooled job 94 void HandleSpooledJob(); 95 // Abort print_thread without processing spooled job 96 void AbortPrintThread(); 97 98 void MessageReceived(BMessage* msg); 99 100 // Scripting support, see Printer.Scripting.cpp 101 status_t GetSupportedSuites(BMessage* msg); 102 void HandleScriptingCommand(BMessage* msg); 103 BHandler* ResolveSpecifier(BMessage* msg, int32 index, BMessage* spec, 104 int32 form, const char* prop); 105 106 void GetName(BString& name); 107 Resource* GetResource() { return fResource; } 108 109 private: 110 status_t LoadPrinterAddon(image_id& id); 111 void AddCurrentPrinter(BMessage* m); 112 113 SpoolFolder fPrinter; // the printer spooling directory 114 Resource* fResource; // the resource required for processing a print job 115 bool fSinglePrintThread; // is printer add-on allowed to process multiple print job at once 116 Job* fJob; // the next job to process 117 vint32 fProcessing; // the current nmber of processing threads 118 bool fAbort; // stop processing 119 120 static BObjectList<Printer> sPrinters; 121 122 // Accessor 123 BDirectory* SpoolDir() { return fPrinter.GetSpoolDir(); } 124 125 void ResetJobStatus(); 126 bool HasCurrentPrinter(BString& name); 127 bool MoveJob(const BString& name); 128 // Get next spooled job if any 129 bool FindSpooledJob(); 130 status_t PrintSpooledJob(BFile* spoolFile); 131 void PrintThread(Job* job); 132 static status_t print_thread(void* data); 133 void StartPrintThread(); 134 }; 135 136 #endif 137