github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/cecprivate/apis_js_wasm.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright 2023 The Prime Citizens 3 4 package cecprivate 5 6 import ( 7 "github.com/primecitizens/pcz/std/core/abi" 8 "github.com/primecitizens/pcz/std/ffi/js" 9 "github.com/primecitizens/pcz/std/plat/js/webext/cecprivate/bindings" 10 ) 11 12 type ChangePowerStateCallbackFunc func(this js.Ref) js.Ref 13 14 func (fn ChangePowerStateCallbackFunc) Register() js.Func[func()] { 15 return js.RegisterCallback[func()]( 16 fn, abi.FuncPCABIInternal(fn), 17 ) 18 } 19 20 func (fn ChangePowerStateCallbackFunc) DispatchCallback( 21 targetPC uintptr, ctx *js.CallbackContext, 22 ) { 23 args := ctx.Args() 24 if len(args) != 0+1 /* js this */ || 25 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 26 js.ThrowInvalidCallbackInvocation() 27 } 28 29 if ctx.Return(fn( 30 args[0], 31 )) { 32 return 33 } 34 35 js.ThrowCallbackValueNotReturned() 36 } 37 38 type ChangePowerStateCallback[T any] struct { 39 Fn func(arg T, this js.Ref) js.Ref 40 Arg T 41 } 42 43 func (cb *ChangePowerStateCallback[T]) Register() js.Func[func()] { 44 return js.RegisterCallback[func()]( 45 cb, abi.FuncPCABIInternal(cb.Fn), 46 ) 47 } 48 49 func (cb *ChangePowerStateCallback[T]) DispatchCallback( 50 targetPC uintptr, ctx *js.CallbackContext, 51 ) { 52 args := ctx.Args() 53 if len(args) != 0+1 /* js this */ || 54 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 55 js.ThrowInvalidCallbackInvocation() 56 } 57 58 if ctx.Return(cb.Fn( 59 cb.Arg, 60 args[0], 61 )) { 62 return 63 } 64 65 js.ThrowCallbackValueNotReturned() 66 } 67 68 type DisplayCecPowerState uint32 69 70 const ( 71 _ DisplayCecPowerState = iota 72 73 DisplayCecPowerState_ERROR 74 DisplayCecPowerState_ADAPTER_NOT_CONFIGURED 75 DisplayCecPowerState_NO_DEVICE 76 DisplayCecPowerState_ON 77 DisplayCecPowerState_STANDBY 78 DisplayCecPowerState_TRANSITIONING_TO_ON 79 DisplayCecPowerState_TRANSITIONING_TO_STANDBY 80 DisplayCecPowerState_UNKNOWN 81 ) 82 83 func (DisplayCecPowerState) FromRef(str js.Ref) DisplayCecPowerState { 84 return DisplayCecPowerState(bindings.ConstOfDisplayCecPowerState(str)) 85 } 86 87 func (x DisplayCecPowerState) String() (string, bool) { 88 switch x { 89 case DisplayCecPowerState_ERROR: 90 return "error", true 91 case DisplayCecPowerState_ADAPTER_NOT_CONFIGURED: 92 return "adapterNotConfigured", true 93 case DisplayCecPowerState_NO_DEVICE: 94 return "noDevice", true 95 case DisplayCecPowerState_ON: 96 return "on", true 97 case DisplayCecPowerState_STANDBY: 98 return "standby", true 99 case DisplayCecPowerState_TRANSITIONING_TO_ON: 100 return "transitioningToOn", true 101 case DisplayCecPowerState_TRANSITIONING_TO_STANDBY: 102 return "transitioningToStandby", true 103 case DisplayCecPowerState_UNKNOWN: 104 return "unknown", true 105 default: 106 return "", false 107 } 108 } 109 110 type DisplayCecPowerStateCallbackFunc func(this js.Ref, powerStates js.Array[DisplayCecPowerState]) js.Ref 111 112 func (fn DisplayCecPowerStateCallbackFunc) Register() js.Func[func(powerStates js.Array[DisplayCecPowerState])] { 113 return js.RegisterCallback[func(powerStates js.Array[DisplayCecPowerState])]( 114 fn, abi.FuncPCABIInternal(fn), 115 ) 116 } 117 118 func (fn DisplayCecPowerStateCallbackFunc) DispatchCallback( 119 targetPC uintptr, ctx *js.CallbackContext, 120 ) { 121 args := ctx.Args() 122 if len(args) != 1+1 /* js this */ || 123 targetPC != uintptr(abi.FuncPCABIInternal(fn)) { 124 js.ThrowInvalidCallbackInvocation() 125 } 126 127 if ctx.Return(fn( 128 args[0], 129 130 js.Array[DisplayCecPowerState]{}.FromRef(args[0+1]), 131 )) { 132 return 133 } 134 135 js.ThrowCallbackValueNotReturned() 136 } 137 138 type DisplayCecPowerStateCallback[T any] struct { 139 Fn func(arg T, this js.Ref, powerStates js.Array[DisplayCecPowerState]) js.Ref 140 Arg T 141 } 142 143 func (cb *DisplayCecPowerStateCallback[T]) Register() js.Func[func(powerStates js.Array[DisplayCecPowerState])] { 144 return js.RegisterCallback[func(powerStates js.Array[DisplayCecPowerState])]( 145 cb, abi.FuncPCABIInternal(cb.Fn), 146 ) 147 } 148 149 func (cb *DisplayCecPowerStateCallback[T]) DispatchCallback( 150 targetPC uintptr, ctx *js.CallbackContext, 151 ) { 152 args := ctx.Args() 153 if len(args) != 1+1 /* js this */ || 154 targetPC != uintptr(abi.FuncPCABIInternal(cb.Fn)) { 155 js.ThrowInvalidCallbackInvocation() 156 } 157 158 if ctx.Return(cb.Fn( 159 cb.Arg, 160 args[0], 161 162 js.Array[DisplayCecPowerState]{}.FromRef(args[0+1]), 163 )) { 164 return 165 } 166 167 js.ThrowCallbackValueNotReturned() 168 } 169 170 // HasFuncQueryDisplayCecPowerState returns true if the function "WEBEXT.cecPrivate.queryDisplayCecPowerState" exists. 171 func HasFuncQueryDisplayCecPowerState() bool { 172 return js.True == bindings.HasFuncQueryDisplayCecPowerState() 173 } 174 175 // FuncQueryDisplayCecPowerState returns the function "WEBEXT.cecPrivate.queryDisplayCecPowerState". 176 func FuncQueryDisplayCecPowerState() (fn js.Func[func() js.Promise[js.Array[DisplayCecPowerState]]]) { 177 bindings.FuncQueryDisplayCecPowerState( 178 js.Pointer(&fn), 179 ) 180 return 181 } 182 183 // QueryDisplayCecPowerState calls the function "WEBEXT.cecPrivate.queryDisplayCecPowerState" directly. 184 func QueryDisplayCecPowerState() (ret js.Promise[js.Array[DisplayCecPowerState]]) { 185 bindings.CallQueryDisplayCecPowerState( 186 js.Pointer(&ret), 187 ) 188 189 return 190 } 191 192 // TryQueryDisplayCecPowerState calls the function "WEBEXT.cecPrivate.queryDisplayCecPowerState" 193 // in a try/catch block and returns (_, err, ok = false) when it went through 194 // the catch clause. 195 func TryQueryDisplayCecPowerState() (ret js.Promise[js.Array[DisplayCecPowerState]], exception js.Any, ok bool) { 196 ok = js.True == bindings.TryQueryDisplayCecPowerState( 197 js.Pointer(&ret), js.Pointer(&exception), 198 ) 199 200 return 201 } 202 203 // HasFuncSendStandBy returns true if the function "WEBEXT.cecPrivate.sendStandBy" exists. 204 func HasFuncSendStandBy() bool { 205 return js.True == bindings.HasFuncSendStandBy() 206 } 207 208 // FuncSendStandBy returns the function "WEBEXT.cecPrivate.sendStandBy". 209 func FuncSendStandBy() (fn js.Func[func() js.Promise[js.Void]]) { 210 bindings.FuncSendStandBy( 211 js.Pointer(&fn), 212 ) 213 return 214 } 215 216 // SendStandBy calls the function "WEBEXT.cecPrivate.sendStandBy" directly. 217 func SendStandBy() (ret js.Promise[js.Void]) { 218 bindings.CallSendStandBy( 219 js.Pointer(&ret), 220 ) 221 222 return 223 } 224 225 // TrySendStandBy calls the function "WEBEXT.cecPrivate.sendStandBy" 226 // in a try/catch block and returns (_, err, ok = false) when it went through 227 // the catch clause. 228 func TrySendStandBy() (ret js.Promise[js.Void], exception js.Any, ok bool) { 229 ok = js.True == bindings.TrySendStandBy( 230 js.Pointer(&ret), js.Pointer(&exception), 231 ) 232 233 return 234 } 235 236 // HasFuncSendWakeUp returns true if the function "WEBEXT.cecPrivate.sendWakeUp" exists. 237 func HasFuncSendWakeUp() bool { 238 return js.True == bindings.HasFuncSendWakeUp() 239 } 240 241 // FuncSendWakeUp returns the function "WEBEXT.cecPrivate.sendWakeUp". 242 func FuncSendWakeUp() (fn js.Func[func() js.Promise[js.Void]]) { 243 bindings.FuncSendWakeUp( 244 js.Pointer(&fn), 245 ) 246 return 247 } 248 249 // SendWakeUp calls the function "WEBEXT.cecPrivate.sendWakeUp" directly. 250 func SendWakeUp() (ret js.Promise[js.Void]) { 251 bindings.CallSendWakeUp( 252 js.Pointer(&ret), 253 ) 254 255 return 256 } 257 258 // TrySendWakeUp calls the function "WEBEXT.cecPrivate.sendWakeUp" 259 // in a try/catch block and returns (_, err, ok = false) when it went through 260 // the catch clause. 261 func TrySendWakeUp() (ret js.Promise[js.Void], exception js.Any, ok bool) { 262 ok = js.True == bindings.TrySendWakeUp( 263 js.Pointer(&ret), js.Pointer(&exception), 264 ) 265 266 return 267 }