1/*
2 * Copyright (c) 2000 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/*
24cc classcount.c -o classcount -Wall -framework IOKit
25 */
26
27#include <assert.h>
28
29#include <CoreFoundation/CoreFoundation.h>
30
31#include <IOKit/IOKitLib.h>
32#include <IOKit/IOKitKeys.h>
33
34int main(int argc, char **argv)
35{
36    kern_return_t	status;
37    mach_port_t		masterPort;
38    io_registry_entry_t	root;
39    CFDictionaryRef	dictionary;
40    CFDictionaryRef	props;
41    CFStringRef		key;
42    CFNumberRef		num;
43    int			arg;
44
45    // Parse args
46
47    if( argc < 2 ) {
48	printf("%s ClassName...\n", argv[0]);
49	exit(0);
50    }
51
52    // Obtain the I/O Kit communication handle.
53
54    status = IOMasterPort(bootstrap_port, &masterPort);
55    assert(status == KERN_SUCCESS);
56
57    // Obtain the registry root entry.
58
59    root = IORegistryGetRootEntry(masterPort);
60    assert(root);
61
62    status = IORegistryEntryCreateCFProperties(root,
63			(CFTypeRef *)&props,
64			kCFAllocatorDefault, kNilOptions );
65    assert( KERN_SUCCESS == status );
66    assert( CFDictionaryGetTypeID() == CFGetTypeID(props));
67
68    dictionary = (CFDictionaryRef)
69		CFDictionaryGetValue( props, CFSTR(kIOKitDiagnosticsKey));
70    assert( dictionary );
71    assert( CFDictionaryGetTypeID() == CFGetTypeID(dictionary));
72
73    dictionary = (CFDictionaryRef)
74		CFDictionaryGetValue( dictionary, CFSTR("Classes"));
75    assert( dictionary );
76    assert( CFDictionaryGetTypeID() == CFGetTypeID(dictionary));
77
78    for( arg = 1; arg < argc; arg++ ) {
79	key = CFStringCreateWithCString(kCFAllocatorDefault,
80			argv[arg], CFStringGetSystemEncoding());
81	assert(key);
82        num = (CFNumberRef) CFDictionaryGetValue(dictionary, key);
83	CFRelease(key);
84        if( num) {
85	    SInt32	num32;
86            assert( CFNumberGetTypeID() == CFGetTypeID(num) );
87	    CFNumberGetValue(num, kCFNumberSInt32Type, &num32);
88            printf("%s = %d, ", argv[arg], (int)num32);
89	}
90    }
91    if( num)
92        printf("\n");
93
94    CFRelease(props);
95    IOObjectRelease(root);
96
97    exit(0);
98}
99
100