]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/PrinterSetupWizard/UtilTypes.h
mDNSResponder-176.3.tar.gz
[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.16 2007/04/20 22:58:10 herscher
21 <rdar://problem/4826126> mDNS: Printer Wizard doesn't offer generic HP printers or generic PS support on Vista RC2
22
23 Revision 1.15 2006/08/14 23:24:09 cheshire
24 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
25
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 typedef std::list<CString> Decorations;
101
102 struct Printer
103 {
104 Printer();
105
106 ~Printer();
107
108 Service*
109 LookupService
110 (
111 const std::string & type
112 );
113
114 CPrinterSetupWizardSheet * window;
115 HTREEITEM item;
116
117 //
118 // These are from the browse reply
119 //
120 std::string name;
121 CString displayName;
122 CString actualName;
123
124 //
125 // These keep track of the different services associated with this printer.
126 // the services are ordered according to preference.
127 //
128 Services services;
129
130 //
131 // these are derived from the printer matching code
132 //
133 // if driverInstalled is false, then infFileName should
134 // have an absolute path to the printers inf file. this
135 // is used to install the printer from printui.dll
136 //
137 // if driverInstalled is true, then model is the name
138 // of the driver to use in AddPrinter
139 //
140 bool driverInstalled;
141 CString infFileName;
142 CString manufacturer;
143 CString displayModelName;
144 CString modelName;
145 CString portName;
146 bool deflt;
147
148 // This let's us know that this printer was discovered via OSX Printer Sharing.
149 // We use this knowledge to workaround a problem with OS X Printer sharing.
150
151 bool isSharedFromOSX;
152
153 //
154 // state
155 //
156 unsigned resolving;
157 bool installed;
158 };
159
160
161 struct Service
162 {
163 Service();
164
165 ~Service();
166
167 Queue*
168 SelectedQueue();
169
170 void
171 EmptyQueues();
172
173 Printer * printer;
174 uint32_t ifi;
175 std::string type;
176 std::string domain;
177
178 //
179 // these are from the resolve
180 //
181 DNSServiceRef serviceRef;
182 CString hostname;
183 unsigned short portNumber;
184 CString protocol;
185 unsigned short qtotal;
186
187 //
188 // There will usually one be one of these, however
189 // this will handle printers that have multiple
190 // queues. These are ordered according to preference.
191 //
192 Queues queues;
193
194 //
195 // Reference count
196 //
197 unsigned refs;
198 };
199
200
201 struct Queue
202 {
203 Queue();
204
205 ~Queue();
206
207 CString name;
208 uint32_t priority;
209 CString pdl;
210 CString usb_MFG;
211 CString usb_MDL;
212 CString description;
213 CString location;
214 CString product;
215 };
216
217
218 struct Manufacturer
219 {
220 CString name;
221 CString tag;
222 Models models;
223 Decorations decorations;
224
225 Model*
226 find( const CString & name );
227 };
228
229
230 struct Model
231 {
232 bool driverInstalled;
233 CString infFileName;
234 CString displayName;
235 CString name;
236 };
237
238
239 inline
240 Printer::Printer()
241 :
242 isSharedFromOSX( false )
243 {
244 }
245
246 inline
247 Printer::~Printer()
248 {
249 while ( services.size() > 0 )
250 {
251 Service * service = services.front();
252 services.pop_front();
253 delete service;
254 }
255 }
256
257 inline Service*
258 Printer::LookupService
259 (
260 const std::string & type
261 )
262 {
263 Services::iterator it;
264
265 for ( it = services.begin(); it != services.end(); it++ )
266 {
267 Service * service = *it;
268
269 if ( strcmp(service->type.c_str(), type.c_str()) == 0 )
270 {
271 return service;
272 }
273 }
274
275 return NULL;
276 }
277
278 inline
279 Service::Service()
280 :
281 qtotal(kDefaultQTotal)
282 {
283 }
284
285 inline
286 Service::~Service()
287 {
288 check( serviceRef == NULL );
289
290 EmptyQueues();
291 }
292
293 inline Queue*
294 Service::SelectedQueue()
295 {
296 return queues.front();
297 }
298
299 inline void
300 Service::EmptyQueues()
301 {
302 while ( queues.size() > 0 )
303 {
304 Queue * q = queues.front();
305 queues.pop_front();
306 delete q;
307 }
308 }
309
310 inline
311 Queue::Queue()
312 :
313 priority(kDefaultPriority)
314 {
315 }
316
317 inline
318 Queue::~Queue()
319 {
320 }
321
322 inline Model*
323 Manufacturer::find( const CString & name )
324 {
325 Models::iterator it;
326
327 for ( it = models.begin(); it != models.end(); it++ )
328 {
329 Model * model = *it;
330
331 if ( model->name == name )
332 {
333 return model;
334 }
335 }
336
337 return NULL;
338 }
339 }
340
341