1 USING: alien.syntax alien.c-types core-foundation system
2 combinators kernel sequences debugger io accessors ;
7 [ "/System/Library/Frameworks/IOKit.framework" load-framework ]
11 : kIOKitBuildVersionKey "IOKitBuildVersion" ; inline
12 : kIOKitDiagnosticsKey "IOKitDiagnostics" ; inline
14 : kIORegistryPlanesKey "IORegistryPlanes" ; inline
15 : kIOCatalogueKey "IOCatalogue" ; inline
17 : kIOServicePlane "IOService" ; inline
18 : kIOPowerPlane "IOPower" ; inline
19 : kIODeviceTreePlane "IODeviceTree" ; inline
20 : kIOAudioPlane "IOAudio" ; inline
21 : kIOFireWirePlane "IOFireWire" ; inline
22 : kIOUSBPlane "IOUSB" ; inline
24 : kIOServiceClass "IOService" ; inline
26 : kIOResourcesClass "IOResources" ; inline
28 : kIOClassKey "IOClass" ; inline
29 : kIOProbeScoreKey "IOProbeScore" ; inline
30 : kIOKitDebugKey "IOKitDebug" ; inline
32 : kIOProviderClassKey "IOProviderClass" ; inline
33 : kIONameMatchKey "IONameMatch" ; inline
34 : kIOPropertyMatchKey "IOPropertyMatch" ; inline
35 : kIOPathMatchKey "IOPathMatch" ; inline
36 : kIOLocationMatchKey "IOLocationMatch" ; inline
37 : kIOParentMatchKey "IOParentMatch" ; inline
38 : kIOResourceMatchKey "IOResourceMatch" ; inline
39 : kIOMatchedServiceCountKey "IOMatchedServiceCountMatch" ; inline
41 : kIONameMatchedKey "IONameMatched" ; inline
43 : kIOMatchCategoryKey "IOMatchCategory" ; inline
44 : kIODefaultMatchCategoryKey "IODefaultMatchCategory" ; inline
46 : kIOUserClientClassKey "IOUserClientClass" ; inline
48 : kIOUserClientCrossEndianKey "IOUserClientCrossEndian" ; inline
49 : kIOUserClientCrossEndianCompatibleKey "IOUserClientCrossEndianCompatible" ; inline
50 : kIOUserClientSharedInstanceKey "IOUserClientSharedInstance" ; inline
52 : kIOPublishNotification "IOServicePublish" ; inline
53 : kIOFirstPublishNotification "IOServiceFirstPublish" ; inline
54 : kIOMatchedNotification "IOServiceMatched" ; inline
55 : kIOFirstMatchNotification "IOServiceFirstMatch" ; inline
56 : kIOTerminatedNotification "IOServiceTerminate" ; inline
58 : kIOGeneralInterest "IOGeneralInterest" ; inline
59 : kIOBusyInterest "IOBusyInterest" ; inline
60 : kIOAppPowerStateInterest "IOAppPowerStateInterest" ; inline
61 : kIOPriorityPowerStateInterest "IOPriorityPowerStateInterest" ; inline
63 : kIOPlatformDeviceMessageKey "IOPlatformDeviceMessage" ; inline
65 : kIOCFPlugInTypesKey "IOCFPlugInTypes" ; inline
67 : kIOCommandPoolSizeKey "IOCommandPoolSize" ; inline
69 : kIOMaximumBlockCountReadKey "IOMaximumBlockCountRead" ; inline
70 : kIOMaximumBlockCountWriteKey "IOMaximumBlockCountWrite" ; inline
71 : kIOMaximumByteCountReadKey "IOMaximumByteCountRead" ; inline
72 : kIOMaximumByteCountWriteKey "IOMaximumByteCountWrite" ; inline
73 : kIOMaximumSegmentCountReadKey "IOMaximumSegmentCountRead" ; inline
74 : kIOMaximumSegmentCountWriteKey "IOMaximumSegmentCountWrite" ; inline
75 : kIOMaximumSegmentByteCountReadKey "IOMaximumSegmentByteCountRead" ; inline
76 : kIOMaximumSegmentByteCountWriteKey "IOMaximumSegmentByteCountWrite" ; inline
77 : kIOMinimumSegmentAlignmentByteCountKey "IOMinimumSegmentAlignmentByteCount" ; inline
78 : kIOMaximumSegmentAddressableBitCountKey "IOMaximumSegmentAddressableBitCount" ; inline
80 : kIOIconKey "IOIcon" ; inline
81 : kIOBundleResourceFileKey "IOBundleResourceFile" ; inline
83 : kIOBusBadgeKey "IOBusBadge" ; inline
84 : kIODeviceIconKey "IODeviceIcon" ; inline
86 : kIOPlatformSerialNumberKey "IOPlatformSerialNumber" ; inline
88 : kIOPlatformUUIDKey "IOPlatformUUID" ; inline
90 : kIONVRAMDeletePropertyKey "IONVRAM-DELETE-PROPERTY" ; inline
91 : kIODTNVRAMPanicInfoKey "aapl,panic-info" ; inline
93 : kIOBootDeviceKey "IOBootDevice" ; inline
94 : kIOBootDevicePathKey "IOBootDevicePath" ; inline
95 : kIOBootDeviceSizeKey "IOBootDeviceSize" ; inline
97 : kOSBuildVersionKey "OS Build Version" ; inline
99 : kNilOptions 0 ; inline
101 TYPEDEF: uint mach_port_t
102 TYPEDEF: int kern_return_t
103 TYPEDEF: int boolean_t
104 TYPEDEF: mach_port_t io_object_t
105 TYPEDEF: io_object_t io_iterator_t
106 TYPEDEF: io_object_t io_registry_entry_t
107 TYPEDEF: io_object_t io_service_t
108 TYPEDEF: char[128] io_name_t
109 TYPEDEF: char[512] io_string_t
110 TYPEDEF: kern_return_t IOReturn
112 TYPEDEF: uint IOOptionBits
114 : MACH_PORT_NULL 0 ; inline
115 : KERN_SUCCESS 0 ; inline
117 FUNCTION: IOReturn IOMasterPort ( mach_port_t bootstrap, mach_port_t* master ) ;
119 FUNCTION: CFDictionaryRef IOServiceMatching ( char* name ) ;
120 FUNCTION: CFDictionaryRef IOServiceNameMatching ( char* name ) ;
121 FUNCTION: CFDictionaryRef IOBSDNameMatching ( char* name ) ;
123 FUNCTION: IOReturn IOObjectRetain ( io_object_t o ) ;
124 FUNCTION: IOReturn IOObjectRelease ( io_object_t o ) ;
126 FUNCTION: IOReturn IOServiceGetMatchingServices ( mach_port_t master, CFDictionaryRef matchingDict, io_iterator_t* iterator ) ;
128 FUNCTION: io_object_t IOIteratorNext ( io_iterator_t i ) ;
129 FUNCTION: void IOIteratorReset ( io_iterator_t i ) ;
130 FUNCTION: boolean_t IOIteratorIsValid ( io_iterator_t i ) ;
132 FUNCTION: IOReturn IORegistryEntryGetPath ( io_registry_entry_t entry, io_name_t plane, io_string_t path ) ;
134 FUNCTION: IOReturn IORegistryEntryCreateCFProperties ( io_registry_entry_t entry, CFMutableDictionaryRef properties, CFAllocatorRef allocator, IOOptionBits options ) ;
136 FUNCTION: char* mach_error_string ( IOReturn error ) ;
138 TUPLE: mach-error error-code ;
139 C: <mach-error> mach-error
142 "IOKit call failed: " print error-code>> mach_error_string print ;
144 : mach-error ( return -- )
145 dup KERN_SUCCESS = [ drop ] [ <mach-error> throw ] if ;
147 : master-port ( -- port )
148 MACH_PORT_NULL 0 <uint> [ IOMasterPort mach-error ] keep *uint ;
150 : io-services-matching-dictionary ( nsdictionary -- iterator )
151 master-port swap 0 <uint>
152 [ IOServiceGetMatchingServices mach-error ] keep
155 : io-services-matching-service ( service -- iterator )
156 IOServiceMatching io-services-matching-dictionary ;
157 : io-services-matching-service-name ( service-name -- iterator )
158 IOServiceNameMatching io-services-matching-dictionary ;
159 : io-services-matching-bsd-name ( bsd-name -- iterator )
160 IOBSDNameMatching io-services-matching-dictionary ;
162 : retain-io-object ( o -- o )
163 [ IOObjectRetain mach-error ] keep ;
164 : release-io-object ( o -- )
165 IOObjectRelease mach-error ;
167 : io-objects-from-iterator* ( i -- i array )
168 [ dup IOIteratorNext dup MACH_PORT_NULL = not ]
172 : io-objects-from-iterator ( i -- array )
173 io-objects-from-iterator* [ release-io-object ] dip ;
175 : properties-from-io-object ( o -- o nsdictionary )
177 kCFAllocatorDefault kNilOptions
178 IORegistryEntryCreateCFProperties mach-error