]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IORegistryEntry.h
xnu-123.5.tar.gz
[apple/xnu.git] / iokit / IOKit / IORegistryEntry.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
24 *
25 * HISTORY
26 *
27 */
28
29
30#ifndef _IOKIT_IOREGISTRYENTRY_H
31#define _IOKIT_IOREGISTRYENTRY_H
32
33#include <IOKit/IOTypes.h>
34#include <libkern/c++/OSContainers.h>
35
36
37extern const OSSymbol * gIONameKey;
38extern const OSSymbol * gIOLocationKey;
39
40class IORegistryEntry;
41class IORegistryPlane;
42class IORegistryIterator;
43
44typedef void (*IORegistryEntryApplierFunction)(IORegistryEntry * entry,
45 void * context);
46
47enum {
48 kIORegistryIterateRecursively = 0x00000001,
49 kIORegistryIterateParents = 0x00000002
50};
51
52/*! @class IORegistryEntry : public OSObject
53 @abstract The base class for all objects in the registry.
54 @discussion The IORegistryEntry base class provides functions for describing graphs of connected registry entries, each with a dictionary-based property table. Entries may be connected in different planes, with differing topologies. Access to the registry is protected against multiple threads. Inside the kernel planes are specified with plane objects and are published by the creator - IOService exports the gIOServicePlane plane object for example. Non kernel clients specify planes by their name.
55*/
56
57class IORegistryEntry : public OSObject
58{
59 friend IORegistryIterator;
60
61 OSDeclareDefaultStructors(IORegistryEntry)
62
63protected:
64/*! @struct ExpansionData
65 @discussion This structure will be used to expand the capablilties of this class in the future.
66 */
67 struct ExpansionData { };
68
69/*! @var reserved
70 Reserved for future use. (Internal use only) */
71 ExpansionData * reserved;
72
73private:
74
75 OSDictionary * fRegistryTable;
76 OSDictionary * fPropertyTable;
77
78private:
79 OSMetaClassDeclareReservedUnused(IORegistryEntry, 0);
80 OSMetaClassDeclareReservedUnused(IORegistryEntry, 1);
81 OSMetaClassDeclareReservedUnused(IORegistryEntry, 2);
82 OSMetaClassDeclareReservedUnused(IORegistryEntry, 3);
83 OSMetaClassDeclareReservedUnused(IORegistryEntry, 4);
84 OSMetaClassDeclareReservedUnused(IORegistryEntry, 5);
85 OSMetaClassDeclareReservedUnused(IORegistryEntry, 6);
86 OSMetaClassDeclareReservedUnused(IORegistryEntry, 7);
87 OSMetaClassDeclareReservedUnused(IORegistryEntry, 8);
88 OSMetaClassDeclareReservedUnused(IORegistryEntry, 9);
89 OSMetaClassDeclareReservedUnused(IORegistryEntry, 10);
90 OSMetaClassDeclareReservedUnused(IORegistryEntry, 11);
91 OSMetaClassDeclareReservedUnused(IORegistryEntry, 12);
92 OSMetaClassDeclareReservedUnused(IORegistryEntry, 13);
93 OSMetaClassDeclareReservedUnused(IORegistryEntry, 14);
94 OSMetaClassDeclareReservedUnused(IORegistryEntry, 15);
95 OSMetaClassDeclareReservedUnused(IORegistryEntry, 16);
96 OSMetaClassDeclareReservedUnused(IORegistryEntry, 17);
97 OSMetaClassDeclareReservedUnused(IORegistryEntry, 18);
98 OSMetaClassDeclareReservedUnused(IORegistryEntry, 19);
99 OSMetaClassDeclareReservedUnused(IORegistryEntry, 20);
100 OSMetaClassDeclareReservedUnused(IORegistryEntry, 21);
101 OSMetaClassDeclareReservedUnused(IORegistryEntry, 22);
102 OSMetaClassDeclareReservedUnused(IORegistryEntry, 23);
103 OSMetaClassDeclareReservedUnused(IORegistryEntry, 24);
104 OSMetaClassDeclareReservedUnused(IORegistryEntry, 25);
105 OSMetaClassDeclareReservedUnused(IORegistryEntry, 26);
106 OSMetaClassDeclareReservedUnused(IORegistryEntry, 27);
107 OSMetaClassDeclareReservedUnused(IORegistryEntry, 28);
108 OSMetaClassDeclareReservedUnused(IORegistryEntry, 29);
109 OSMetaClassDeclareReservedUnused(IORegistryEntry, 30);
110 OSMetaClassDeclareReservedUnused(IORegistryEntry, 31);
111
112public:
113
114 /* Registry accessors */
115
116/*! @function getRegistryRoot
117 @abstract Returns a pointer to the root instance of the registry.
118 @discussion This method provides an accessor to the root of the registry for the machine. The root may be passed to a registry iterator when iterating a plane, and contains properties that describe the available planes, and diagnostic information for IOKit. Keys for these properties are in IOKitKeys.h.
119 @result A pointer to the IORegistryEntry root instance. It should not be released by the caller. */
120
121 static IORegistryEntry * getRegistryRoot( void );
122
123/*! @function getGenerationCount
124 @abstract Returns an generation count for all registry changing operations.
125 @discussion This method provides an accessor to the current generation count (or seed) of the registry which changes when any topology change occurs in the registry - this does not include property table changes. It may be used to invalidate any caching of the results from IORegistryEntry methods.
126 @result An integer generation count. */
127
128 static SInt32 getGenerationCount( void );
129
130/*! @function getPlane
131 @abstract Looks up the plane object by a C-string name.
132 @discussion Planes are usually provided as globals by the creator, eg. gIOServicePlane, gIODeviceTreePlane, or gIOAudioPlane, however they may also be looked up by name with this method.
133 @result A pointer to the plane object, or zero if no such plane exists. The returned plane should not be released. */
134
135 static const IORegistryPlane * getPlane( const char * name );
136
137 /* Registry Entry allocation & init */
138
139/*! @function init
140 @abstract Standard init method for all IORegistryEntry subclasses.
141 @discussion A registry entry must be initialized with this method before it can be used. A property dictionary may passed and will be retained by this method for use as the registry entry's property table, or an empty one will be created.
142 @param A dictionary that will become the registry entry's property table (retaining it), or zero which will cause an empty property table to be created.
143 @result true on success, or false on a resource failure. */
144
145 virtual bool init( OSDictionary * dictionary = 0 );
146
147/*! @function free
148 @abstract Standard free method for all IORegistryEntry subclasses.
149 @discussion This method will release any resources of the entry, in particular its property table. Note that the registry entry must always be detached from the registry before free may be called, and subclasses (namely IOService) will have additional protocols for removing registry entries. free should never need be called directly. */
150
151 virtual void free( void );
152
153/*! @function setPropertyTable
154 @abstract Replace a registry entry's property table.
155 @discussion This method will release the current property table of a the entry and replace it with another, retaining the new property table.
156 @param dict The new dictionary to be used as the entry's property table. */
157
158 virtual void setPropertyTable( OSDictionary * dict );
159
160 /* Synchronized property accessors; wrappers to OSDictionary
161 * plus property creation helpers */
162
163/*! @function setProperty
164 @abstract Synchronized method to add a property to a registry entry's property table.
165 @discussion This method will add or replace a property in a registry entry's property table, using the OSDictionary::setObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table.
166 @param aKey The properties name as an OSSymbol.
167 @param anObject The property value.
168 @result true on success or false on a resource failure. */
169
170 virtual bool setProperty(const OSSymbol * aKey, OSObject * anObject);
171
172/*! @function setProperty
173 @abstract Synchronized method to add a property to a registry entry's property table.
174 @discussion This method will add or replace a property in a registry entry's property table, using the OSDictionary::setObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table.
175 @param aKey The property's name as an OSString.
176 @param anObject The property value.
177 @result true on success or false on a resource failure. */
178
179 virtual bool setProperty(const OSString * aKey, OSObject * anObject);
180
181/*! @function setProperty
182 @abstract Synchronized method to add a property to a registry entry's property table.
183 @discussion This method will add or replace a property in a registry entry's property table, using the OSDictionary::setObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table.
184 @param aKey The property's name as a C-string.
185 @param anObject The property value.
186 @result true on success or false on a resource failure. */
187
188 virtual bool setProperty(const char * aKey, OSObject * anObject);
189
190/*! @function setProperty
191 @abstract Synchronized method to construct and add a OSString property to a registry entry's property table.
192 @discussion This method will add or replace a property in a registry entry's property table, using the OSDictionary::setObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table. The property is created as an OSString from the supplied C-string, set in the property table with the given name, and released.
193 @param aKey The property's name as a C-string.
194 @param aString The property value as a C-string.
195 @result true on success or false on a resource failure. */
196
197 virtual bool setProperty(const char * aKey, const char * aString);
198
199/*! @function setProperty
200 @abstract Synchronized method to construct and add an OSBoolean property to a registry entry's property table.
201 @discussion This method will add or replace a property in a registry entry's property table, using the OSDictionary::setObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table. The property is created as an OSBoolean from the supplied value, set in the property table with the given name, and released.
202 @param aKey The property's name as a C-string.
203 @param aBoolean The property's boolean value.
204 @result true on success or false on a resource failure. */
205
206 virtual bool setProperty(const char * aKey, bool aBoolean);
207
208/*! @function setProperty
209 @abstract Synchronized method to construct and add an OSNumber property to a registry entry's property table.
210 @discussion This method will add or replace a property in a registry entry's property table, using the OSDictionary::setObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table. The property is created as an OSNumber from the supplied value and size, set in the property table with the given name, and released.
211 @param aKey The property's name as a C-string.
212 @param aValue The property's numeric value.
213 @param aNumberOfBits The property's size in bits, for OSNumber.
214 @result true on success or false on a resource failure. */
215
216 virtual bool setProperty( const char * aKey,
217 unsigned long long aValue,
218 unsigned int aNumberOfBits);
219
220/*! @function setProperty
221 @abstract Synchronized method to construct and add an OSData property to a registry entry's property table.
222 @discussion This method will add or replace a property in a registry entry's property table, using the OSDictionary::setObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table. The property is created as an OSData copied from the supplied date and length, set in the property table with the given name, and released.
223 @param aKey The property's name as a C-string.
224 @param bytes The property's value as a pointer. OSData will copy this data.
225 @param length The property's size in bytes, for OSData.
226 @result true on success or false on a resource failure. */
227
228 virtual bool setProperty( const char * aKey,
229 void * bytes,
230 unsigned int length);
231
232/*! @function removeProperty
233 @abstract Synchronized method to remove a property from a registry entry's property table.
234 @discussion This method will remove a property from a registry entry's property table, using the OSDictionary::removeObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table.
235 @param aKey The property's name as an OSSymbol. */
236
237 virtual void removeProperty( const OSSymbol * aKey);
238
239/*! @function removeProperty
240 @abstract Synchronized method to remove a property from a registry entry's property table.
241 @discussion This method will remove a property from a registry entry's property table, using the OSDictionary::removeObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table.
242 @param aKey The property's name as an OSString. */
243
244 virtual void removeProperty( const OSString * aKey);
245
246/*! @function removeProperty
247 @abstract Synchronized method to remove a property from a registry entry's property table.
248 @discussion This method will remove a property from a registry entry's property table, using the OSDictionary::removeObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table.
249 @param aKey The property's name as a C-string. */
250
251 virtual void removeProperty( const char * aKey);
252
253/*! @function getProperty
254 @abstract Synchronized method to obtain a property from a registry entry's property table.
255 @discussion This method will lookup a property in a registry entry's property table, using the OSDictionary::getObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table.
256 @param aKey The property's name as an OSSymbol.
257 @result The property value found, or zero. */
258
259 virtual OSObject * getProperty( const OSSymbol * aKey) const;
260
261/*! @function getProperty
262 @abstract Synchronized method to obtain a property from a registry entry's property table.
263 @discussion This method will lookup a property in a registry entry's property table, using the OSDictionary::getObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table.
264 @param aKey The property's name as an OSString.
265 @result The property value found, or zero. */
266
267 virtual OSObject * getProperty( const OSString * aKey) const;
268
269/*! @function getProperty
270 @abstract Synchronized method to obtain a property from a registry entry's property table.
271 @discussion This method will lookup a property in a registry entry's property table, using the OSDictionary::getObject semantics. This method is synchronized with other IORegistryEntry accesses to the property table.
272 @param aKey The property's name as a C-string.
273 @result The property value found, or zero. */
274
275 virtual OSObject * getProperty( const char * aKey) const;
276
277/*! @function getProperty
278 @abstract Synchronized method to obtain a property from a registry entry or one of its parents (or children) in the hierarchy.
279 @discussion This method will search for a property, starting first with this registry entry's property table, then iterating recusively through either the parent registry entries or the child registry entries of this entry. Once the first occurrence is found, it will lookup and return the value of the property, using the OSDictionary::getObject semantics. The iteration keeps track of entries that have been recursed into previously to avoid loops. This method is synchronized with other IORegistryEntry accesses to the property table(s).
280 @param aKey The property's name as an OSSymbol.
281 @param plane The plane to iterate over, eg. gIOServicePlane.
282 @param options kIORegistryIterateRecursively may be set to recurse automatically into the registry hierarchy. Without this option, this method degenerates into the standard getProperty() call. kIORegistryIterateParents may be set to iterate the parents of the entry, in place of the children.
283 @result The property value found, or zero. */
284
285 virtual OSObject * getProperty( const OSSymbol * aKey,
286 const IORegistryPlane * plane,
287 IOOptionBits options =
288 kIORegistryIterateRecursively |
289 kIORegistryIterateParents) const;
290
291/*! @function getProperty
292 @abstract Synchronized method to obtain a property from a registry entry or one of its parents (or children) in the hierarchy.
293 @discussion This method will search for a property, starting first with this registry entry's property table, then iterating recusively through either the parent registry entries or the child registry entries of this entry. Once the first occurrence is found, it will lookup and return the value of the property, using the OSDictionary::getObject semantics. The iteration keeps track of entries that have been recursed into previously to avoid loops. This method is synchronized with other IORegistryEntry accesses to the property table(s).
294 @param aKey The property's name as an OSString.
295 @param plane The plane to iterate over, eg. gIOServicePlane.
296 @param options kIORegistryIterateRecursively may be set to recurse automatically into the registry hierarchy. Without this option, this method degenerates into the standard getProperty() call. kIORegistryIterateParents may be set to iterate the parents of the entry, in place of the children.
297 @result The property value found, or zero. */
298
299 virtual OSObject * getProperty( const OSString * aKey,
300 const IORegistryPlane * plane,
301 IOOptionBits options =
302 kIORegistryIterateRecursively |
303 kIORegistryIterateParents) const;
304
305/*! @function getProperty
306 @abstract Synchronized method to obtain a property from a registry entry or one of its parents (or children) in the hierarchy.
307 @discussion This method will search for a property, starting first with this registry entry's property table, then iterating recusively through either the parent registry entries or the child registry entries of this entry. Once the first occurrence is found, it will lookup and return the value of the property, using the OSDictionary::getObject semantics. The iteration keeps track of entries that have been recursed into previously to avoid loops. This method is synchronized with other IORegistryEntry accesses to the property table(s).
308 @param aKey The property's name as a C-string.
309 @param plane The plane to iterate over, eg. gIOServicePlane.
310 @param options kIORegistryIterateRecursively may be set to recurse automatically into the registry hierarchy. Without this option, this method degenerates into the standard getProperty() call. kIORegistryIterateParents may be set to iterate the parents of the entry, in place of the children.
311 @result The property value found, or zero. */
312
313 virtual OSObject * getProperty( const char * aKey,
314 const IORegistryPlane * plane,
315 IOOptionBits options =
316 kIORegistryIterateRecursively |
317 kIORegistryIterateParents) const;
318
319/*! @function copyProperty
320 @abstract Synchronized method to obtain a property from a registry entry's property table.
321 @discussion This method will lookup a property in a registry entry's property table, using the OSDictionary::getObject semantics, and return a reference to the caller. This method is synchronized with other IORegistryEntry accesses to the property table.
322 @param aKey The property's name as an OSSymbol.
323 @result The property value found, or zero. It should be released by the caller. */
324
325 virtual OSObject * copyProperty( const OSSymbol * aKey) const;
326
327/*! @function copyProperty
328 @abstract Synchronized method to obtain a property from a registry entry's property table.
329 @discussion This method will lookup a property in a registry entry's property table, using the OSDictionary::getObject semantics, and return a reference to the caller. This method is synchronized with other IORegistryEntry accesses to the property table.
330 @param aKey The property's name as an OSString.
331 @result The property value found, or zero. It should be released by the caller. */
332
333 virtual OSObject * copyProperty( const OSString * aKey) const;
334
335/*! @function copyProperty
336 @abstract Synchronized method to obtain a property from a registry entry's property table.
337 @discussion This method will lookup a property in a registry entry's property table, using the OSDictionary::getObject semantics, and return a reference to the caller. This method is synchronized with other IORegistryEntry accesses to the property table.
338 @param aKey The property's name as a C-string.
339 @result The property value found, or zero. It should be released by the caller. */
340
341 virtual OSObject * copyProperty( const char * aKey) const;
342
343/*! @function dictionaryWithProperties
344 @abstract Synchronized method to obtain copy a registry entry's property table.
345 @discussion This method will copy a registry entry's property table, using the OSDictionary::withDictionary semantics. This method is synchronized with other IORegistryEntry accesses to the property table. Since OSDictionary will only copy property values by reference, synchronization is not guaranteed to any collection values.
346 @result The created dictionary, or zero on a resource value. It should be released by the caller. */
347
348 virtual OSDictionary * dictionaryWithProperties( void ) const;
349
350/*! @function serializeProperties
351 @abstract Synchronized method to serialize a registry entry's property table.
352 @discussion This method will serialize a registry entry's property table, using the OSDictionary::serialize semantics. This method is synchronized with other IORegistryEntry accesses to the property table. Many non-kernel clients of IOKit read information from the registry via properties, and will invoke this method in a registry entry to create a serialization of all the entry's properties, which is then reconstructed in the client's task as a CFDictionary. This method may be intercepted by subclasses to update their properties or implement a different serialization method, though it is usually better to implement such functionality by creating objects in the property table and implementing their serialize methods, avoiding any need to implement serializeProperties.
353 @param serialize The OSSerialize instance representing the serialization request.
354 @result True on success, false otherwise. */
355
356 virtual bool serializeProperties( OSSerialize * serialize ) const;
357
358 /* Unsynchronized(!) property table access */
359
360/*! @function getPropertyTable
361 @abstract Unsynchronized accessor to a registry entry's property table.
362 @discussion This method will return a pointer to the live property table as an OSDictionery. Its use is not recommended in most cases, instead use the synchronized accessors and helper functions of IORegistryEntry to access properties. It can only safely be used by one thread, which usually means it can only be used before a registry entry is entered into the registry.
363 @result A pointer to the property table as an OSDictionary. The pointer is valid while the registry entry is retained, and should not be released by the caller. */
364
365 inline OSDictionary * getPropertyTable( void ) const
366 { return(fPropertyTable); }
367
368 /* Set properties from user level, to be overridden if supported */
369
370/*! @function setProperties
371 @abstract Optionally supported external method to set properties in a registry entry.
372 @discussion This method is not implemented by IORegistryEntry, but is available to kernel and non-kernel clients to set properties in a registry entry. IOUserClient provides connection based, more controlled access to this functionality and may be more appropriate for many uses, since there is no differentiation between clients available to this method.
373 @param properties Any OSObject subclass, to be interpreted by the implementing method - for example an OSDictionary, OSData etc. may all be appropriate.
374 @result An IOReturn code to be returned to the caller. */
375
376 virtual IOReturn setProperties( OSObject * properties );
377
378 /* Topology */
379
380/*! @function getParentIterator
381 @abstract Returns an iterator over an registry entry's parent entries in a specified plane.
382 @param plane The plane object.
383 @result Returns an iterator over the parents of the registry entry, or zero if there is a resource failure. The iterator must be released when the iteration is finished. All objects returned by the iteration are retained while the iterator is valid, though they may no longer be attached during the iteration. */
384
385 virtual OSIterator * getParentIterator( const IORegistryPlane * plane )
386 const;
387 virtual void applyToParents( IORegistryEntryApplierFunction applier,
388 void * context,
389 const IORegistryPlane * plane ) const;
390
391/*! @function getParentEntry
392 @abstract Returns an registry entry's first parent entry in a plane.
393 @discussion This function will return the parent to which a registry entry was first attached. Since the majority of registry entrys have only one provider, this is a useful simplification.
394 @param plane The plane object.
395 @result Returns the first parent of the registry entry, or zero if the entry is not attached into the registry in that plane. The parent is retained while the entry is attached, and should not be released by the caller. */
396
397 virtual IORegistryEntry * getParentEntry( const IORegistryPlane * plane )
398 const;
399
400/*! @function getChildIterator
401 @abstract Returns an iterator over an registry entry's child entries in a plane.
402 @discussion This method creates an iterator which will return each of a registry entry's child entries in a specified plane.
403 @param plane The plane object.
404 @result Returns an iterator over the children of the entry, or zero if there is a resource failure. The iterator must be released when the iteration is finished. All objects returned by the iteration are retained while the iterator is valid, though they may no longer be attached during the iteration. */
405
406 virtual OSIterator * getChildIterator( const IORegistryPlane * plane )
407 const;
408
409 virtual void applyToChildren( IORegistryEntryApplierFunction applier,
410 void * context,
411 const IORegistryPlane * plane ) const;
412
413/*! @function getChildEntry
414 @abstract Returns an registry entry's first child entry in a plane.
415 @discussion This function will return the child which first attached to a registry entry.
416 @param plane The plane object.
417 @result Returns the first child of the registry entry, or zero if the entry is not attached into the registry in that plane. The child is retained while the entry is attached, and should not be released by the caller. */
418
419 virtual IORegistryEntry * getChildEntry( const IORegistryPlane * plane )
420 const;
421
422/*! @function isChild
423 @abstract Determines whether a registry entry is the child of another in a plane.
424 @discussion This method called in the parent entry determines if the specified entry is a child, in a plane. Additionally, it can check if the child is the only child of the parent entry.
425 @param child The possible child registry entry.
426 @param plane The plane object.
427 @param onlyChild If true, check also if the child is the only child.
428 @result If the child argument is not a child of the registry entry, false is returned. If onlyChild is true and the child is not the only child of the entry, false is returned, otherwise true is returned. */
429
430 virtual bool isChild( IORegistryEntry * child,
431 const IORegistryPlane * plane,
432 bool onlyChild = false ) const;
433
434/*! @function isParent
435 @abstract Determines whether a registry entry is the parent of another in a plane.
436 @discussion This method called in the child entry determines if the specified entry is a parent, in a plane. Additionally, it can check if the parent is the only parent of the child entry.
437 @param parent The possible parent registry entry.
438 @param plane The plane object.
439 @param onlyParent If true, check also if the parent is the only parent.
440 @result If the parent argument is not a parent of the registry entry, false is returned. If onlyParent is true and the parent is not the only parent of the entry, false is returned, otherwise true is returned. */
441
442 virtual bool isParent( IORegistryEntry * parent,
443 const IORegistryPlane * plane,
444 bool onlyParent = false ) const;
445
446/*! @function inPlane
447 @abstract Determines whether a registry entry is attached in a plane.
448 @discussion This method determines if the entry is attached in a plane to any other entry.
449 @param plane The plane object.
450 @result If the entry has a parent in the plane, true is returned, otherwise false is returned. */
451
452 virtual bool inPlane( const IORegistryPlane * plane ) const;
453
454/*! @function getDepth
455 @abstract Counts the maximum number of entries between an entry and the registry root, in a plane.
456 @discussion This method counts the number of entries between and entry and the registry root, in a plane, for each parent of the entry and returns the maximum value.
457 @param plane The plane object.
458 @result The maximum number of entries between the entry and the root. Zero is returned if the entry is not attached in the plane. */
459
460 virtual unsigned int getDepth( const IORegistryPlane * plane ) const;
461
462 /* Attach / detach */
463
464/*! @function attachToParent
465 @abstract Attaches a entry to a parent entry in a plane.
466 @discussion This is the usual method of entering an entry into the registry. It is a no-op and success if the entry is already attached to the parent. Attaching the entry into the registry retains both the child and parent while they are attached. This method will call attachToChild in the parent entry if it is not being called from attachToChild.
467 @param parent The registry entry to attach to.
468 @param plane The plane object.
469 @result true on success, or false on a resource failure, or if the parent is the same as the child. */
470
471 virtual bool attachToParent( IORegistryEntry * parent,
472 const IORegistryPlane * plane );
473
474/*! @function detachFromParent
475 @abstract Detaches an entry from a parent entry in a plane.
476 @discussion This is the usual method of removing an entry from the registry. It is a no-op if the entry is not attached to the parent. Detaching the entry will release both the child and parent. This method will call detachFromChild in the parent entry if it is not being called from detachFromChild.
477 @param parent The registry entry to detach from.
478 @param plane The plane object. */
479
480 virtual void detachFromParent( IORegistryEntry * parent,
481 const IORegistryPlane * plane );
482
483/*! @function attachToChild
484 @abstract Method called in the parent entry when a child attaches.
485 @discussion This method is called in the parent entry when a child attaches, to make overrides possible. This method will also call attachToParent in the child entry if it is not being called from attachToParent. It is a no-op and success if the entry is already a child. Attaching the entry into the registry retains both the child and parent while they are attached.
486 @param child The registry entry being attached.
487 @param plane The plane object.
488 @result true on success, or false on a resource failure, or if the parent is the same as the child. */
489
490 virtual bool attachToChild( IORegistryEntry * child,
491 const IORegistryPlane * plane );
492
493/*! @function detachFromChild
494 @abstract Detaches a child entry from its parent in a plane.
495 @discussion This method is called in the parent entry when a child detaches, to make overrides possible. It is a no-op if the entry is not a child of the parent. Detaching the entry will release both the child and parent. This method will call detachFromParent in the child entry if it is not being called from detachFromParent.
496 @param parent The registry entry to detach.
497 @param plane The plane object. */
498
499 virtual void detachFromChild( IORegistryEntry * child,
500 const IORegistryPlane * plane );
501
502/*! @function detachAbove
503 @abstract Detaches an entry from all its parent entries in a plane.
504 @discussion This method calls detachFromParent in the entry for each of its parent entries in the plane.
505 @param plane The plane object. */
506
507 virtual void detachAbove( const IORegistryPlane * plane );
508
509/*! @function detachAll
510 @abstract Detaches an entry and all its children recursively in a plane.
511 @discussion This method breaks the registry connections for a subtree. detachAbove is called in the entry, and all child entries and their children in the plane.
512 @param plane The plane object. */
513
514 virtual void detachAll( const IORegistryPlane * plane );
515
516 /* Name, location and path accessors */
517
518/*! @function getName
519 @abstract Returns the name assigned to the registry entry as a C-string.
520 @discussion Entries can be named in a particular plane, or globally. If the entry is named in plane and the plane is specified that name will be returned, otherwise the global name is returned. The global name defaults to the entry's meta class name if it has not been named.
521 @param plane The plane object, or zero for the global name.
522 @result A C-string name, valid while the entry is retained. */
523
524 virtual const char * getName( const IORegistryPlane * plane = 0 ) const;
525
526/*! @function copyName
527 @abstract Returns the name assigned to the registry entry as an OSSymbol.
528 @discussion Entries can be named in a particular plane, or globally. If the entry is named in plane and the plane is specified that name will be returned, otherwise the global name is returned. The global name defaults to the entry's meta class name if it has not been named.
529 @param plane The plane object, or zero for the global name.
530 @result A reference to an OSSymbol for the name, which should be released by the caller. */
531
532 virtual const OSSymbol * copyName(
533 const IORegistryPlane * plane = 0 ) const;
534
535/*! @function compareNames
536 @abstract Compares the name of the entry with one or more names, and optionally returns the matching name.
537 @discussion This method is called during IOService name matching and elsewhere to compare the entry's global name with a list of names, or a single name. A list of names may be passed as any OSCollection of OSStrings, while a single name may be passed an OSString, in the name parameter. compareNames will call the compareName method for each name, for overrides.
538 @param name The name or names to compare with as any OSCollection (eg. OSArray, OSSet, OSDictionary) of OSStrings, or a single name may be passed an OSString.
539 @param matched If the caller wants the successfully matched name returned, pass a non-zero pointer for the matched parameter and an OSString will be returned here. It should be released by the caller.
540 @result True if one of the names compared true with the entry's global name. */
541
542 virtual bool compareNames( OSObject * name, OSString ** matched = 0 ) const;
543
544/*! @function compareName
545 @abstract Compares the name of the entry with one name, and optionally returns the matching name.
546 @discussion This method is called during IOService name matching and elsewhere from the compareNames method. It should be overridden to provide non-standard name matching.
547 @param name The name to compare with as an OSString.
548 @param matched If the caller wants the successfully matched name returned, pass a non-zero pointer for the matched parameter and an OSString will be returned here. It should be released by the caller. Generally, this will be the same as the name parameter, but may not be if wildcards are used.
549 @result True if the name compared true with the entry's global name. */
550
551 virtual bool compareName( OSString * name, OSString ** matched = 0 ) const;
552
553/*! @function setName
554 @abstract Sets a name for the registry entry, in a particular plane, or globally.
555 @discussion Entries can be named in a particular plane, or globally. If the plane is specified the name applies only to that plane, otherwise the global name is set. The global name defaults to the entry's meta class name if it has not been named.
556 @param name An OSSymbol which will be retained.
557 @param plane The plane object, or zero to set the global name. */
558
559 virtual void setName( const OSSymbol * name,
560 const IORegistryPlane * plane = 0 );
561
562/*! @function setName
563 @abstract Sets a name for the registry entry, in a particular plane, or globally.
564 @discussion Entries can be named in a particular plane, or globally. If the plane is specified the name applies only to that plane, otherwise the global name is set. The global name defaults to the entry's meta class name if it has not been named.
565 @param name A const C-string name which will be copied.
566 @param plane The plane object, or zero to set the global name. */
567
568 virtual void setName( const char * name,
569 const IORegistryPlane * plane = 0 );
570
571/*! @function getLocation
572 @abstract Returns the location string assigned to the registry entry as a C-string.
573 @discussion Entries can given a location string in a particular plane, or globally. If the entry has had a location set in a plane and the plane is specified that location string will be returned, otherwise the global location string is returned. If no global location string has been set, zero is returned.
574 @param plane The plane object, or zero for the global name.
575 @result A C-string location string, valid while the entry is retained, or zero. */
576
577 virtual const char * getLocation( const IORegistryPlane * plane = 0 ) const;
578
579/*! @function copyLocation
580 @abstract Returns the location string assigned to the registry entry as an OSSymbol.
581 @discussion Entries can given a location string in a particular plane, or globally. If the entry has had a location set in a plane and the plane is specified that location string will be returned, otherwise the global location string is returned. If no global location string has been set, zero is returned.
582 @param plane The plane object, or zero for the global name.
583 @result A reference to an OSSymbol for the location if one exists, which should be released by the caller, or zero. */
584
585 virtual const OSSymbol * copyLocation(
586 const IORegistryPlane * plane = 0 ) const;
587
588/*! @function setLocation
589 @abstract Sets a location string for the registry entry, in a particular plane, or globally.
590 @discussion Entries can be given a location string in a particular plane, or globally. If the plane is specified the location applies only to that plane, otherwise the global location is set. The location string may be used during path lookups of registry entries, to distinguish between sibling entries with the same name. The default IORegistryEntry parsing of location strings expects a list of hex numbers separated by commas, though subclasses of IORegistryEntry might do their own parsing.
591 @param location A C-string location string which will be copied, or an OSSymbol which will be retained.
592 @param plane The plane object, or zero to set the global location string. */
593
594 virtual void setLocation( const OSSymbol * location,
595 const IORegistryPlane * plane = 0 );
596 virtual void setLocation( const char * location,
597 const IORegistryPlane * plane = 0 );
598
599/*! @function getPath
600 @abstract Create a path for a registry entry.
601 @discussion The path for a registry entry is copied to the caller's buffer. The path describes the entry's attachment in a particular plane, which must be specified. The path begins with the plane name followed by a colon, and then followed by '/' separated path components for each of the entries between the root and the registry entry. Each component is constructed with the getPathComponent method called in each entry. An alias may also exist for the entry, which are described as properties in a registry entry found at /aliases in the plane. If a property value interpreted as a path in a call to IORegistryEntry::fromPath yields the entry, then the property name is used as the entry's path.
602 @param path A char buffer allocated by the caller.
603 @param length An in/out parameter - the caller sets the length of the buffer available, and getPath returns the total length of the path copied to the buffer.
604 @param plane The plane object.
605 @result getPath will fail if the entry is not attached in the plane, or if the buffer is not large enough to contain the path. */
606
607 virtual bool getPath( char * path, int * length,
608 const IORegistryPlane * plane) const;
609
610/*! @function getPathComponent
611 @abstract Create a path component for a registry entry.
612 @discussion Each component of a path created with getPath is created with getPathComponent. The default implementation concatenates the entry's name in the the plane, with the "at" symbol and the location string of the entry in the plane if it has been set.
613 @param path A char buffer allocated by the caller.
614 @param length An in/out parameter - the caller sets the length of the buffer available, and getPathComponent returns the total length of the path component copied to the buffer.
615 @param plane The plane object.
616 @result true if the path fits into the supplied buffer or false on a overflow. */
617
618 virtual bool getPathComponent( char * path, int * length,
619 const IORegistryPlane * plane ) const;
620
621/*! @function fromPath
622 @abstract Looks up a registry entry by path.
623 @discussion This function parses paths to lookup registry entries. The path may begin with the <plane name>: created by getPath, or the plane may be set by the caller. If there are characters remaining unparsed after an entry has been looked up, this may be considered an invalid lookup, or those characters may be passed back to the caller and the lookup successful.
624 @param path A C-string path.
625 @param plane The plane to lookup up the path, or zero, in which case the path must begin with the plane name.
626 @param residualPath If the path may contain residual characters after the last path component, the residual will be copied back to the caller's residualPath buffer. If there are residual characters and no residual buffer is specified, fromPath will fail.
627 @param residualLength An in/out parameter - the caller sets the length of the residual buffer available, and fromPath returns the total length of the residual path copied to the buffer. If there is no residualBuffer (residualPath = 0) then residualLength may be zero also.
628 @param fromEntry The lookup will proceed rooted at this entry if non-zero, otherwise it proceeds from the root of the plane.
629 @result A retained registry entry is returned on success, or zero on failure. The caller should release the entry. */
630
631 static IORegistryEntry * fromPath( const char * path,
632 const IORegistryPlane * plane = 0,
633 char * residualPath = 0,
634 int * residualLength = 0,
635 IORegistryEntry * fromEntry = 0 );
636
637/*! @function fromPath
638 @abstract Looks up a registry entry by relative path.
639 @discussion This function looks up a entry below the called entry by a relative path. It is just a convenience that calls IORegistryEntry::fromPath with this as the fromEntry parameter.
640 @param path See IORegistryEntry::fromPath.
641 @param plane See IORegistryEntry::fromPath.
642 @param residualPath See IORegistryEntry::fromPath.
643 @param residualLength See IORegistryEntry::fromPath.
644 @result See IORegistryEntry::fromPath. */
645
646 virtual IORegistryEntry * childFromPath( const char * path,
647 const IORegistryPlane * plane = 0,
648 char * residualPath = 0,
649 int * residualLength = 0 );
650
651/*! @function dealiasPath
652 @abstract Strips any aliases from the head of path and returns the full path.
653 @discussion If the path specified begins with an alias found in the /aliases entry, the value of the alias is returned, and a pointer into the passed in path after the alias is passed back to the caller. If an alias is not found, zero is returned and the path parameter is unchanged.
654 @param opath An in/out paramter - the caller passes in a pointer to a C-string pointer to a path. If an alias is found, dealiasPath returns a pointer into the path just beyond the end of the alias.
655 @param plane A plane object must be specified.
656 @result A C-string pointer to the value of the alias if one is found, or zero if not. */
657
658 static const char * dealiasPath( const char ** opath,
659 const IORegistryPlane * plane );
660
661 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
662 /* * * * * * * * * * * * internals * * * * * * * * * * * */
663 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
664
665public:
666 static IORegistryEntry * initialize( void );
667 static const IORegistryPlane * makePlane( const char * name );
668 // don't even think about using this
669 virtual bool init( IORegistryEntry * from,
670 const IORegistryPlane * inPlane );
671private:
672 inline bool arrayMember( OSArray * set,
673 const IORegistryEntry * member,
674 unsigned int * index = 0 ) const;
675
676 bool makeLink( IORegistryEntry * to,
677 unsigned int relation,
678 const IORegistryPlane * plane ) const;
679 void breakLink( IORegistryEntry * to,
680 unsigned int relation,
681 const IORegistryPlane * plane ) const;
682
683 virtual OSArray * getParentSetReference( const IORegistryPlane * plane )
684 const;
685 virtual OSArray * getChildSetReference( const IORegistryPlane * plane )
686 const;
687 virtual IORegistryEntry * getChildFromComponent( const char ** path,
688 const IORegistryPlane * plane );
689
690 virtual const OSSymbol * hasAlias( const IORegistryPlane * plane,
691 char * opath = 0, int * length = 0 ) const;
692 virtual const char * matchPathLocation( const char * cmp,
693 const IORegistryPlane * plane );
694
695};
696
697/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
698
699/*! @class IORegistryIterator : public OSIterator
700 @abstract An iterator over the registry.
701 @discussion An iterator that can traverse the children or parents of a registry entry in a plane, and recurse. Access to the registry is protected against multiple threads, but an IORegistryIterator instance is for use by one thread only. */
702
703class IORegistryIterator : public OSIterator
704{
705 OSDeclareAbstractStructors(IORegistryIterator)
706
707private:
708 struct IORegCursor {
709 IORegCursor * next;
710 IORegistryEntry * current;
711 OSIterator * iter;
712 };
713 IORegCursor start;
714 IORegCursor * where;
715 IORegistryEntry * root;
716 OSOrderedSet * done;
717 const IORegistryPlane * plane;
718 IOOptionBits options;
719
720 virtual void free( void );
721
722public:
723/*! @function iterateOver
724 @abstract Create an iterator rooted at a given registry entry.
725 @discussion This method creates an IORegistryIterator that is set up with options to iterate children or parents of a root entry, and to recurse automatically into entries as they are returned, or only when instructed. The iterator object keeps track of entries that have been recursed into previously to avoid loops.
726 @param start The root entry to begin the iteration at.
727 @param plane A plane object must be specified.
728 @param options kIORegistryIterateRecursively may be set to recurse automatically into each entry as it is returned. This option affects the behaviour of the getNextObject method, which is defined in the OSIterator superclass. Other methods will override this behaviour. kIORegistryIterateParents may be set to iterate the parents of each entry, by default the children are iterated.
729 @result A created IORegistryIterator instance, to be released by the caller when it has finished with it. */
730
731 static IORegistryIterator * iterateOver( IORegistryEntry * start,
732 const IORegistryPlane * plane,
733 IOOptionBits options = 0 );
734
735/*! @function iterateOver
736 @abstract Create an iterator rooted at the registry root.
737 @discussion This method creates an IORegistryIterator that is set up with options to iterate children of the registry root entry, and to recurse automatically into entries as they are returned, or only when instructed. The iterator object keeps track of entries that have been recursed into previously to avoid loops.
738 @param plane A plane object must be specified.
739 @param options kIORegistryIterateRecursively may be set to recurse automatically into each entry as it is returned. This option affects the behaviour of the getNextObject method, which is defined in the OSIterator superclass. Other methods will override this behaviour. kIORegistryIterateParents may be set to iterate the parents of each entry, by default the children are iterated.
740 @result A created IORegistryIterator instance, to be released by the caller when it has finished with it. */
741
742 static IORegistryIterator * iterateOver( const IORegistryPlane * plane,
743 IOOptionBits options = 0 );
744
745/*! @function getNextObject
746 @abstract Return the next object in the registry iteration.
747 @discussion This method calls either getNextObjectFlat or getNextObjectRecursive depending on the options the iterator was created with. This implements the OSIterator defined getNextObject method. The object returned is retained while the iterator is pointing at it (its the current entry), or recursing into it. The caller should not release it.
748 @result The next registry entry in the iteration (the current entry), or zero if the iteration has finished at this level of recursion. The entry returned is retained while the iterator is pointing at it (its the current entry), or recursing into it. The caller should not release it. */
749
750 virtual IORegistryEntry * getNextObject( void );
751
752/*! @function getNextObjectFlat
753 @abstract Return the next object in the registry iteration, ignoring the kIORegistryIterateRecursively option.
754 @discussion This method returns the next child, or parent if the kIORegistryIterateParents option was used to create the iterator, of the current root entry. The object returned is retained while the iterator is pointing at it (its the current entry), or recursing into it. The caller should not release it.
755 @result The next registry entry in the iteration (the current entry), or zero if the iteration has finished at this level of recursion, or the iteration is invalid (see isValid). The entry returned is retained while the iterator is pointing at it (its the current entry), or recursing into it. The caller should not release it. */
756
757 virtual IORegistryEntry * getNextObjectFlat( void );
758
759/*! @function getNextObjectRecursive
760 @abstract Return the next object in the registry iteration, and enter it.
761 @discussion If the iterator has a current entry, and the iterator has not already entered previously, enterEntry is called to recurse into it, ie. make it the new root, and the next child, or parent if the kIORegistryIterateParents option was used to create the iterator, at this new level of recursion is returned. If there is no current entry at this level of recursion, exitEntry is called and the process repeats, until the iteration returns to the entry the iterator was created with and zero is returned. The object returned is retained while the iterator is pointing at it (its the current entry), or recursing into it. The caller should not release it.
762 @result The next registry entry in the iteration (the current entry), or zero if its finished, or the iteration is invalid (see isValid). The entry returned is retained while the iterator is pointing at it (its the current entry), or recursing into it. The caller should not release it. */
763
764 virtual IORegistryEntry * getNextObjectRecursive( void );
765
766/*! @function getCurrentEntry
767 @abstract Return the current entry in the registry iteration.
768 @discussion This method returns the current entry, last returned by getNextObject et al. The object returned is retained while the iterator is pointing at it (its the current entry), or recursing into it. The caller should not release it. If the iteration is no longer valid (see isValid), the current entry is zero.
769 @result The current registry entry in the iteration, or zero if the last iteration returned zero, or the iteration is invalid (see isValid). The entry returned is retained while the iterator is pointing at it (its the current entry), or recursing into it. The caller should not release it. */
770
771 virtual IORegistryEntry * getCurrentEntry( void );
772
773/*! @function enterEntry
774 @abstract Recurse into the current entry in the registry iteration.
775 @discussion This method makes the current entry, ie. the last entry returned by getNextObject et al., the root in a new level of recursion. */
776
777 virtual void enterEntry( void );
778
779/*! @function enterEntry
780 @abstract Recurse into the current entry in the registry iteration.
781 @discussion This method recurses into an entry as with enterEntry, but also switches from the current plane to a new one set by the caller.
782 @param plane The new plane to switch into. */
783
784 virtual void enterEntry( const IORegistryPlane * plane );
785
786/*! @function exitEntry
787 @abstract Exits a level of recursion, restoring the current entry.
788 @discussion This method undoes an enterEntry, restoring the current entry. If there are no more levels of recursion to exit false is returned, otherwise true is returned.
789 @result true if a level of recursion was undone, false if no recursive levels are left in the iteration. */
790
791 virtual bool exitEntry( void );
792
793/*! @function reset
794 @abstract Exits all levels of recursion, restoring the iterator to its state at creation.
795 @discussion This method exits all levels of recursion, and restores the iterator to its state at creation. */
796
797 virtual void reset( void );
798
799/*! @function isValid
800 @abstract Checks that no registry changes have invalidated the iteration.
801 @discussion If a registry iteration is invalidated by changes to the registry, it will be made invalid, the currentEntry will be considered zero, and further calls to getNextObject et al. will return zero. The iterator should be reset to restart the iteration when this happens.
802 @result false if the iterator has been invalidated by changes to the registry, true otherwise. */
803
804 virtual bool isValid( void );
805
806/*! @function iterateAll
807 @abstract Iterates all entries (with getNextObject) and returns a set of all returned entries.
808 @discussion This method will reset, then iterate all entries in the iteration (with getNextObject) until successful (ie. the iterator is valid at the end of the iteration).
809 @result A set of entries returned by the iteration. The caller should release the set when it has finished with it. Zero is returned on a resource failure. */
810
811 virtual OSOrderedSet * iterateAll( void );
812};
813
814#endif /* _IOKIT_IOREGISTRYENTRY_H */