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