github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/printing/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/printing", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "constof_PrinterStatus": (ref: heap.Ref<string>): number => { 8 const idx = [ 9 "DOOR_OPEN", 10 "TRAY_MISSING", 11 "OUT_OF_INK", 12 "OUT_OF_PAPER", 13 "OUTPUT_FULL", 14 "PAPER_JAM", 15 "GENERIC_ISSUE", 16 "STOPPED", 17 "UNREACHABLE", 18 "EXPIRED_CERTIFICATE", 19 "AVAILABLE", 20 ].indexOf(A.H.get(ref)); 21 return idx < 0 ? 0 : idx + 1; 22 }, 23 24 "store_GetPrinterInfoResponse": (ptr: Pointer, ref: heap.Ref<any>) => { 25 const x = A.H.get<any>(ref); 26 27 if (typeof x === "undefined") { 28 A.store.Bool(ptr + 8, false); 29 A.store.Ref(ptr + 0, undefined); 30 A.store.Enum(ptr + 4, -1); 31 } else { 32 A.store.Bool(ptr + 8, true); 33 A.store.Ref(ptr + 0, x["capabilities"]); 34 A.store.Enum( 35 ptr + 4, 36 [ 37 "DOOR_OPEN", 38 "TRAY_MISSING", 39 "OUT_OF_INK", 40 "OUT_OF_PAPER", 41 "OUTPUT_FULL", 42 "PAPER_JAM", 43 "GENERIC_ISSUE", 44 "STOPPED", 45 "UNREACHABLE", 46 "EXPIRED_CERTIFICATE", 47 "AVAILABLE", 48 ].indexOf(x["status"] as string) 49 ); 50 } 51 }, 52 "load_GetPrinterInfoResponse": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 53 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 54 55 x["capabilities"] = A.load.Ref(ptr + 0, undefined); 56 x["status"] = A.load.Enum(ptr + 4, [ 57 "DOOR_OPEN", 58 "TRAY_MISSING", 59 "OUT_OF_INK", 60 "OUT_OF_PAPER", 61 "OUTPUT_FULL", 62 "PAPER_JAM", 63 "GENERIC_ISSUE", 64 "STOPPED", 65 "UNREACHABLE", 66 "EXPIRED_CERTIFICATE", 67 "AVAILABLE", 68 ]); 69 return create === A.H.TRUE ? A.H.push(x) : ref; 70 }, 71 "constof_PrinterSource": (ref: heap.Ref<string>): number => { 72 const idx = ["USER", "POLICY"].indexOf(A.H.get(ref)); 73 return idx < 0 ? 0 : idx + 1; 74 }, 75 76 "store_Printer": (ptr: Pointer, ref: heap.Ref<any>) => { 77 const x = A.H.get<any>(ref); 78 79 if (typeof x === "undefined") { 80 A.store.Bool(ptr + 30, false); 81 A.store.Ref(ptr + 0, undefined); 82 A.store.Ref(ptr + 4, undefined); 83 A.store.Ref(ptr + 8, undefined); 84 A.store.Ref(ptr + 12, undefined); 85 A.store.Enum(ptr + 16, -1); 86 A.store.Bool(ptr + 28, false); 87 A.store.Bool(ptr + 20, false); 88 A.store.Bool(ptr + 29, false); 89 A.store.Int32(ptr + 24, 0); 90 } else { 91 A.store.Bool(ptr + 30, true); 92 A.store.Ref(ptr + 0, x["id"]); 93 A.store.Ref(ptr + 4, x["name"]); 94 A.store.Ref(ptr + 8, x["description"]); 95 A.store.Ref(ptr + 12, x["uri"]); 96 A.store.Enum(ptr + 16, ["USER", "POLICY"].indexOf(x["source"] as string)); 97 A.store.Bool(ptr + 28, "isDefault" in x ? true : false); 98 A.store.Bool(ptr + 20, x["isDefault"] ? true : false); 99 A.store.Bool(ptr + 29, "recentlyUsedRank" in x ? true : false); 100 A.store.Int32(ptr + 24, x["recentlyUsedRank"] === undefined ? 0 : (x["recentlyUsedRank"] as number)); 101 } 102 }, 103 "load_Printer": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 104 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 105 106 x["id"] = A.load.Ref(ptr + 0, undefined); 107 x["name"] = A.load.Ref(ptr + 4, undefined); 108 x["description"] = A.load.Ref(ptr + 8, undefined); 109 x["uri"] = A.load.Ref(ptr + 12, undefined); 110 x["source"] = A.load.Enum(ptr + 16, ["USER", "POLICY"]); 111 if (A.load.Bool(ptr + 28)) { 112 x["isDefault"] = A.load.Bool(ptr + 20); 113 } else { 114 delete x["isDefault"]; 115 } 116 if (A.load.Bool(ptr + 29)) { 117 x["recentlyUsedRank"] = A.load.Int32(ptr + 24); 118 } else { 119 delete x["recentlyUsedRank"]; 120 } 121 return create === A.H.TRUE ? A.H.push(x) : ref; 122 }, 123 "constof_JobStatus": (ref: heap.Ref<string>): number => { 124 const idx = ["PENDING", "IN_PROGRESS", "FAILED", "CANCELED", "PRINTED"].indexOf(A.H.get(ref)); 125 return idx < 0 ? 0 : idx + 1; 126 }, 127 128 "has_Properties_MAX_SUBMIT_JOB_CALLS_PER_MINUTE": (self: heap.Ref<any>): heap.Ref<boolean> => { 129 if (WEBEXT?.printing && "MAX_SUBMIT_JOB_CALLS_PER_MINUTE" in WEBEXT?.printing) { 130 return A.H.TRUE; 131 } 132 return A.H.FALSE; 133 }, 134 "func_Properties_MAX_SUBMIT_JOB_CALLS_PER_MINUTE": (self: heap.Ref<any>, fn: Pointer): void => { 135 A.store.Ref(fn, WEBEXT.printing.MAX_SUBMIT_JOB_CALLS_PER_MINUTE); 136 }, 137 138 "call_Properties_MAX_SUBMIT_JOB_CALLS_PER_MINUTE": (self: heap.Ref<object>, retPtr: Pointer): void => { 139 const thiz = A.H.get<any>(self); 140 141 const _ret = Reflect.apply(WEBEXT.printing.MAX_SUBMIT_JOB_CALLS_PER_MINUTE, thiz, []); 142 A.store.Int32(retPtr, _ret); 143 }, 144 "try_Properties_MAX_SUBMIT_JOB_CALLS_PER_MINUTE": ( 145 self: heap.Ref<object>, 146 retPtr: Pointer, 147 errPtr: Pointer 148 ): heap.Ref<boolean> => { 149 try { 150 const thiz = A.H.get<any>(self); 151 152 const _ret = Reflect.apply(WEBEXT.printing.MAX_SUBMIT_JOB_CALLS_PER_MINUTE, thiz, []); 153 A.store.Int32(retPtr, _ret); 154 return A.H.TRUE; 155 } catch (err: any) { 156 A.store.Ref(errPtr, err); 157 return A.H.FALSE; 158 } 159 }, 160 "has_Properties_MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE": (self: heap.Ref<any>): heap.Ref<boolean> => { 161 if (WEBEXT?.printing && "MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE" in WEBEXT?.printing) { 162 return A.H.TRUE; 163 } 164 return A.H.FALSE; 165 }, 166 "func_Properties_MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE": (self: heap.Ref<any>, fn: Pointer): void => { 167 A.store.Ref(fn, WEBEXT.printing.MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE); 168 }, 169 170 "call_Properties_MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE": (self: heap.Ref<object>, retPtr: Pointer): void => { 171 const thiz = A.H.get<any>(self); 172 173 const _ret = Reflect.apply(WEBEXT.printing.MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE, thiz, []); 174 A.store.Int32(retPtr, _ret); 175 }, 176 "try_Properties_MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE": ( 177 self: heap.Ref<object>, 178 retPtr: Pointer, 179 errPtr: Pointer 180 ): heap.Ref<boolean> => { 181 try { 182 const thiz = A.H.get<any>(self); 183 184 const _ret = Reflect.apply(WEBEXT.printing.MAX_GET_PRINTER_INFO_CALLS_PER_MINUTE, thiz, []); 185 A.store.Int32(retPtr, _ret); 186 return A.H.TRUE; 187 } catch (err: any) { 188 A.store.Ref(errPtr, err); 189 return A.H.FALSE; 190 } 191 }, 192 "constof_SubmitJobStatus": (ref: heap.Ref<string>): number => { 193 const idx = ["OK", "USER_REJECTED"].indexOf(A.H.get(ref)); 194 return idx < 0 ? 0 : idx + 1; 195 }, 196 197 "store_SubmitJobResponse": (ptr: Pointer, ref: heap.Ref<any>) => { 198 const x = A.H.get<any>(ref); 199 200 if (typeof x === "undefined") { 201 A.store.Bool(ptr + 8, false); 202 A.store.Enum(ptr + 0, -1); 203 A.store.Ref(ptr + 4, undefined); 204 } else { 205 A.store.Bool(ptr + 8, true); 206 A.store.Enum(ptr + 0, ["OK", "USER_REJECTED"].indexOf(x["status"] as string)); 207 A.store.Ref(ptr + 4, x["jobId"]); 208 } 209 }, 210 "load_SubmitJobResponse": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 211 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 212 213 x["status"] = A.load.Enum(ptr + 0, ["OK", "USER_REJECTED"]); 214 x["jobId"] = A.load.Ref(ptr + 4, undefined); 215 return create === A.H.TRUE ? A.H.push(x) : ref; 216 }, 217 218 "store_SubmitJobRequest": (ptr: Pointer, ref: heap.Ref<any>) => { 219 const x = A.H.get<any>(ref); 220 221 if (typeof x === "undefined") { 222 A.store.Bool(ptr + 28, false); 223 224 A.store.Bool(ptr + 0 + 20, false); 225 A.store.Ref(ptr + 0 + 0, undefined); 226 A.store.Ref(ptr + 0 + 4, undefined); 227 A.store.Ref(ptr + 0 + 8, undefined); 228 A.store.Ref(ptr + 0 + 12, undefined); 229 A.store.Ref(ptr + 0 + 16, undefined); 230 A.store.Ref(ptr + 24, undefined); 231 } else { 232 A.store.Bool(ptr + 28, true); 233 234 if (typeof x["job"] === "undefined") { 235 A.store.Bool(ptr + 0 + 20, false); 236 A.store.Ref(ptr + 0 + 0, undefined); 237 A.store.Ref(ptr + 0 + 4, undefined); 238 A.store.Ref(ptr + 0 + 8, undefined); 239 A.store.Ref(ptr + 0 + 12, undefined); 240 A.store.Ref(ptr + 0 + 16, undefined); 241 } else { 242 A.store.Bool(ptr + 0 + 20, true); 243 A.store.Ref(ptr + 0 + 0, x["job"]["printerId"]); 244 A.store.Ref(ptr + 0 + 4, x["job"]["title"]); 245 A.store.Ref(ptr + 0 + 8, x["job"]["ticket"]); 246 A.store.Ref(ptr + 0 + 12, x["job"]["contentType"]); 247 A.store.Ref(ptr + 0 + 16, x["job"]["document"]); 248 } 249 A.store.Ref(ptr + 24, x["documentBlobUuid"]); 250 } 251 }, 252 "load_SubmitJobRequest": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 253 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 254 255 if (A.load.Bool(ptr + 0 + 20)) { 256 x["job"] = {}; 257 x["job"]["printerId"] = A.load.Ref(ptr + 0 + 0, undefined); 258 x["job"]["title"] = A.load.Ref(ptr + 0 + 4, undefined); 259 x["job"]["ticket"] = A.load.Ref(ptr + 0 + 8, undefined); 260 x["job"]["contentType"] = A.load.Ref(ptr + 0 + 12, undefined); 261 x["job"]["document"] = A.load.Ref(ptr + 0 + 16, undefined); 262 } else { 263 delete x["job"]; 264 } 265 x["documentBlobUuid"] = A.load.Ref(ptr + 24, undefined); 266 return create === A.H.TRUE ? A.H.push(x) : ref; 267 }, 268 "has_CancelJob": (): heap.Ref<boolean> => { 269 if (WEBEXT?.printing && "cancelJob" in WEBEXT?.printing) { 270 return A.H.TRUE; 271 } 272 return A.H.FALSE; 273 }, 274 "func_CancelJob": (fn: Pointer): void => { 275 A.store.Ref(fn, WEBEXT.printing.cancelJob); 276 }, 277 "call_CancelJob": (retPtr: Pointer, jobId: heap.Ref<object>): void => { 278 const _ret = WEBEXT.printing.cancelJob(A.H.get<object>(jobId)); 279 A.store.Ref(retPtr, _ret); 280 }, 281 "try_CancelJob": (retPtr: Pointer, errPtr: Pointer, jobId: heap.Ref<object>): heap.Ref<boolean> => { 282 try { 283 const _ret = WEBEXT.printing.cancelJob(A.H.get<object>(jobId)); 284 A.store.Ref(retPtr, _ret); 285 return A.H.TRUE; 286 } catch (err: any) { 287 A.store.Ref(errPtr, err); 288 return A.H.FALSE; 289 } 290 }, 291 "has_GetPrinterInfo": (): heap.Ref<boolean> => { 292 if (WEBEXT?.printing && "getPrinterInfo" in WEBEXT?.printing) { 293 return A.H.TRUE; 294 } 295 return A.H.FALSE; 296 }, 297 "func_GetPrinterInfo": (fn: Pointer): void => { 298 A.store.Ref(fn, WEBEXT.printing.getPrinterInfo); 299 }, 300 "call_GetPrinterInfo": (retPtr: Pointer, printerId: heap.Ref<object>): void => { 301 const _ret = WEBEXT.printing.getPrinterInfo(A.H.get<object>(printerId)); 302 A.store.Ref(retPtr, _ret); 303 }, 304 "try_GetPrinterInfo": (retPtr: Pointer, errPtr: Pointer, printerId: heap.Ref<object>): heap.Ref<boolean> => { 305 try { 306 const _ret = WEBEXT.printing.getPrinterInfo(A.H.get<object>(printerId)); 307 A.store.Ref(retPtr, _ret); 308 return A.H.TRUE; 309 } catch (err: any) { 310 A.store.Ref(errPtr, err); 311 return A.H.FALSE; 312 } 313 }, 314 "has_GetPrinters": (): heap.Ref<boolean> => { 315 if (WEBEXT?.printing && "getPrinters" in WEBEXT?.printing) { 316 return A.H.TRUE; 317 } 318 return A.H.FALSE; 319 }, 320 "func_GetPrinters": (fn: Pointer): void => { 321 A.store.Ref(fn, WEBEXT.printing.getPrinters); 322 }, 323 "call_GetPrinters": (retPtr: Pointer): void => { 324 const _ret = WEBEXT.printing.getPrinters(); 325 A.store.Ref(retPtr, _ret); 326 }, 327 "try_GetPrinters": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 328 try { 329 const _ret = WEBEXT.printing.getPrinters(); 330 A.store.Ref(retPtr, _ret); 331 return A.H.TRUE; 332 } catch (err: any) { 333 A.store.Ref(errPtr, err); 334 return A.H.FALSE; 335 } 336 }, 337 "has_OnJobStatusChanged": (): heap.Ref<boolean> => { 338 if (WEBEXT?.printing?.onJobStatusChanged && "addListener" in WEBEXT?.printing?.onJobStatusChanged) { 339 return A.H.TRUE; 340 } 341 return A.H.FALSE; 342 }, 343 "func_OnJobStatusChanged": (fn: Pointer): void => { 344 A.store.Ref(fn, WEBEXT.printing.onJobStatusChanged.addListener); 345 }, 346 "call_OnJobStatusChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 347 const _ret = WEBEXT.printing.onJobStatusChanged.addListener(A.H.get<object>(callback)); 348 }, 349 "try_OnJobStatusChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 350 try { 351 const _ret = WEBEXT.printing.onJobStatusChanged.addListener(A.H.get<object>(callback)); 352 return A.H.TRUE; 353 } catch (err: any) { 354 A.store.Ref(errPtr, err); 355 return A.H.FALSE; 356 } 357 }, 358 "has_OffJobStatusChanged": (): heap.Ref<boolean> => { 359 if (WEBEXT?.printing?.onJobStatusChanged && "removeListener" in WEBEXT?.printing?.onJobStatusChanged) { 360 return A.H.TRUE; 361 } 362 return A.H.FALSE; 363 }, 364 "func_OffJobStatusChanged": (fn: Pointer): void => { 365 A.store.Ref(fn, WEBEXT.printing.onJobStatusChanged.removeListener); 366 }, 367 "call_OffJobStatusChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 368 const _ret = WEBEXT.printing.onJobStatusChanged.removeListener(A.H.get<object>(callback)); 369 }, 370 "try_OffJobStatusChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 371 try { 372 const _ret = WEBEXT.printing.onJobStatusChanged.removeListener(A.H.get<object>(callback)); 373 return A.H.TRUE; 374 } catch (err: any) { 375 A.store.Ref(errPtr, err); 376 return A.H.FALSE; 377 } 378 }, 379 "has_HasOnJobStatusChanged": (): heap.Ref<boolean> => { 380 if (WEBEXT?.printing?.onJobStatusChanged && "hasListener" in WEBEXT?.printing?.onJobStatusChanged) { 381 return A.H.TRUE; 382 } 383 return A.H.FALSE; 384 }, 385 "func_HasOnJobStatusChanged": (fn: Pointer): void => { 386 A.store.Ref(fn, WEBEXT.printing.onJobStatusChanged.hasListener); 387 }, 388 "call_HasOnJobStatusChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 389 const _ret = WEBEXT.printing.onJobStatusChanged.hasListener(A.H.get<object>(callback)); 390 A.store.Bool(retPtr, _ret); 391 }, 392 "try_HasOnJobStatusChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 393 try { 394 const _ret = WEBEXT.printing.onJobStatusChanged.hasListener(A.H.get<object>(callback)); 395 A.store.Bool(retPtr, _ret); 396 return A.H.TRUE; 397 } catch (err: any) { 398 A.store.Ref(errPtr, err); 399 return A.H.FALSE; 400 } 401 }, 402 "has_SubmitJob": (): heap.Ref<boolean> => { 403 if (WEBEXT?.printing && "submitJob" in WEBEXT?.printing) { 404 return A.H.TRUE; 405 } 406 return A.H.FALSE; 407 }, 408 "func_SubmitJob": (fn: Pointer): void => { 409 A.store.Ref(fn, WEBEXT.printing.submitJob); 410 }, 411 "call_SubmitJob": (retPtr: Pointer, request: Pointer): void => { 412 const request_ffi = {}; 413 414 if (A.load.Bool(request + 0 + 20)) { 415 request_ffi["job"] = {}; 416 request_ffi["job"]["printerId"] = A.load.Ref(request + 0 + 0, undefined); 417 request_ffi["job"]["title"] = A.load.Ref(request + 0 + 4, undefined); 418 request_ffi["job"]["ticket"] = A.load.Ref(request + 0 + 8, undefined); 419 request_ffi["job"]["contentType"] = A.load.Ref(request + 0 + 12, undefined); 420 request_ffi["job"]["document"] = A.load.Ref(request + 0 + 16, undefined); 421 } 422 request_ffi["documentBlobUuid"] = A.load.Ref(request + 24, undefined); 423 424 const _ret = WEBEXT.printing.submitJob(request_ffi); 425 A.store.Ref(retPtr, _ret); 426 }, 427 "try_SubmitJob": (retPtr: Pointer, errPtr: Pointer, request: Pointer): heap.Ref<boolean> => { 428 try { 429 const request_ffi = {}; 430 431 if (A.load.Bool(request + 0 + 20)) { 432 request_ffi["job"] = {}; 433 request_ffi["job"]["printerId"] = A.load.Ref(request + 0 + 0, undefined); 434 request_ffi["job"]["title"] = A.load.Ref(request + 0 + 4, undefined); 435 request_ffi["job"]["ticket"] = A.load.Ref(request + 0 + 8, undefined); 436 request_ffi["job"]["contentType"] = A.load.Ref(request + 0 + 12, undefined); 437 request_ffi["job"]["document"] = A.load.Ref(request + 0 + 16, undefined); 438 } 439 request_ffi["documentBlobUuid"] = A.load.Ref(request + 24, undefined); 440 441 const _ret = WEBEXT.printing.submitJob(request_ffi); 442 A.store.Ref(retPtr, _ret); 443 return A.H.TRUE; 444 } catch (err: any) { 445 A.store.Ref(errPtr, err); 446 return A.H.FALSE; 447 } 448 }, 449 }; 450 });