Bug 1691099 [wpt PR 27512] - Reorganize and augment beacon wpt, a=testonly
[gecko.git] / widget / nsCUPSShim.h
blob658c1e7a17c95244aa2ea8fcc7f4fcd13632358f
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsCUPSShim_h___
8 #define nsCUPSShim_h___
10 #include <cups/cups.h>
11 #include "mozilla/Atomics.h"
12 #include "mozilla/Mutex.h"
14 // TODO: This should be a configure option, ideally.
15 #ifndef XP_MACOSX
16 # define CUPS_SHIM_RUNTIME_LINK
17 #endif
19 struct PRLibrary;
21 class nsCUPSShim {
22 public:
23 #ifdef CUPS_SHIM_RUNTIME_LINK
24 nsCUPSShim();
25 bool InitOkay() { return mInitOkay; }
26 #else
27 nsCUPSShim() = default;
28 bool InitOkay() { return true; }
29 #endif
31 /**
32 * Function pointers for supported functions. These are only
33 * valid after successful initialization.
35 #define CUPS_SHIM_ALL_FUNCS(X) \
36 X(cupsAddOption) \
37 X(cupsCheckDestSupported) \
38 X(cupsConnectDest) \
39 X(cupsCopyDest) \
40 X(cupsCopyDestInfo) \
41 X(cupsDoRequest) \
42 X(cupsEnumDests) \
43 X(cupsFindDestDefault) \
44 X(cupsFreeDestInfo) \
45 X(cupsFreeDests) \
46 X(cupsGetDestMediaDefault) \
47 X(cupsGetDestMediaCount) \
48 X(cupsGetDestMediaByIndex) \
49 X(cupsGetDestMediaByName) \
50 X(cupsGetDest) \
51 X(cupsGetDests) \
52 X(cupsGetNamedDest) \
53 X(cupsGetOption) \
54 X(cupsLocalizeDestMedia) \
55 X(cupsPrintFile) \
56 X(cupsTempFd) \
57 X(httpClose) \
58 X(ippAddString) \
59 X(ippAddStrings) \
60 X(ippDelete) \
61 X(ippFindAttribute) \
62 X(ippGetCount) \
63 X(ippGetString) \
64 X(ippNewRequest)
66 #ifdef CUPS_SHIM_RUNTIME_LINK
67 // Define a single field which holds a function pointer.
68 # define CUPS_SHIM_FUNC_DECL(X) decltype(::X)* X = nullptr;
69 #else
70 // Define a static constexpr function pointer. GCC can sometimes optimize
71 // away the pointer fetch for this.
72 # define CUPS_SHIM_FUNC_DECL(X) static constexpr decltype(::X)* const X = ::X;
73 #endif
75 CUPS_SHIM_ALL_FUNCS(CUPS_SHIM_FUNC_DECL)
76 #undef CUPS_SHIM_FUNC_DECL
78 #ifdef CUPS_SHIM_RUNTIME_LINK
79 private:
80 bool mInitOkay = false;
81 PRLibrary* mCupsLib = nullptr;
82 #endif
85 #endif /* nsCUPSShim_h___ */