1 /*****************************************************************************\
2 Copyright (c) 2002 - 2002, Hewlett-Packard Co.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. Neither the name of Hewlett-Packard nor the names of its
14 contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 \*****************************************************************************/
28 // PrinterFactory.h - Morpheus component code base
30 #if !defined(APDK_PRINTERFACTORY_H)
31 #define APDK_PRINTERFACTORY_H
33 #include "printerproxy.h" // the factory has to know about the proxies
37 typedef const void* FAMILY_HANDLE;
38 typedef MODEL_HANDLE PRINTER_HANDLE;
40 #define pPFI PrinterFactory::GetInstance()
43 //! Provides the interface to enumerate models and create printer classes
45 PrinterFactory is a singleton that allows the caller to enumerate:
46 \li Families supported
47 \li Models supported within a family
48 \li Printers supported in the factory
50 Callers use the factory to create the appropriate printer class based on
51 familiy name, model name, or device ID string.
52 ******************************************************************************/
54 // Specify a class prototype, otherwise "virtual printer" fails with error: ISO C++
55 // forbids declaration of "Printer" with no type
64 // get class related information
65 inline static const PrinterFactory* GetInstance() { return s_Instance; }
66 inline const unsigned int GetPrinterCount() const { return s_uPrinterCount; }
67 inline const unsigned int GetFamilyCount() const { return s_uFamilyCount; }
70 // enumerate Family APIs
71 FAMILY_HANDLE StartFamilyNameEnum() const { return NULL; }
72 const char* GetNextFamilyName(FAMILY_HANDLE& theFamilyHandle) const;
74 // enumerate models in a family APIs
75 inline MODEL_HANDLE StartModelNameEnum(FAMILY_HANDLE theFamilyHandle) const;
76 const char* GetNextModelName(FAMILY_HANDLE theFamilyHandle, MODEL_HANDLE& theModelHandle) const;
78 // enumerate all printers in factroy APIs
79 PRINTER_HANDLE StartPrinterNameEnum() const { return NULL; }
80 const char* GetNextPrinterName(PRINTER_HANDLE& thePrinterHandle) const;
82 // get family name based on printer name
83 const char* GetFamilyName(const char* thePrinterName) const;
84 const char* GetFamilyName(const FAMILY_HANDLE theFamilyHandle) const;
85 const PRINTER_TYPE GetFamilyType(const FAMILY_HANDLE theFamilyHandle) const;
86 const PRINTER_TYPE EnumDevices( FAMILY_HANDLE& theFamilyHandle) const;
87 const unsigned int GetModelBits() const;
88 const void GetModelString(char* modelstring, int modelstring_length) const;
90 // get a handle to family based on device string
91 // const FAMILY_HANDLE FindModelMatch(const char* szModel) const;
92 const FAMILY_HANDLE FindDevIdMatch(const char* szDevIdString) const;
94 // Printer (un)registration and creation APIs
95 static void Register(const PrinterProxy* thePrinterProxy);
96 static void UnRegister(const PrinterProxy* thePrinterProxy);
97 inline Printer* CreatePrinter(SystemServices* pSys, const FAMILY_HANDLE& theFamilyHandle) const;
100 // constructors/destructor - Only the factory can construct or destruct itself
102 ~PrinterFactory(); // doesn't need to be virtual - there is only one
103 PrinterFactory(const PrinterFactory& theFactory) {}; // dont' let the compiler generate a copy constructor
105 // Only available to factory manager
106 struct ProxyListElement
108 const PrinterProxy* printerProxyElement;
109 ProxyListElement* next;
112 inline const ProxyListElement* getProxyListElement(FAMILY_HANDLE theFamilyHandle) const;
113 inline const PrinterProxy* getPrinterProxy(FAMILY_HANDLE theFamilyHandle) const;
114 bool nextPrinter(FAMILY_HANDLE& theFamilyHandle, MODEL_HANDLE& theModelHandle) const;
115 bool nextFamily(FAMILY_HANDLE& theFamilyHandle) const;
117 static PrinterFactory* s_Instance;
118 static ProxyListElement* s_ProxyList;
120 static unsigned int s_uPrinterCount;
121 static unsigned int s_uFamilyCount;
126 //getProxyListElement
127 //! Return the the correct ProxyListELement based on the FAMILY_HANDLE
128 inline const PrinterFactory::ProxyListElement* PrinterFactory::getProxyListElement
130 const FAMILY_HANDLE theFamilyHandle
133 return reinterpret_cast<const ProxyListElement*>(theFamilyHandle);
138 //! Return the correct PrinterProxy based on the FAMILY_HANDLE
139 inline const PrinterProxy* PrinterFactory::getPrinterProxy
141 const FAMILY_HANDLE theFamilyHandle
144 return theFamilyHandle ? getProxyListElement(theFamilyHandle)->printerProxyElement : NULL;
149 //! Prepare for a Model Name enumeration based on a family
150 inline MODEL_HANDLE PrinterFactory::StartModelNameEnum
152 const FAMILY_HANDLE theFamilyHandle
155 return getPrinterProxy(theFamilyHandle)->StartModelNameEnum();
156 } //StartModelNameEnum
160 //! Get the family name string based on the family handel
161 inline const char* PrinterFactory::GetFamilyName
163 const FAMILY_HANDLE theFamilyHandle //!< handle to the family
166 return getPrinterProxy(theFamilyHandle)->GetFamilyName();
170 //! Get the family printer type enum based on the family handel
171 inline const PRINTER_TYPE PrinterFactory::GetFamilyType
173 const FAMILY_HANDLE theFamilyHandle //!< handle to the family
176 return getPrinterProxy(theFamilyHandle)->GetPrinterType();
182 //! Create a printer class based on the family handle
183 inline Printer* PrinterFactory::CreatePrinter
185 SystemServices* pSys, //!< pointer to a valid SystemSerivce object
186 const FAMILY_HANDLE& theFamilyHandle //!< handle to the family to support
189 return theFamilyHandle ? getPrinterProxy(theFamilyHandle)->CreatePrinter(pSys) : NULL;
194 #endif //APDK_PRINTERFACTORY_H