Skip to content

Commit 5323d98

Browse files
committed
Add hardware syscalls
1 parent 1c70ca4 commit 5323d98

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// Syscalls.swift
3+
// SwiftAndroid
4+
//
5+
// Created by Alsey Coleman Miller on 7/6/25.
6+
//
7+
8+
#if canImport(Darwin)
9+
import Darwin
10+
#elseif canImport(Glibc)
11+
import Glibc
12+
#endif
13+
14+
#if !os(Android)
15+
16+
func stub() -> Never {
17+
fatalError("Not running on Android")
18+
}
19+
20+
// MARK: - ASensorEvent
21+
22+
/**
23+
* A sensor event payload.
24+
*
25+
* This struct must match the C layout of ASensorEvent exactly.
26+
* Total size: 104 bytes on all supported Android ABI targets.
27+
* version(4) + sensor(4) + type(4) + reserved0(4) +
28+
* timestamp(8) + data_union(64) + flags(4) + reserved1(12)
29+
*/
30+
public struct ASensorEvent {
31+
public var version: Int32 // sizeof(struct ASensorEvent)
32+
public var sensor: Int32 // sensor identifier
33+
public var type: Int32 // sensor type
34+
public var reserved0: Int32
35+
public var timestamp: Int64 // nanoseconds
36+
// Data union: largest member is float[16] = 64 bytes.
37+
// Represented here as eight UInt64 to keep the layout correct
38+
// without needing to replicate the full C union hierarchy.
39+
internal var _data: (UInt64, UInt64, UInt64, UInt64, UInt64, UInt64, UInt64, UInt64)
40+
public var flags: UInt32
41+
internal var _reserved1: (Int32, Int32, Int32)
42+
43+
public init() {
44+
version = 0; sensor = 0; type = 0; reserved0 = 0; timestamp = 0
45+
_data = (0, 0, 0, 0, 0, 0, 0, 0)
46+
flags = 0; _reserved1 = (0, 0, 0)
47+
}
48+
}
49+
50+
// MARK: - ASensorManager
51+
52+
func ASensorManager_getInstanceForPackage(_ packageName: UnsafePointer<CChar>?) -> OpaquePointer? { stub() }
53+
func ASensorManager_getSensorList(_ manager: OpaquePointer, _ list: UnsafeMutablePointer<UnsafePointer<OpaquePointer>?>) -> Int32 { stub() }
54+
func ASensorManager_getDefaultSensor(_ manager: OpaquePointer, _ type: Int32) -> OpaquePointer? { stub() }
55+
func ASensorManager_getDefaultSensorEx(_ manager: OpaquePointer, _ type: Int32, _ wakeUp: Bool) -> OpaquePointer? { stub() }
56+
func ASensorManager_createEventQueue(_ manager: OpaquePointer, _ looper: OpaquePointer, _ ident: Int32, _ callback: ALooper_callbackFunc?, _ data: UnsafeMutableRawPointer?) -> OpaquePointer? { stub() }
57+
func ASensorManager_destroyEventQueue(_ manager: OpaquePointer, _ queue: OpaquePointer) -> Int32 { stub() }
58+
59+
// MARK: - ASensor
60+
61+
func ASensor_getName(_ sensor: OpaquePointer) -> UnsafePointer<CChar>? { stub() }
62+
func ASensor_getVendor(_ sensor: OpaquePointer) -> UnsafePointer<CChar>? { stub() }
63+
func ASensor_getType(_ sensor: OpaquePointer) -> Int32 { stub() }
64+
func ASensor_getResolution(_ sensor: OpaquePointer) -> Float { stub() }
65+
func ASensor_getMinDelay(_ sensor: OpaquePointer) -> Int32 { stub() }
66+
func ASensor_getFifoMaxEventCount(_ sensor: OpaquePointer) -> Int32 { stub() }
67+
func ASensor_getFifoReservedEventCount(_ sensor: OpaquePointer) -> Int32 { stub() }
68+
func ASensor_getStringType(_ sensor: OpaquePointer) -> UnsafePointer<CChar>? { stub() }
69+
func ASensor_getReportingMode(_ sensor: OpaquePointer) -> Int32 { stub() }
70+
func ASensor_isWakeUpSensor(_ sensor: OpaquePointer) -> Bool { stub() }
71+
func ASensor_getHandle(_ sensor: OpaquePointer) -> Int32 { stub() }
72+
73+
// MARK: - ASensorEventQueue
74+
75+
func ASensorEventQueue_registerSensor(_ queue: OpaquePointer, _ sensor: OpaquePointer, _ samplingPeriodUs: Int32, _ maxBatchReportLatencyUs: Int64) -> Int32 { stub() }
76+
func ASensorEventQueue_enableSensor(_ queue: OpaquePointer, _ sensor: OpaquePointer) -> Int32 { stub() }
77+
func ASensorEventQueue_disableSensor(_ queue: OpaquePointer, _ sensor: OpaquePointer) -> Int32 { stub() }
78+
func ASensorEventQueue_setEventRate(_ queue: OpaquePointer, _ sensor: OpaquePointer, _ usec: Int32) -> Int32 { stub() }
79+
func ASensorEventQueue_hasEvents(_ queue: OpaquePointer) -> Int32 { stub() }
80+
func ASensorEventQueue_getEvents(_ queue: OpaquePointer, _ events: UnsafeMutablePointer<ASensorEvent>, _ count: Int) -> Int { stub() }
81+
func ASensorEventQueue_requestAdditionalInfoEvents(_ queue: OpaquePointer, _ enable: Bool) -> Int32 { stub() }
82+
83+
#endif

0 commit comments

Comments
 (0)