]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/PrinterSetupWizard/UtilTypes.h
mDNSResponder-107.tar.gz
[apple/mdnsresponder.git] / Clients / PrinterSetupWizard / UtilTypes.h
1 /*
2 * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22
23 Change History (most recent first):
24
25 $Log: UtilTypes.h,v $
26 Revision 1.11 2005/03/05 02:27:46 shersche
27 <rdar://problem/4030388> Generic drivers don't do color
28
29 Revision 1.10 2005/02/08 21:45:06 shersche
30 <rdar://problem/3947490> Default to Generic PostScript or PCL if unable to match driver
31
32 Revision 1.9 2005/02/01 01:16:12 shersche
33 Change window owner from CSecondPage to CPrinterSetupWizardSheet
34
35 Revision 1.8 2005/01/06 08:18:26 shersche
36 Add protocol field to service, add EmptyQueues() function to service
37
38 Revision 1.7 2005/01/04 21:07:29 shersche
39 add description member to service object. this member corresponds to the 'ty' key in a printer text record
40
41 Revision 1.6 2004/12/30 01:24:02 shersche
42 <rdar://problem/3906182> Remove references to description key
43 Bug #: 3906182
44
45 Revision 1.5 2004/12/29 18:53:38 shersche
46 <rdar://problem/3725106>
47 <rdar://problem/3737413> Added support for LPR and IPP protocols as well as support for obtaining multiple text records. Reorganized and simplified codebase.
48 Bug #: 3725106, 3737413
49
50 Revision 1.4 2004/09/13 21:22:44 shersche
51 <rdar://problem/3796483> Add moreComing argument to OnAddPrinter and OnRemovePrinter callbacks
52 Bug #: 3796483
53
54 Revision 1.3 2004/06/26 23:27:12 shersche
55 support for installing multiple printers of the same name
56
57 Revision 1.2 2004/06/25 02:25:59 shersche
58 Remove item field from manufacturer and model structures
59 Submitted by: herscher
60
61 Revision 1.1 2004/06/18 04:36:58 rpantos
62 First checked in
63
64
65 */
66
67 #pragma once
68
69 #include <dns_sd.h>
70 #include <string>
71 #include <list>
72 #include <DebugServices.h>
73
74 class CPrinterSetupWizardSheet;
75
76 #define kDefaultPriority 50
77 #define kDefaultQTotal 1
78
79 namespace PrinterSetupWizard
80 {
81 struct Printer;
82 struct Service;
83 struct Queue;
84 struct Manufacturer;
85 struct Model;
86
87 typedef std::list<Queue*> Queues;
88 typedef std::list<Printer*> Printers;
89 typedef std::list<Service*> Services;
90 typedef std::list<Model*> Models;
91
92 struct Printer
93 {
94 Printer();
95
96 ~Printer();
97
98 Service*
99 LookupService
100 (
101 const std::string & type
102 );
103
104 CPrinterSetupWizardSheet * window;
105 HTREEITEM item;
106
107 //
108 // These are from the browse reply
109 //
110 std::string name;
111 CString displayName;
112 CString actualName;
113
114 //
115 // These keep track of the different services associated with this printer.
116 // the services are ordered according to preference.
117 //
118 Services services;
119
120 //
121 // these are derived from the printer matching code
122 //
123 // if driverInstalled is false, then infFileName should
124 // have an absolute path to the printers inf file. this
125 // is used to install the printer from printui.dll
126 //
127 // if driverInstalled is true, then model is the name
128 // of the driver to use in AddPrinter
129 //
130 bool driverInstalled;
131 CString infFileName;
132 CString manufacturer;
133 CString displayModelName;
134 CString modelName;
135 CString portName;
136 bool deflt;
137
138 //
139 // state
140 //
141 unsigned resolving;
142 bool installed;
143 };
144
145
146 struct Service
147 {
148 Service();
149
150 ~Service();
151
152 void
153 EmptyQueues();
154
155 Printer * printer;
156 uint32_t ifi;
157 std::string type;
158 std::string domain;
159
160 //
161 // these are from the resolve
162 //
163 DNSServiceRef serviceRef;
164 CString hostname;
165 unsigned short portNumber;
166 CString pdl;
167 CString usb_MFG;
168 CString usb_MDL;
169 CString description;
170 CString location;
171 CString product;
172 CString protocol;
173 unsigned short qtotal;
174
175 //
176 // There will usually one be one of these, however
177 // this will handle printers that have multiple
178 // queues. These are ordered according to preference.
179 //
180 Queues queues;
181
182 //
183 // Reference count
184 //
185 unsigned refs;
186 };
187
188
189 struct Queue
190 {
191 Queue();
192
193 ~Queue();
194
195 CString name;
196 uint32_t priority;
197 };
198
199
200 struct Manufacturer
201 {
202 CString name;
203 CString tag;
204 Models models;
205
206 Model*
207 find( const CString & name );
208 };
209
210
211 struct Model
212 {
213 bool driverInstalled;
214 CString infFileName;
215 CString displayName;
216 CString name;
217 };
218
219
220 inline
221 Printer::Printer()
222 {
223 }
224
225 inline
226 Printer::~Printer()
227 {
228 while ( services.size() > 0 )
229 {
230 Service * service = services.front();
231 services.pop_front();
232 delete service;
233 }
234 }
235
236 inline Service*
237 Printer::LookupService
238 (
239 const std::string & type
240 )
241 {
242 Services::iterator it;
243
244 for ( it = services.begin(); it != services.end(); it++ )
245 {
246 Service * service = *it;
247
248 if ( strcmp(service->type.c_str(), type.c_str()) == 0 )
249 {
250 return service;
251 }
252 }
253
254 return NULL;
255 }
256
257 inline
258 Service::Service()
259 :
260 qtotal(kDefaultQTotal)
261 {
262 }
263
264 inline
265 Service::~Service()
266 {
267 check( serviceRef == NULL );
268
269 EmptyQueues();
270 }
271
272 inline void
273 Service::EmptyQueues()
274 {
275 while ( queues.size() > 0 )
276 {
277 Queue * q = queues.front();
278 queues.pop_front();
279 delete q;
280 }
281 }
282
283 inline
284 Queue::Queue()
285 :
286 priority(kDefaultPriority)
287 {
288 }
289
290 inline
291 Queue::~Queue()
292 {
293 }
294
295 inline Model*
296 Manufacturer::find( const CString & name )
297 {
298 Models::iterator it;
299
300 for ( it = models.begin(); it != models.end(); it++ )
301 {
302 Model * model = *it;
303
304 if ( model->name = name )
305 {
306 return model;
307 }
308 }
309
310 return NULL;
311 }
312 }
313
314