scoop:scoop.window:0.1.0
src/native/results.scoop
Selected production source · src/native/results.scoop
1
package scoop.window3
@CLayout4
internal struct NativeCreateResult(val pointer: Ptr<Unit>?, val error: Long)6
internal fun checkNativeStatus(code: Long, operation: String) {7
if (code == -1L) throw WindowException(operation, WindowErrorKind.Unsupported)8
if (code == -2L) throw WindowException(operation, WindowErrorKind.Unavailable)9
if (code == -3L) throw WindowException(operation, WindowErrorKind.Disconnected)10
if (code == -4L) throw WindowException(operation, WindowErrorKind.InvalidState)11
if (code == -5L) throw WindowException(operation, WindowErrorKind.ResourceBusy)12
if (code != 0L)13
throw WindowException(operation, WindowErrorKind.NativeFailure, nativeCode = Some(code))14
}16
internal fun nativeRequestStatus(17
code: Long,18
operation: String,19
success: RequestStatus = RequestStatus.Applied20
): RequestStatus {21
if (code == -1L) return RequestStatus.Unsupported22
checkNativeStatus(code, operation)23
return success24
}26
internal fun requireCreationStatus(status: RequestStatus, operation: String) {27
if (status == RequestStatus.Unsupported)28
throw WindowException(operation, WindowErrorKind.Unsupported)29
}31
internal fun created(result: NativeCreateResult, operation: String): Ptr<Unit> {32
when (result.pointer) {33
case Some(val pointer) -> return pointer35
case None -> {36
checkNativeStatus(result.error, operation)37
throw WindowException(operation, WindowErrorKind.NativeFailure)38
}39
}40
}42
internal fun flag(value: Boolean): Int = if (value) 1 else 0