github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/printerprovider/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/printerprovider", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "constof_PrintError": (ref: heap.Ref<string>): number => { 8 const idx = ["OK", "FAILED", "INVALID_TICKET", "INVALID_DATA"].indexOf(A.H.get(ref)); 9 return idx < 0 ? 0 : idx + 1; 10 }, 11 12 "store_PrintJob": (ptr: Pointer, ref: heap.Ref<any>) => { 13 const x = A.H.get<any>(ref); 14 15 if (typeof x === "undefined") { 16 A.store.Bool(ptr + 20, false); 17 A.store.Ref(ptr + 0, undefined); 18 A.store.Ref(ptr + 4, undefined); 19 A.store.Ref(ptr + 8, undefined); 20 A.store.Ref(ptr + 12, undefined); 21 A.store.Ref(ptr + 16, undefined); 22 } else { 23 A.store.Bool(ptr + 20, true); 24 A.store.Ref(ptr + 0, x["printerId"]); 25 A.store.Ref(ptr + 4, x["title"]); 26 A.store.Ref(ptr + 8, x["ticket"]); 27 A.store.Ref(ptr + 12, x["contentType"]); 28 A.store.Ref(ptr + 16, x["document"]); 29 } 30 }, 31 "load_PrintJob": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 32 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 33 34 x["printerId"] = A.load.Ref(ptr + 0, undefined); 35 x["title"] = A.load.Ref(ptr + 4, undefined); 36 x["ticket"] = A.load.Ref(ptr + 8, undefined); 37 x["contentType"] = A.load.Ref(ptr + 12, undefined); 38 x["document"] = A.load.Ref(ptr + 16, undefined); 39 return create === A.H.TRUE ? A.H.push(x) : ref; 40 }, 41 42 "store_PrinterInfo": (ptr: Pointer, ref: heap.Ref<any>) => { 43 const x = A.H.get<any>(ref); 44 45 if (typeof x === "undefined") { 46 A.store.Bool(ptr + 12, false); 47 A.store.Ref(ptr + 0, undefined); 48 A.store.Ref(ptr + 4, undefined); 49 A.store.Ref(ptr + 8, undefined); 50 } else { 51 A.store.Bool(ptr + 12, true); 52 A.store.Ref(ptr + 0, x["id"]); 53 A.store.Ref(ptr + 4, x["name"]); 54 A.store.Ref(ptr + 8, x["description"]); 55 } 56 }, 57 "load_PrinterInfo": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 58 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 59 60 x["id"] = A.load.Ref(ptr + 0, undefined); 61 x["name"] = A.load.Ref(ptr + 4, undefined); 62 x["description"] = A.load.Ref(ptr + 8, undefined); 63 return create === A.H.TRUE ? A.H.push(x) : ref; 64 }, 65 "has_OnGetCapabilityRequested": (): heap.Ref<boolean> => { 66 if ( 67 WEBEXT?.printerProvider?.onGetCapabilityRequested && 68 "addListener" in WEBEXT?.printerProvider?.onGetCapabilityRequested 69 ) { 70 return A.H.TRUE; 71 } 72 return A.H.FALSE; 73 }, 74 "func_OnGetCapabilityRequested": (fn: Pointer): void => { 75 A.store.Ref(fn, WEBEXT.printerProvider.onGetCapabilityRequested.addListener); 76 }, 77 "call_OnGetCapabilityRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 78 const _ret = WEBEXT.printerProvider.onGetCapabilityRequested.addListener(A.H.get<object>(callback)); 79 }, 80 "try_OnGetCapabilityRequested": ( 81 retPtr: Pointer, 82 errPtr: Pointer, 83 callback: heap.Ref<object> 84 ): heap.Ref<boolean> => { 85 try { 86 const _ret = WEBEXT.printerProvider.onGetCapabilityRequested.addListener(A.H.get<object>(callback)); 87 return A.H.TRUE; 88 } catch (err: any) { 89 A.store.Ref(errPtr, err); 90 return A.H.FALSE; 91 } 92 }, 93 "has_OffGetCapabilityRequested": (): heap.Ref<boolean> => { 94 if ( 95 WEBEXT?.printerProvider?.onGetCapabilityRequested && 96 "removeListener" in WEBEXT?.printerProvider?.onGetCapabilityRequested 97 ) { 98 return A.H.TRUE; 99 } 100 return A.H.FALSE; 101 }, 102 "func_OffGetCapabilityRequested": (fn: Pointer): void => { 103 A.store.Ref(fn, WEBEXT.printerProvider.onGetCapabilityRequested.removeListener); 104 }, 105 "call_OffGetCapabilityRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 106 const _ret = WEBEXT.printerProvider.onGetCapabilityRequested.removeListener(A.H.get<object>(callback)); 107 }, 108 "try_OffGetCapabilityRequested": ( 109 retPtr: Pointer, 110 errPtr: Pointer, 111 callback: heap.Ref<object> 112 ): heap.Ref<boolean> => { 113 try { 114 const _ret = WEBEXT.printerProvider.onGetCapabilityRequested.removeListener(A.H.get<object>(callback)); 115 return A.H.TRUE; 116 } catch (err: any) { 117 A.store.Ref(errPtr, err); 118 return A.H.FALSE; 119 } 120 }, 121 "has_HasOnGetCapabilityRequested": (): heap.Ref<boolean> => { 122 if ( 123 WEBEXT?.printerProvider?.onGetCapabilityRequested && 124 "hasListener" in WEBEXT?.printerProvider?.onGetCapabilityRequested 125 ) { 126 return A.H.TRUE; 127 } 128 return A.H.FALSE; 129 }, 130 "func_HasOnGetCapabilityRequested": (fn: Pointer): void => { 131 A.store.Ref(fn, WEBEXT.printerProvider.onGetCapabilityRequested.hasListener); 132 }, 133 "call_HasOnGetCapabilityRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 134 const _ret = WEBEXT.printerProvider.onGetCapabilityRequested.hasListener(A.H.get<object>(callback)); 135 A.store.Bool(retPtr, _ret); 136 }, 137 "try_HasOnGetCapabilityRequested": ( 138 retPtr: Pointer, 139 errPtr: Pointer, 140 callback: heap.Ref<object> 141 ): heap.Ref<boolean> => { 142 try { 143 const _ret = WEBEXT.printerProvider.onGetCapabilityRequested.hasListener(A.H.get<object>(callback)); 144 A.store.Bool(retPtr, _ret); 145 return A.H.TRUE; 146 } catch (err: any) { 147 A.store.Ref(errPtr, err); 148 return A.H.FALSE; 149 } 150 }, 151 "has_OnGetPrintersRequested": (): heap.Ref<boolean> => { 152 if ( 153 WEBEXT?.printerProvider?.onGetPrintersRequested && 154 "addListener" in WEBEXT?.printerProvider?.onGetPrintersRequested 155 ) { 156 return A.H.TRUE; 157 } 158 return A.H.FALSE; 159 }, 160 "func_OnGetPrintersRequested": (fn: Pointer): void => { 161 A.store.Ref(fn, WEBEXT.printerProvider.onGetPrintersRequested.addListener); 162 }, 163 "call_OnGetPrintersRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 164 const _ret = WEBEXT.printerProvider.onGetPrintersRequested.addListener(A.H.get<object>(callback)); 165 }, 166 "try_OnGetPrintersRequested": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 167 try { 168 const _ret = WEBEXT.printerProvider.onGetPrintersRequested.addListener(A.H.get<object>(callback)); 169 return A.H.TRUE; 170 } catch (err: any) { 171 A.store.Ref(errPtr, err); 172 return A.H.FALSE; 173 } 174 }, 175 "has_OffGetPrintersRequested": (): heap.Ref<boolean> => { 176 if ( 177 WEBEXT?.printerProvider?.onGetPrintersRequested && 178 "removeListener" in WEBEXT?.printerProvider?.onGetPrintersRequested 179 ) { 180 return A.H.TRUE; 181 } 182 return A.H.FALSE; 183 }, 184 "func_OffGetPrintersRequested": (fn: Pointer): void => { 185 A.store.Ref(fn, WEBEXT.printerProvider.onGetPrintersRequested.removeListener); 186 }, 187 "call_OffGetPrintersRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 188 const _ret = WEBEXT.printerProvider.onGetPrintersRequested.removeListener(A.H.get<object>(callback)); 189 }, 190 "try_OffGetPrintersRequested": ( 191 retPtr: Pointer, 192 errPtr: Pointer, 193 callback: heap.Ref<object> 194 ): heap.Ref<boolean> => { 195 try { 196 const _ret = WEBEXT.printerProvider.onGetPrintersRequested.removeListener(A.H.get<object>(callback)); 197 return A.H.TRUE; 198 } catch (err: any) { 199 A.store.Ref(errPtr, err); 200 return A.H.FALSE; 201 } 202 }, 203 "has_HasOnGetPrintersRequested": (): heap.Ref<boolean> => { 204 if ( 205 WEBEXT?.printerProvider?.onGetPrintersRequested && 206 "hasListener" in WEBEXT?.printerProvider?.onGetPrintersRequested 207 ) { 208 return A.H.TRUE; 209 } 210 return A.H.FALSE; 211 }, 212 "func_HasOnGetPrintersRequested": (fn: Pointer): void => { 213 A.store.Ref(fn, WEBEXT.printerProvider.onGetPrintersRequested.hasListener); 214 }, 215 "call_HasOnGetPrintersRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 216 const _ret = WEBEXT.printerProvider.onGetPrintersRequested.hasListener(A.H.get<object>(callback)); 217 A.store.Bool(retPtr, _ret); 218 }, 219 "try_HasOnGetPrintersRequested": ( 220 retPtr: Pointer, 221 errPtr: Pointer, 222 callback: heap.Ref<object> 223 ): heap.Ref<boolean> => { 224 try { 225 const _ret = WEBEXT.printerProvider.onGetPrintersRequested.hasListener(A.H.get<object>(callback)); 226 A.store.Bool(retPtr, _ret); 227 return A.H.TRUE; 228 } catch (err: any) { 229 A.store.Ref(errPtr, err); 230 return A.H.FALSE; 231 } 232 }, 233 "has_OnGetUsbPrinterInfoRequested": (): heap.Ref<boolean> => { 234 if ( 235 WEBEXT?.printerProvider?.onGetUsbPrinterInfoRequested && 236 "addListener" in WEBEXT?.printerProvider?.onGetUsbPrinterInfoRequested 237 ) { 238 return A.H.TRUE; 239 } 240 return A.H.FALSE; 241 }, 242 "func_OnGetUsbPrinterInfoRequested": (fn: Pointer): void => { 243 A.store.Ref(fn, WEBEXT.printerProvider.onGetUsbPrinterInfoRequested.addListener); 244 }, 245 "call_OnGetUsbPrinterInfoRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 246 const _ret = WEBEXT.printerProvider.onGetUsbPrinterInfoRequested.addListener(A.H.get<object>(callback)); 247 }, 248 "try_OnGetUsbPrinterInfoRequested": ( 249 retPtr: Pointer, 250 errPtr: Pointer, 251 callback: heap.Ref<object> 252 ): heap.Ref<boolean> => { 253 try { 254 const _ret = WEBEXT.printerProvider.onGetUsbPrinterInfoRequested.addListener(A.H.get<object>(callback)); 255 return A.H.TRUE; 256 } catch (err: any) { 257 A.store.Ref(errPtr, err); 258 return A.H.FALSE; 259 } 260 }, 261 "has_OffGetUsbPrinterInfoRequested": (): heap.Ref<boolean> => { 262 if ( 263 WEBEXT?.printerProvider?.onGetUsbPrinterInfoRequested && 264 "removeListener" in WEBEXT?.printerProvider?.onGetUsbPrinterInfoRequested 265 ) { 266 return A.H.TRUE; 267 } 268 return A.H.FALSE; 269 }, 270 "func_OffGetUsbPrinterInfoRequested": (fn: Pointer): void => { 271 A.store.Ref(fn, WEBEXT.printerProvider.onGetUsbPrinterInfoRequested.removeListener); 272 }, 273 "call_OffGetUsbPrinterInfoRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 274 const _ret = WEBEXT.printerProvider.onGetUsbPrinterInfoRequested.removeListener(A.H.get<object>(callback)); 275 }, 276 "try_OffGetUsbPrinterInfoRequested": ( 277 retPtr: Pointer, 278 errPtr: Pointer, 279 callback: heap.Ref<object> 280 ): heap.Ref<boolean> => { 281 try { 282 const _ret = WEBEXT.printerProvider.onGetUsbPrinterInfoRequested.removeListener(A.H.get<object>(callback)); 283 return A.H.TRUE; 284 } catch (err: any) { 285 A.store.Ref(errPtr, err); 286 return A.H.FALSE; 287 } 288 }, 289 "has_HasOnGetUsbPrinterInfoRequested": (): heap.Ref<boolean> => { 290 if ( 291 WEBEXT?.printerProvider?.onGetUsbPrinterInfoRequested && 292 "hasListener" in WEBEXT?.printerProvider?.onGetUsbPrinterInfoRequested 293 ) { 294 return A.H.TRUE; 295 } 296 return A.H.FALSE; 297 }, 298 "func_HasOnGetUsbPrinterInfoRequested": (fn: Pointer): void => { 299 A.store.Ref(fn, WEBEXT.printerProvider.onGetUsbPrinterInfoRequested.hasListener); 300 }, 301 "call_HasOnGetUsbPrinterInfoRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 302 const _ret = WEBEXT.printerProvider.onGetUsbPrinterInfoRequested.hasListener(A.H.get<object>(callback)); 303 A.store.Bool(retPtr, _ret); 304 }, 305 "try_HasOnGetUsbPrinterInfoRequested": ( 306 retPtr: Pointer, 307 errPtr: Pointer, 308 callback: heap.Ref<object> 309 ): heap.Ref<boolean> => { 310 try { 311 const _ret = WEBEXT.printerProvider.onGetUsbPrinterInfoRequested.hasListener(A.H.get<object>(callback)); 312 A.store.Bool(retPtr, _ret); 313 return A.H.TRUE; 314 } catch (err: any) { 315 A.store.Ref(errPtr, err); 316 return A.H.FALSE; 317 } 318 }, 319 "has_OnPrintRequested": (): heap.Ref<boolean> => { 320 if (WEBEXT?.printerProvider?.onPrintRequested && "addListener" in WEBEXT?.printerProvider?.onPrintRequested) { 321 return A.H.TRUE; 322 } 323 return A.H.FALSE; 324 }, 325 "func_OnPrintRequested": (fn: Pointer): void => { 326 A.store.Ref(fn, WEBEXT.printerProvider.onPrintRequested.addListener); 327 }, 328 "call_OnPrintRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 329 const _ret = WEBEXT.printerProvider.onPrintRequested.addListener(A.H.get<object>(callback)); 330 }, 331 "try_OnPrintRequested": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 332 try { 333 const _ret = WEBEXT.printerProvider.onPrintRequested.addListener(A.H.get<object>(callback)); 334 return A.H.TRUE; 335 } catch (err: any) { 336 A.store.Ref(errPtr, err); 337 return A.H.FALSE; 338 } 339 }, 340 "has_OffPrintRequested": (): heap.Ref<boolean> => { 341 if (WEBEXT?.printerProvider?.onPrintRequested && "removeListener" in WEBEXT?.printerProvider?.onPrintRequested) { 342 return A.H.TRUE; 343 } 344 return A.H.FALSE; 345 }, 346 "func_OffPrintRequested": (fn: Pointer): void => { 347 A.store.Ref(fn, WEBEXT.printerProvider.onPrintRequested.removeListener); 348 }, 349 "call_OffPrintRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 350 const _ret = WEBEXT.printerProvider.onPrintRequested.removeListener(A.H.get<object>(callback)); 351 }, 352 "try_OffPrintRequested": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 353 try { 354 const _ret = WEBEXT.printerProvider.onPrintRequested.removeListener(A.H.get<object>(callback)); 355 return A.H.TRUE; 356 } catch (err: any) { 357 A.store.Ref(errPtr, err); 358 return A.H.FALSE; 359 } 360 }, 361 "has_HasOnPrintRequested": (): heap.Ref<boolean> => { 362 if (WEBEXT?.printerProvider?.onPrintRequested && "hasListener" in WEBEXT?.printerProvider?.onPrintRequested) { 363 return A.H.TRUE; 364 } 365 return A.H.FALSE; 366 }, 367 "func_HasOnPrintRequested": (fn: Pointer): void => { 368 A.store.Ref(fn, WEBEXT.printerProvider.onPrintRequested.hasListener); 369 }, 370 "call_HasOnPrintRequested": (retPtr: Pointer, callback: heap.Ref<object>): void => { 371 const _ret = WEBEXT.printerProvider.onPrintRequested.hasListener(A.H.get<object>(callback)); 372 A.store.Bool(retPtr, _ret); 373 }, 374 "try_HasOnPrintRequested": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 375 try { 376 const _ret = WEBEXT.printerProvider.onPrintRequested.hasListener(A.H.get<object>(callback)); 377 A.store.Bool(retPtr, _ret); 378 return A.H.TRUE; 379 } catch (err: any) { 380 A.store.Ref(errPtr, err); 381 return A.H.FALSE; 382 } 383 }, 384 }; 385 });