-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathLooperEvents.swift
More file actions
96 lines (78 loc) · 2.65 KB
/
LooperEvents.swift
File metadata and controls
96 lines (78 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// LooperEvents.swift
// SwiftAndroid
//
// Created by Alsey Coleman Miller on 7/6/25.
//
#if os(Android)
import Android
import CAndroidNDK
#endif
public extension Looper {
/**
* Flags for file descriptor events that a looper can monitor.
*
* These flag bits can be combined to monitor multiple events at once.
*/
struct Events: OptionSet, Sendable {
public typealias RawValue = Int
public var rawValue: Int
public init(rawValue: Int) {
self.init(rawValue)
}
private init(_ raw: Int) {
self.rawValue = raw
}
}
}
// MARK: - Constants
public extension Looper.Events {
/**
* The file descriptor is available for read operations.
*/
static var input: Looper.Events { .init(ALOOPER_EVENT_INPUT) }
/**
* The file descriptor is available for write operations.
*/
static var output: Looper.Events { .init(ALOOPER_EVENT_OUTPUT) }
/**
* The file descriptor has encountered an error condition.
*
* The looper always sends notifications about errors; it is not necessary
* to specify this event flag in the requested event set.
*/
static var error: Looper.Events { .init(ALOOPER_EVENT_ERROR) }
/**
* The file descriptor was hung up.
* For example, indicates that the remote end of a pipe or socket was closed.
*
* The looper always sends notifications about hangups; it is not necessary
* to specify this event flag in the requested event set.
*/
static var hangup: Looper.Events { .init(ALOOPER_EVENT_HANGUP)}
/**
* The file descriptor is invalid.
* For example, the file descriptor was closed prematurely.
*
* The looper always sends notifications about invalid file descriptors; it is not necessary
* to specify this event flag in the requested event set.
*/
static var invalid: Looper.Events { .init(ALOOPER_EVENT_INVALID) }
}
// MARK: - CustomStringConvertible
extension Looper.Events: CustomStringConvertible, CustomDebugStringConvertible {
/// A textual representation of the binder object flags.
@inline(never)
public var description: String {
let descriptions: [(Looper.Events, StaticString)] = [
(.input, ".input"),
(.output, ".output"),
(.error, ".error"),
(.hangup, ".hangup"),
(.invalid, ".invalid")
]
return _buildDescription(descriptions)
}
/// A textual representation of the binder object flags, suitable for debugging.
public var debugDescription: String { self.description }
}