]> gitweb.factorcode.org Git - factor.git/blob - basis/iokit/iokit.factor
Updating code to use with-out-parameters
[factor.git] / basis / iokit / iokit.factor
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 ;
4 IN: iokit
5
6 <<
7     os macosx?
8     [ "/System/Library/Frameworks/IOKit.framework" load-framework ]
9     when
10 >>
11
12 CONSTANT: kIOKitBuildVersionKey   "IOKitBuildVersion"
13 CONSTANT: kIOKitDiagnosticsKey   "IOKitDiagnostics"
14  
15 CONSTANT: kIORegistryPlanesKey   "IORegistryPlanes"
16 CONSTANT: kIOCatalogueKey    "IOCatalogue"
17
18 CONSTANT: kIOServicePlane    "IOService"
19 CONSTANT: kIOPowerPlane    "IOPower"
20 CONSTANT: kIODeviceTreePlane   "IODeviceTree"
21 CONSTANT: kIOAudioPlane    "IOAudio"
22 CONSTANT: kIOFireWirePlane   "IOFireWire"
23 CONSTANT: kIOUSBPlane    "IOUSB"
24
25 CONSTANT: kIOServiceClass    "IOService"
26
27 CONSTANT: kIOResourcesClass   "IOResources"
28
29 CONSTANT: kIOClassKey    "IOClass"
30 CONSTANT: kIOProbeScoreKey   "IOProbeScore"
31 CONSTANT: kIOKitDebugKey    "IOKitDebug"
32
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"
41
42 CONSTANT: kIONameMatchedKey   "IONameMatched"
43
44 CONSTANT: kIOMatchCategoryKey   "IOMatchCategory"
45 CONSTANT: kIODefaultMatchCategoryKey  "IODefaultMatchCategory"
46
47 CONSTANT: kIOUserClientClassKey   "IOUserClientClass"
48
49 CONSTANT: kIOUserClientCrossEndianKey   "IOUserClientCrossEndian"
50 CONSTANT: kIOUserClientCrossEndianCompatibleKey  "IOUserClientCrossEndianCompatible"
51 CONSTANT: kIOUserClientSharedInstanceKey   "IOUserClientSharedInstance"
52
53 CONSTANT: kIOPublishNotification   "IOServicePublish"
54 CONSTANT: kIOFirstPublishNotification  "IOServiceFirstPublish"
55 CONSTANT: kIOMatchedNotification   "IOServiceMatched"
56 CONSTANT: kIOFirstMatchNotification  "IOServiceFirstMatch"
57 CONSTANT: kIOTerminatedNotification  "IOServiceTerminate"
58
59 CONSTANT: kIOGeneralInterest   "IOGeneralInterest"
60 CONSTANT: kIOBusyInterest    "IOBusyInterest"
61 CONSTANT: kIOAppPowerStateInterest  "IOAppPowerStateInterest"
62 CONSTANT: kIOPriorityPowerStateInterest  "IOPriorityPowerStateInterest"
63
64 CONSTANT: kIOPlatformDeviceMessageKey "IOPlatformDeviceMessage"
65
66 CONSTANT: kIOCFPlugInTypesKey   "IOCFPlugInTypes"
67
68 CONSTANT: kIOCommandPoolSizeKey         "IOCommandPoolSize"
69
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"
80
81 CONSTANT: kIOIconKey "IOIcon"
82 CONSTANT: kIOBundleResourceFileKey "IOBundleResourceFile"
83
84 CONSTANT: kIOBusBadgeKey "IOBusBadge"
85 CONSTANT: kIODeviceIconKey "IODeviceIcon"
86
87 CONSTANT: kIOPlatformSerialNumberKey  "IOPlatformSerialNumber" 
88
89 CONSTANT: kIOPlatformUUIDKey  "IOPlatformUUID" 
90
91 CONSTANT: kIONVRAMDeletePropertyKey  "IONVRAM-DELETE-PROPERTY"
92 CONSTANT: kIODTNVRAMPanicInfoKey   "aapl,panic-info"
93
94 CONSTANT: kIOBootDeviceKey "IOBootDevice"  
95 CONSTANT: kIOBootDevicePathKey "IOBootDevicePath" 
96 CONSTANT: kIOBootDeviceSizeKey "IOBootDeviceSize" 
97
98 CONSTANT: kOSBuildVersionKey   "OS Build Version"
99
100 CONSTANT: kNilOptions 0
101
102 CONSTANT: MACH_PORT_NULL 0
103 CONSTANT: KERN_SUCCESS 0
104
105 FUNCTION: IOReturn IOMasterPort ( mach_port_t bootstrap, mach_port_t* master ) ;
106
107 FUNCTION: CFDictionaryRef IOServiceMatching ( c-string name ) ;
108 FUNCTION: CFDictionaryRef IOServiceNameMatching ( c-string name ) ;
109 FUNCTION: CFDictionaryRef IOBSDNameMatching ( c-string name ) ;
110
111 FUNCTION: IOReturn IOObjectRetain ( io_object_t o ) ;
112 FUNCTION: IOReturn IOObjectRelease ( io_object_t o ) ;
113
114 FUNCTION: IOReturn IOServiceGetMatchingServices ( mach_port_t master, CFDictionaryRef matchingDict, io_iterator_t* iterator ) ;
115
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 ) ;
119
120 FUNCTION: IOReturn IORegistryEntryGetPath ( io_registry_entry_t entry, io_name_t plane, io_string_t path ) ;
121
122 FUNCTION: IOReturn IORegistryEntryCreateCFProperties ( io_registry_entry_t entry, CFMutableDictionaryRef properties, CFAllocatorRef allocator, IOOptionBits options ) ;
123
124 FUNCTION: c-string mach_error_string ( IOReturn error ) ;
125
126 TUPLE: mach-error error-code error-string ;
127 : <mach-error> ( code -- error )
128     dup mach_error_string \ mach-error boa ;
129
130 : mach-error ( return -- )
131     dup KERN_SUCCESS = [ drop ] [ <mach-error> throw ] if ;
132
133 : master-port ( -- port )
134     MACH_PORT_NULL { uint } [ IOMasterPort mach-error ] [ ] with-out-parameters ;
135
136 : io-services-matching-dictionary ( nsdictionary -- iterator )
137     master-port swap
138     { uint } [ IOServiceGetMatchingServices mach-error ] [ ] with-out-parameters ;
139
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 ;
146
147 : retain-io-object ( o -- o )
148     [ IOObjectRetain mach-error ] keep ;
149 : release-io-object ( o -- )
150     IOObjectRelease mach-error ;
151
152 : io-objects-from-iterator* ( i -- i array )
153     [ dup IOIteratorNext dup MACH_PORT_NULL = not ] [ ] produce nip ;
154
155 : io-objects-from-iterator ( i -- array )
156     io-objects-from-iterator* [ release-io-object ] dip ;
157     
158 : properties-from-io-object ( o -- o nsdictionary )
159     dup f <void*> [
160         kCFAllocatorDefault kNilOptions
161         IORegistryEntryCreateCFProperties mach-error
162     ]
163     keep *void* ;
164