Bug 1831086 - Patch winsock2.h usage in nICEr to include missing types r=RyanVM
[gecko.git] / widget / nsCUPSShim.h
blob8ab00a48ad51c327b4903b67f3ae472407b20c8b
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 // We allow some functions to be missing, to degrade as gracefully as possible
32 // for older versions of CUPS.
34 // The current target is CUPS 1.6 (bug 1701019).
35 enum class Optional : bool { No, Yes };
37 /**
38 * Function pointers for supported functions. These are only
39 * valid after successful initialization.
41 #define CUPS_SHIM_ALL_FUNCS(X) \
42 X(Optional::No, cupsAddOption) \
43 X(Optional::No, cupsCheckDestSupported) \
44 X(Optional::No, cupsConnectDest) \
45 X(Optional::No, cupsCopyDest) \
46 X(Optional::No, cupsCopyDestInfo) \
47 X(Optional::No, cupsDoRequest) \
48 X(Optional::No, cupsEnumDests) \
49 X(Optional::No, cupsFreeDestInfo) \
50 X(Optional::No, cupsFreeDests) \
51 X(Optional::No, cupsGetDestMediaByName) \
52 X(Optional::Yes, cupsFindDestDefault) \
53 X(Optional::Yes, cupsGetDestMediaDefault) \
54 X(Optional::Yes, cupsGetDestMediaCount) \
55 X(Optional::Yes, cupsGetDestMediaByIndex) \
56 X(Optional::Yes, cupsLocalizeDestMedia) \
57 X(Optional::No, cupsGetDest) \
58 X(Optional::No, cupsGetDests) \
59 X(Optional::No, cupsGetDests2) \
60 X(Optional::No, cupsGetNamedDest) \
61 X(Optional::No, cupsGetOption) \
62 X(Optional::No, cupsServer) \
63 X(Optional::Yes, httpAddrPort) \
64 X(Optional::No, httpClose) \
65 X(Optional::No, httpGetHostname) \
66 X(Optional::Yes, httpGetAddress) \
67 X(Optional::No, ippAddString) \
68 X(Optional::No, ippAddStrings) \
69 X(Optional::No, ippDelete) \
70 X(Optional::No, ippFindAttribute) \
71 X(Optional::No, ippGetCount) \
72 X(Optional::No, ippGetString) \
73 X(Optional::No, ippNewRequest) \
74 X(Optional::No, ippPort)
76 #ifdef CUPS_SHIM_RUNTIME_LINK
77 // Define a single field which holds a function pointer.
78 # define CUPS_SHIM_FUNC_DECL(opt_, fn_) decltype(::fn_)* fn_ = nullptr;
79 #else
80 // Define a static constexpr function pointer. GCC can sometimes optimize
81 // away the pointer fetch for this.
82 # define CUPS_SHIM_FUNC_DECL(opt_, fn_) \
83 static constexpr decltype(::fn_)* const fn_ = ::fn_;
84 #endif
86 CUPS_SHIM_ALL_FUNCS(CUPS_SHIM_FUNC_DECL)
87 #undef CUPS_SHIM_FUNC_DECL
89 #ifdef CUPS_SHIM_RUNTIME_LINK
90 private:
91 bool mInitOkay = false;
92 PRLibrary* mCupsLib = nullptr;
93 #endif
96 #endif /* nsCUPSShim_h___ */