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.
16 # define CUPS_SHIM_RUNTIME_LINK
23 #ifdef CUPS_SHIM_RUNTIME_LINK
25 bool InitOkay() { return mInitOkay
; }
27 nsCUPSShim() = default;
28 bool InitOkay() { return true; }
32 * Function pointers for supported functions. These are only
33 * valid after successful initialization.
35 #define CUPS_SHIM_ALL_FUNCS(X) \
37 X(cupsCheckDestSupported) \
43 X(cupsFindDestDefault) \
46 X(cupsGetDestMediaDefault) \
47 X(cupsGetDestMediaCount) \
48 X(cupsGetDestMediaByIndex) \
49 X(cupsGetDestMediaByName) \
54 X(cupsLocalizeDestMedia) \
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;
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;
75 CUPS_SHIM_ALL_FUNCS(CUPS_SHIM_FUNC_DECL
)
76 #undef CUPS_SHIM_FUNC_DECL
78 #ifdef CUPS_SHIM_RUNTIME_LINK
80 bool mInitOkay
= false;
81 PRLibrary
* mCupsLib
= nullptr;
85 #endif /* nsCUPSShim_h___ */