]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/PrinterSetupWizard/UtilTypes.h
11042ddf136151afa9ea855832e9d890bc164655
[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.8 2005/01/06 08:18:26 shersche
27 Add protocol field to service, add EmptyQueues() function to service
28
29 Revision 1.7 2005/01/04 21:07:29 shersche
30 add description member to service object. this member corresponds to the 'ty' key in a printer text record
31
32 Revision 1.6 2004/12/30 01:24:02 shersche
33 <rdar://problem/3906182> Remove references to description key
34 Bug #: 3906182
35
36 Revision 1.5 2004/12/29 18:53:38 shersche
37 <rdar://problem/3725106>
38 <rdar://problem/3737413> Added support for LPR and IPP protocols as well as support for obtaining multiple text records. Reorganized and simplified codebase.
39 Bug #: 3725106, 3737413
40
41 Revision 1.4 2004/09/13 21:22:44 shersche
42 <rdar://problem/3796483> Add moreComing argument to OnAddPrinter and OnRemovePrinter callbacks
43 Bug #: 3796483
44
45 Revision 1.3 2004/06/26 23:27:12 shersche
46 support for installing multiple printers of the same name
47
48 Revision 1.2 2004/06/25 02:25:59 shersche
49 Remove item field from manufacturer and model structures
50 Submitted by: herscher
51
52 Revision 1.1 2004/06/18 04:36:58 rpantos
53 First checked in
54
55
56 */
57
58 #pragma once
59
60 #include <dns_sd.h>
61 #include <string>
62 #include <list>
63 #include <DebugServices.h>
64
65 class CSecondPage;
66
67 #define kDefaultPriority 50
68 #define kDefaultQTotal 1
69
70 namespace PrinterSetupWizard
71 {
72 struct Printer;
73 struct Service;
74 struct Queue;
75 struct Manufacturer;
76 struct Model;
77
78 typedef std::list<Queue*> Queues;
79 typedef std::list<Service*> Services;
80 typedef std::list<Model*> Models;
81
82 struct Printer
83 {
84 Printer();
85
86 ~Printer();
87
88 Service*
89 LookupService
90 (
91 const std::string & type
92 );
93
94 CSecondPage * window;
95 HTREEITEM item;
96
97 //
98 // These are from the browse reply
99 //
100 std::string name;
101 CString displayName;
102 CString actualName;
103
104 //
105 // These keep track of the different services associated with this printer.
106 // the services are ordered according to preference.
107 //
108 Services services;
109
110 //
111 // these are derived from the printer matching code
112 //
113 // if driverInstalled is false, then infFileName should
114 // have an absolute path to the printers inf file. this
115 // is used to install the printer from printui.dll
116 //
117 // if driverInstalled is true, then model is the name
118 // of the driver to use in AddPrinter
119 //
120 bool driverInstalled;
121 CString infFileName;
122 CString manufacturer;
123 CString model;
124 CString portName;
125 bool deflt;
126
127 //
128 // state
129 //
130 unsigned resolving;
131 bool installed;
132 };
133
134
135 struct Service
136 {
137 Service();
138
139 ~Service();
140
141 void
142 EmptyQueues();
143
144 Printer * printer;
145 uint32_t ifi;
146 std::string type;
147 std::string domain;
148
149 //
150 // these are from the resolve
151 //
152 DNSServiceRef serviceRef;
153 CString hostname;
154 unsigned short portNumber;
155 CString usb_MFG;
156 CString usb_MDL;
157 CString description;
158 CString location;
159 CString product;
160 CString protocol;
161 unsigned short qtotal;
162
163 //
164 // There will usually one be one of these, however
165 // this will handle printers that have multiple
166 // queues. These are ordered according to preference.
167 //
168 Queues queues;
169
170 //
171 // Reference count
172 //
173 unsigned refs;
174 };
175
176
177 struct Queue
178 {
179 Queue();
180
181 ~Queue();
182
183 CString name;
184 uint32_t priority;
185 };
186
187
188 struct Manufacturer
189 {
190 CString name;
191 CString tag;
192 Models models;
193 };
194
195
196 struct Model
197 {
198 bool driverInstalled;
199 CString infFileName;
200 CString name;
201 };
202
203
204 inline
205 Printer::Printer()
206 {
207 }
208
209 inline
210 Printer::~Printer()
211 {
212 while ( services.size() > 0 )
213 {
214 Service * service = services.front();
215 services.pop_front();
216 delete service;
217 }
218 }
219
220 inline Service*
221 Printer::LookupService
222 (
223 const std::string & type
224 )
225 {
226 Services::iterator it;
227
228 for ( it = services.begin(); it != services.end(); it++ )
229 {
230 Service * service = *it;
231
232 if ( strcmp(service->type.c_str(), type.c_str()) == 0 )
233 {
234 return service;
235 }
236 }
237
238 return NULL;
239 }
240
241 inline
242 Service::Service()
243 :
244 qtotal(kDefaultQTotal)
245 {
246 }
247
248 inline
249 Service::~Service()
250 {
251 check( serviceRef == NULL );
252
253 EmptyQueues();
254 }
255
256 inline void
257 Service::EmptyQueues()
258 {
259 while ( queues.size() > 0 )
260 {
261 Queue * q = queues.front();
262 queues.pop_front();
263 delete q;
264 }
265 }
266
267 inline
268 Queue::Queue()
269 :
270 priority(kDefaultPriority)
271 {
272 }
273
274 inline
275 Queue::~Queue()
276 {
277 }
278 }
279
280