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