github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/printerproviderinternal/bindings/ffi_bindings.ts (about)

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/printerproviderinternal", (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      "has_GetPrintData": (): heap.Ref<boolean> => {
    12        if (WEBEXT?.printerProviderInternal && "getPrintData" in WEBEXT?.printerProviderInternal) {
    13          return A.H.TRUE;
    14        }
    15        return A.H.FALSE;
    16      },
    17      "func_GetPrintData": (fn: Pointer): void => {
    18        A.store.Ref(fn, WEBEXT.printerProviderInternal.getPrintData);
    19      },
    20      "call_GetPrintData": (retPtr: Pointer, requestId: number): void => {
    21        const _ret = WEBEXT.printerProviderInternal.getPrintData(requestId);
    22        A.store.Ref(retPtr, _ret);
    23      },
    24      "try_GetPrintData": (retPtr: Pointer, errPtr: Pointer, requestId: number): heap.Ref<boolean> => {
    25        try {
    26          const _ret = WEBEXT.printerProviderInternal.getPrintData(requestId);
    27          A.store.Ref(retPtr, _ret);
    28          return A.H.TRUE;
    29        } catch (err: any) {
    30          A.store.Ref(errPtr, err);
    31          return A.H.FALSE;
    32        }
    33      },
    34      "has_ReportPrintResult": (): heap.Ref<boolean> => {
    35        if (WEBEXT?.printerProviderInternal && "reportPrintResult" in WEBEXT?.printerProviderInternal) {
    36          return A.H.TRUE;
    37        }
    38        return A.H.FALSE;
    39      },
    40      "func_ReportPrintResult": (fn: Pointer): void => {
    41        A.store.Ref(fn, WEBEXT.printerProviderInternal.reportPrintResult);
    42      },
    43      "call_ReportPrintResult": (retPtr: Pointer, request_id: number, error: number): void => {
    44        const _ret = WEBEXT.printerProviderInternal.reportPrintResult(
    45          request_id,
    46          error > 0 && error <= 4 ? ["OK", "FAILED", "INVALID_TICKET", "INVALID_DATA"][error - 1] : undefined
    47        );
    48      },
    49      "try_ReportPrintResult": (
    50        retPtr: Pointer,
    51        errPtr: Pointer,
    52        request_id: number,
    53        error: number
    54      ): heap.Ref<boolean> => {
    55        try {
    56          const _ret = WEBEXT.printerProviderInternal.reportPrintResult(
    57            request_id,
    58            error > 0 && error <= 4 ? ["OK", "FAILED", "INVALID_TICKET", "INVALID_DATA"][error - 1] : undefined
    59          );
    60          return A.H.TRUE;
    61        } catch (err: any) {
    62          A.store.Ref(errPtr, err);
    63          return A.H.FALSE;
    64        }
    65      },
    66      "has_ReportPrinterCapability": (): heap.Ref<boolean> => {
    67        if (WEBEXT?.printerProviderInternal && "reportPrinterCapability" in WEBEXT?.printerProviderInternal) {
    68          return A.H.TRUE;
    69        }
    70        return A.H.FALSE;
    71      },
    72      "func_ReportPrinterCapability": (fn: Pointer): void => {
    73        A.store.Ref(fn, WEBEXT.printerProviderInternal.reportPrinterCapability);
    74      },
    75      "call_ReportPrinterCapability": (retPtr: Pointer, request_id: number, capability: heap.Ref<object>): void => {
    76        const _ret = WEBEXT.printerProviderInternal.reportPrinterCapability(request_id, A.H.get<object>(capability));
    77      },
    78      "try_ReportPrinterCapability": (
    79        retPtr: Pointer,
    80        errPtr: Pointer,
    81        request_id: number,
    82        capability: heap.Ref<object>
    83      ): heap.Ref<boolean> => {
    84        try {
    85          const _ret = WEBEXT.printerProviderInternal.reportPrinterCapability(request_id, A.H.get<object>(capability));
    86          return A.H.TRUE;
    87        } catch (err: any) {
    88          A.store.Ref(errPtr, err);
    89          return A.H.FALSE;
    90        }
    91      },
    92      "has_ReportPrinters": (): heap.Ref<boolean> => {
    93        if (WEBEXT?.printerProviderInternal && "reportPrinters" in WEBEXT?.printerProviderInternal) {
    94          return A.H.TRUE;
    95        }
    96        return A.H.FALSE;
    97      },
    98      "func_ReportPrinters": (fn: Pointer): void => {
    99        A.store.Ref(fn, WEBEXT.printerProviderInternal.reportPrinters);
   100      },
   101      "call_ReportPrinters": (retPtr: Pointer, requestId: number, printers: heap.Ref<object>): void => {
   102        const _ret = WEBEXT.printerProviderInternal.reportPrinters(requestId, A.H.get<object>(printers));
   103      },
   104      "try_ReportPrinters": (
   105        retPtr: Pointer,
   106        errPtr: Pointer,
   107        requestId: number,
   108        printers: heap.Ref<object>
   109      ): heap.Ref<boolean> => {
   110        try {
   111          const _ret = WEBEXT.printerProviderInternal.reportPrinters(requestId, A.H.get<object>(printers));
   112          return A.H.TRUE;
   113        } catch (err: any) {
   114          A.store.Ref(errPtr, err);
   115          return A.H.FALSE;
   116        }
   117      },
   118      "has_ReportUsbPrinterInfo": (): heap.Ref<boolean> => {
   119        if (WEBEXT?.printerProviderInternal && "reportUsbPrinterInfo" in WEBEXT?.printerProviderInternal) {
   120          return A.H.TRUE;
   121        }
   122        return A.H.FALSE;
   123      },
   124      "func_ReportUsbPrinterInfo": (fn: Pointer): void => {
   125        A.store.Ref(fn, WEBEXT.printerProviderInternal.reportUsbPrinterInfo);
   126      },
   127      "call_ReportUsbPrinterInfo": (retPtr: Pointer, requestId: number, printerInfo: Pointer): void => {
   128        const printerInfo_ffi = {};
   129  
   130        printerInfo_ffi["id"] = A.load.Ref(printerInfo + 0, undefined);
   131        printerInfo_ffi["name"] = A.load.Ref(printerInfo + 4, undefined);
   132        printerInfo_ffi["description"] = A.load.Ref(printerInfo + 8, undefined);
   133  
   134        const _ret = WEBEXT.printerProviderInternal.reportUsbPrinterInfo(requestId, printerInfo_ffi);
   135      },
   136      "try_ReportUsbPrinterInfo": (
   137        retPtr: Pointer,
   138        errPtr: Pointer,
   139        requestId: number,
   140        printerInfo: Pointer
   141      ): heap.Ref<boolean> => {
   142        try {
   143          const printerInfo_ffi = {};
   144  
   145          printerInfo_ffi["id"] = A.load.Ref(printerInfo + 0, undefined);
   146          printerInfo_ffi["name"] = A.load.Ref(printerInfo + 4, undefined);
   147          printerInfo_ffi["description"] = A.load.Ref(printerInfo + 8, undefined);
   148  
   149          const _ret = WEBEXT.printerProviderInternal.reportUsbPrinterInfo(requestId, printerInfo_ffi);
   150          return A.H.TRUE;
   151        } catch (err: any) {
   152          A.store.Ref(errPtr, err);
   153          return A.H.FALSE;
   154        }
   155      },
   156    };
   157  });