]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/PrinterSetupWizard/UtilTypes.h
41a3251c3c54b2f575ca6b9073ca178c4a58f757
[apple/mdnsresponder.git] / Clients / PrinterSetupWizard / UtilTypes.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 1997-2004 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 Change History (most recent first):
18
19 $Log: UtilTypes.h,v $
20 Revision 1.18 2009/05/29 20:43:37 herscher
21 <rdar://problem/6928136> Printer Wizard doesn't work correctly in Windows 7 64 bit
22
23 Revision 1.17 2009/05/27 04:59:57 herscher
24 <rdar://problem/4517393> COMPATIBILITY WITH HP CLJ4700
25 <rdar://problem/6142138> Compatibility with Samsung print driver files
26
27 Revision 1.16 2007/04/20 22:58:10 herscher
28 <rdar://problem/4826126> mDNS: Printer Wizard doesn't offer generic HP printers or generic PS support on Vista RC2
29
30 Revision 1.15 2006/08/14 23:24:09 cheshire
31 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
32
33 Revision 1.14 2005/06/30 18:02:54 shersche
34 <rdar://problem/4124524> Workaround for Mac OS X Printer Sharing bug
35
36 Revision 1.13 2005/04/13 17:46:22 shersche
37 <rdar://problem/4082122> Generic PCL not selected when printers advertise multiple text records
38
39 Revision 1.12 2005/03/16 03:12:28 shersche
40 <rdar://problem/4050504> Generic PCL driver isn't selected correctly on Win2K
41
42 Revision 1.11 2005/03/05 02:27:46 shersche
43 <rdar://problem/4030388> Generic drivers don't do color
44
45 Revision 1.10 2005/02/08 21:45:06 shersche
46 <rdar://problem/3947490> Default to Generic PostScript or PCL if unable to match driver
47
48 Revision 1.9 2005/02/01 01:16:12 shersche
49 Change window owner from CSecondPage to CPrinterSetupWizardSheet
50
51 Revision 1.8 2005/01/06 08:18:26 shersche
52 Add protocol field to service, add EmptyQueues() function to service
53
54 Revision 1.7 2005/01/04 21:07:29 shersche
55 add description member to service object. this member corresponds to the 'ty' key in a printer text record
56
57 Revision 1.6 2004/12/30 01:24:02 shersche
58 <rdar://problem/3906182> Remove references to description key
59 Bug #: 3906182
60
61 Revision 1.5 2004/12/29 18:53:38 shersche
62 <rdar://problem/3725106>
63 <rdar://problem/3737413> Added support for LPR and IPP protocols as well as support for obtaining multiple text records. Reorganized and simplified codebase.
64 Bug #: 3725106, 3737413
65
66 Revision 1.4 2004/09/13 21:22:44 shersche
67 <rdar://problem/3796483> Add moreComing argument to OnAddPrinter and OnRemovePrinter callbacks
68 Bug #: 3796483
69
70 Revision 1.3 2004/06/26 23:27:12 shersche
71 support for installing multiple printers of the same name
72
73 Revision 1.2 2004/06/25 02:25:59 shersche
74 Remove item field from manufacturer and model structures
75 Submitted by: herscher
76
77 Revision 1.1 2004/06/18 04:36:58 rpantos
78 First checked in
79
80
81 */
82
83 #pragma once
84
85 #include <dns_sd.h>
86 #include <string>
87 #include <list>
88 #include <DebugServices.h>
89
90 class CPrinterSetupWizardSheet;
91
92 #define kDefaultPriority 50
93 #define kDefaultQTotal 1
94
95 namespace PrinterSetupWizard
96 {
97 struct Printer;
98 struct Service;
99 struct Queue;
100 struct Manufacturer;
101 struct Model;
102
103 typedef std::list<Queue*> Queues;
104 typedef std::list<Printer*> Printers;
105 typedef std::list<Service*> Services;
106 typedef std::list<Model*> Models;
107
108 struct Printer
109 {
110 Printer();
111
112 ~Printer();
113
114 Service*
115 LookupService
116 (
117 const std::string & type
118 );
119
120 CPrinterSetupWizardSheet * window;
121 HTREEITEM item;
122
123 //
124 // These are from the browse reply
125 //
126 std::string name;
127 CString displayName;
128 CString actualName;
129
130 //
131 // These keep track of the different services associated with this printer.
132 // the services are ordered according to preference.
133 //
134 Services services;
135
136 //
137 // these are derived from the printer matching code
138 //
139 // if driverInstalled is false, then infFileName should
140 // have an absolute path to the printers inf file. this
141 // is used to install the printer from printui.dll
142 //
143 // if driverInstalled is true, then model is the name
144 // of the driver to use in AddPrinter
145 //
146 bool driverInstalled;
147 CString infFileName;
148 CString manufacturer;
149 CString displayModelName;
150 CString modelName;
151 CString portName;
152 bool deflt;
153
154 // This let's us know that this printer was discovered via OSX Printer Sharing.
155 // We use this knowledge to workaround a problem with OS X Printer sharing.
156
157 bool isSharedFromOSX;
158
159 //
160 // state
161 //
162 unsigned resolving;
163 bool installed;
164 };
165
166
167 struct Service
168 {
169 Service();
170
171 ~Service();
172
173 Queue*
174 SelectedQueue();
175
176 void
177 EmptyQueues();
178
179 Printer * printer;
180 uint32_t ifi;
181 std::string type;
182 std::string domain;
183
184 //
185 // these are from the resolve
186 //
187 DNSServiceRef serviceRef;
188 CString hostname;
189 unsigned short portNumber;
190 CString protocol;
191 unsigned short qtotal;
192
193 //
194 // There will usually one be one of these, however
195 // this will handle printers that have multiple
196 // queues. These are ordered according to preference.
197 //
198 Queues queues;
199
200 //
201 // Reference count
202 //
203 unsigned refs;
204 };
205
206
207 struct Queue
208 {
209 Queue();
210
211 ~Queue();
212
213 CString name;
214 uint32_t priority;
215 CString pdl;
216 CString usb_MFG;
217 CString usb_MDL;
218 CString description;
219 CString location;
220 CString product;
221 };
222
223
224 struct Manufacturer
225 {
226 CString name;
227 Models models;
228
229 Model*
230 find( const CString & name );
231 };
232
233
234 struct Model
235 {
236 bool driverInstalled;
237 CString infFileName;
238 CString displayName;
239 CString name;
240 };
241
242
243 inline
244 Printer::Printer()
245 :
246 isSharedFromOSX( false )
247 {
248 }
249
250 inline
251 Printer::~Printer()
252 {
253 while ( services.size() > 0 )
254 {
255 Service * service = services.front();
256 services.pop_front();
257 delete service;
258 }
259 }
260
261 inline Service*
262 Printer::LookupService
263 (
264 const std::string & type
265 )
266 {
267 Services::iterator it;
268
269 for ( it = services.begin(); it != services.end(); it++ )
270 {
271 Service * service = *it;
272
273 if ( strcmp(service->type.c_str(), type.c_str()) == 0 )
274 {
275 return service;
276 }
277 }
278
279 return NULL;
280 }
281
282 inline
283 Service::Service()
284 :
285 qtotal(kDefaultQTotal)
286 {
287 }
288
289 inline
290 Service::~Service()
291 {
292 check( serviceRef == NULL );
293
294 EmptyQueues();
295 }
296
297 inline Queue*
298 Service::SelectedQueue()
299 {
300 return queues.front();
301 }
302
303 inline void
304 Service::EmptyQueues()
305 {
306 while ( queues.size() > 0 )
307 {
308 Queue * q = queues.front();
309 queues.pop_front();
310 delete q;
311 }
312 }
313
314 inline
315 Queue::Queue()
316 :
317 priority(kDefaultPriority)
318 {
319 }
320
321 inline
322 Queue::~Queue()
323 {
324 }
325
326 inline Model*
327 Manufacturer::find( const CString & name )
328 {
329 Models::iterator it;
330
331 for ( it = models.begin(); it != models.end(); it++ )
332 {
333 Model * model = *it;
334
335 if ( model->name == name )
336 {
337 return model;
338 }
339 }
340
341 return NULL;
342 }
343 }
344
345