Tizen 2.1 base
[platform/upstream/hplip.git] / prnt / hpijs / printerfactory.h
1 /*****************************************************************************\
2   Copyright (c) 2002 - 2002, Hewlett-Packard Co.
3   All rights reserved.
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
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.
16
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
29
30 #if !defined(APDK_PRINTERFACTORY_H)
31     #define APDK_PRINTERFACTORY_H
32
33 #include "printerproxy.h"           // the factory has to know about the proxies
34
35 APDK_BEGIN_NAMESPACE
36
37 typedef const void* FAMILY_HANDLE;
38 typedef MODEL_HANDLE PRINTER_HANDLE;
39
40 #define pPFI PrinterFactory::GetInstance()
41
42 //PrinterFactory
43 //! Provides the interface to enumerate models and create printer classes
44 /*!
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
49
50 Callers use the factory to create the appropriate printer class based on
51 familiy name, model name, or device ID string.
52 ******************************************************************************/
53
54 // Specify a class prototype, otherwise "virtual printer" fails with error: ISO C++
55 // forbids declaration of "Printer" with no type
56 class Printer;
57
58 class PrinterFactory
59 {
60         friend class dummy;
61 public:
62     // public API
63
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; }
68
69
70     // enumerate Family APIs
71     FAMILY_HANDLE StartFamilyNameEnum() const { return NULL; }
72     const char* GetNextFamilyName(FAMILY_HANDLE& theFamilyHandle) const;
73
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;
77
78     // enumerate all printers in factroy APIs
79     PRINTER_HANDLE StartPrinterNameEnum() const { return NULL; }
80     const char* GetNextPrinterName(PRINTER_HANDLE& thePrinterHandle) const;
81
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;
89
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;
93
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;
98
99 private:
100     // constructors/destructor - Only the factory can construct or destruct itself
101     PrinterFactory();
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
104
105     // Only available to factory manager
106     struct ProxyListElement
107     {
108         const PrinterProxy* printerProxyElement;
109         ProxyListElement* next;
110     };
111
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;
116
117     static PrinterFactory* s_Instance;
118     static ProxyListElement* s_ProxyList;
119
120     static unsigned int s_uPrinterCount;
121     static unsigned int s_uFamilyCount;
122
123 }; //PrinterFactory
124
125
126 //getProxyListElement
127 //! Return the the correct ProxyListELement based on the FAMILY_HANDLE
128 inline const PrinterFactory::ProxyListElement* PrinterFactory::getProxyListElement
129 (
130     const FAMILY_HANDLE theFamilyHandle
131 ) const
132 {
133     return reinterpret_cast<const ProxyListElement*>(theFamilyHandle);
134 }
135
136
137 //getPrinterProxy
138 //! Return the correct PrinterProxy based on the FAMILY_HANDLE
139 inline const PrinterProxy* PrinterFactory::getPrinterProxy
140 (
141     const FAMILY_HANDLE theFamilyHandle
142 ) const
143 {
144     return theFamilyHandle ? getProxyListElement(theFamilyHandle)->printerProxyElement : NULL;
145 } //GetPrinterPoxy
146
147
148 //StartModelNameEnum
149 //! Prepare for a Model Name enumeration based on a family
150 inline MODEL_HANDLE PrinterFactory::StartModelNameEnum
151 (
152     const FAMILY_HANDLE theFamilyHandle
153 ) const
154 {
155     return getPrinterProxy(theFamilyHandle)->StartModelNameEnum();
156 } //StartModelNameEnum
157
158
159 //GetFamilyName
160 //! Get the family name string based on the family handel
161 inline const char* PrinterFactory::GetFamilyName
162 (
163     const FAMILY_HANDLE theFamilyHandle     //!< handle to the family
164 ) const
165 {
166     return getPrinterProxy(theFamilyHandle)->GetFamilyName();
167 } //GetFamilyName
168
169 //GetFamilyType
170 //! Get the family printer type enum based on the family handel
171 inline const PRINTER_TYPE PrinterFactory::GetFamilyType
172 (
173     const FAMILY_HANDLE theFamilyHandle     //!< handle to the family
174 ) const
175 {
176     return getPrinterProxy(theFamilyHandle)->GetPrinterType();
177 } //GetFamilyName
178
179
180
181 //CreatePrinter
182 //! Create a printer class based on the family handle
183 inline Printer* PrinterFactory::CreatePrinter
184 (
185     SystemServices* pSys,                   //!< pointer to a valid SystemSerivce object
186     const FAMILY_HANDLE& theFamilyHandle    //!< handle to the family to support
187 ) const
188 {
189     return theFamilyHandle ? getPrinterProxy(theFamilyHandle)->CreatePrinter(pSys) : NULL;
190 } //CreatePrinter
191
192 APDK_END_NAMESPACE
193
194 #endif //APDK_PRINTERFACTORY_H