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