1 USING: alien.syntax alien.c-types alien.data core-foundation
2 core-foundation.bundles core-foundation.dictionaries system
3 combinators kernel sequences io accessors unix.types ;
8 [ "/System/Library/Frameworks/IOKit.framework" load-framework ]
12 CONSTANT: kIOKitBuildVersionKey "IOKitBuildVersion"
13 CONSTANT: kIOKitDiagnosticsKey "IOKitDiagnostics"
15 CONSTANT: kIORegistryPlanesKey "IORegistryPlanes"
16 CONSTANT: kIOCatalogueKey "IOCatalogue"
18 CONSTANT: kIOServicePlane "IOService"
19 CONSTANT: kIOPowerPlane "IOPower"
20 CONSTANT: kIODeviceTreePlane "IODeviceTree"
21 CONSTANT: kIOAudioPlane "IOAudio"
22 CONSTANT: kIOFireWirePlane "IOFireWire"
23 CONSTANT: kIOUSBPlane "IOUSB"
25 CONSTANT: kIOServiceClass "IOService"
27 CONSTANT: kIOResourcesClass "IOResources"
29 CONSTANT: kIOClassKey "IOClass"
30 CONSTANT: kIOProbeScoreKey "IOProbeScore"
31 CONSTANT: kIOKitDebugKey "IOKitDebug"
33 CONSTANT: kIOProviderClassKey "IOProviderClass"
34 CONSTANT: kIONameMatchKey "IONameMatch"
35 CONSTANT: kIOPropertyMatchKey "IOPropertyMatch"
36 CONSTANT: kIOPathMatchKey "IOPathMatch"
37 CONSTANT: kIOLocationMatchKey "IOLocationMatch"
38 CONSTANT: kIOParentMatchKey "IOParentMatch"
39 CONSTANT: kIOResourceMatchKey "IOResourceMatch"
40 CONSTANT: kIOMatchedServiceCountKey "IOMatchedServiceCountMatch"
42 CONSTANT: kIONameMatchedKey "IONameMatched"
44 CONSTANT: kIOMatchCategoryKey "IOMatchCategory"
45 CONSTANT: kIODefaultMatchCategoryKey "IODefaultMatchCategory"
47 CONSTANT: kIOUserClientClassKey "IOUserClientClass"
49 CONSTANT: kIOUserClientCrossEndianKey "IOUserClientCrossEndian"
50 CONSTANT: kIOUserClientCrossEndianCompatibleKey "IOUserClientCrossEndianCompatible"
51 CONSTANT: kIOUserClientSharedInstanceKey "IOUserClientSharedInstance"
53 CONSTANT: kIOPublishNotification "IOServicePublish"
54 CONSTANT: kIOFirstPublishNotification "IOServiceFirstPublish"
55 CONSTANT: kIOMatchedNotification "IOServiceMatched"
56 CONSTANT: kIOFirstMatchNotification "IOServiceFirstMatch"
57 CONSTANT: kIOTerminatedNotification "IOServiceTerminate"
59 CONSTANT: kIOGeneralInterest "IOGeneralInterest"
60 CONSTANT: kIOBusyInterest "IOBusyInterest"
61 CONSTANT: kIOAppPowerStateInterest "IOAppPowerStateInterest"
62 CONSTANT: kIOPriorityPowerStateInterest "IOPriorityPowerStateInterest"
64 CONSTANT: kIOPlatformDeviceMessageKey "IOPlatformDeviceMessage"
66 CONSTANT: kIOCFPlugInTypesKey "IOCFPlugInTypes"
68 CONSTANT: kIOCommandPoolSizeKey "IOCommandPoolSize"
70 CONSTANT: kIOMaximumBlockCountReadKey "IOMaximumBlockCountRead"
71 CONSTANT: kIOMaximumBlockCountWriteKey "IOMaximumBlockCountWrite"
72 CONSTANT: kIOMaximumByteCountReadKey "IOMaximumByteCountRead"
73 CONSTANT: kIOMaximumByteCountWriteKey "IOMaximumByteCountWrite"
74 CONSTANT: kIOMaximumSegmentCountReadKey "IOMaximumSegmentCountRead"
75 CONSTANT: kIOMaximumSegmentCountWriteKey "IOMaximumSegmentCountWrite"
76 CONSTANT: kIOMaximumSegmentByteCountReadKey "IOMaximumSegmentByteCountRead"
77 CONSTANT: kIOMaximumSegmentByteCountWriteKey "IOMaximumSegmentByteCountWrite"
78 CONSTANT: kIOMinimumSegmentAlignmentByteCountKey "IOMinimumSegmentAlignmentByteCount"
79 CONSTANT: kIOMaximumSegmentAddressableBitCountKey "IOMaximumSegmentAddressableBitCount"
81 CONSTANT: kIOIconKey "IOIcon"
82 CONSTANT: kIOBundleResourceFileKey "IOBundleResourceFile"
84 CONSTANT: kIOBusBadgeKey "IOBusBadge"
85 CONSTANT: kIODeviceIconKey "IODeviceIcon"
87 CONSTANT: kIOPlatformSerialNumberKey "IOPlatformSerialNumber"
89 CONSTANT: kIOPlatformUUIDKey "IOPlatformUUID"
91 CONSTANT: kIONVRAMDeletePropertyKey "IONVRAM-DELETE-PROPERTY"
92 CONSTANT: kIODTNVRAMPanicInfoKey "aapl,panic-info"
94 CONSTANT: kIOBootDeviceKey "IOBootDevice"
95 CONSTANT: kIOBootDevicePathKey "IOBootDevicePath"
96 CONSTANT: kIOBootDeviceSizeKey "IOBootDeviceSize"
98 CONSTANT: kOSBuildVersionKey "OS Build Version"
100 CONSTANT: kNilOptions 0
102 CONSTANT: MACH_PORT_NULL 0
103 CONSTANT: KERN_SUCCESS 0
105 FUNCTION: IOReturn IOMasterPort ( mach_port_t bootstrap, mach_port_t* master ) ;
107 FUNCTION: CFDictionaryRef IOServiceMatching ( c-string name ) ;
108 FUNCTION: CFDictionaryRef IOServiceNameMatching ( c-string name ) ;
109 FUNCTION: CFDictionaryRef IOBSDNameMatching ( c-string name ) ;
111 FUNCTION: IOReturn IOObjectRetain ( io_object_t o ) ;
112 FUNCTION: IOReturn IOObjectRelease ( io_object_t o ) ;
114 FUNCTION: IOReturn IOServiceGetMatchingServices ( mach_port_t master, CFDictionaryRef matchingDict, io_iterator_t* iterator ) ;
116 FUNCTION: io_object_t IOIteratorNext ( io_iterator_t i ) ;
117 FUNCTION: void IOIteratorReset ( io_iterator_t i ) ;
118 FUNCTION: boolean_t IOIteratorIsValid ( io_iterator_t i ) ;
120 FUNCTION: IOReturn IORegistryEntryGetPath ( io_registry_entry_t entry, io_name_t plane, io_string_t path ) ;
122 FUNCTION: IOReturn IORegistryEntryCreateCFProperties ( io_registry_entry_t entry, CFMutableDictionaryRef properties, CFAllocatorRef allocator, IOOptionBits options ) ;
124 FUNCTION: c-string mach_error_string ( IOReturn error ) ;
126 TUPLE: mach-error error-code error-string ;
127 : <mach-error> ( code -- error )
128 dup mach_error_string \ mach-error boa ;
130 : mach-error ( return -- )
131 dup KERN_SUCCESS = [ drop ] [ <mach-error> throw ] if ;
133 : master-port ( -- port )
134 MACH_PORT_NULL { uint } [ IOMasterPort mach-error ] [ ] with-out-parameters ;
136 : io-services-matching-dictionary ( nsdictionary -- iterator )
138 { uint } [ IOServiceGetMatchingServices mach-error ] [ ] with-out-parameters ;
140 : io-services-matching-service ( service -- iterator )
141 IOServiceMatching io-services-matching-dictionary ;
142 : io-services-matching-service-name ( service-name -- iterator )
143 IOServiceNameMatching io-services-matching-dictionary ;
144 : io-services-matching-bsd-name ( bsd-name -- iterator )
145 IOBSDNameMatching io-services-matching-dictionary ;
147 : retain-io-object ( o -- o )
148 [ IOObjectRetain mach-error ] keep ;
149 : release-io-object ( o -- )
150 IOObjectRelease mach-error ;
152 : io-objects-from-iterator* ( i -- i array )
153 [ dup IOIteratorNext dup MACH_PORT_NULL = not ] [ ] produce nip ;
155 : io-objects-from-iterator ( i -- array )
156 io-objects-from-iterator* [ release-io-object ] dip ;
158 : properties-from-io-object ( o -- o nsdictionary )
160 kCFAllocatorDefault kNilOptions
161 IORegistryEntryCreateCFProperties mach-error