2020-08-07 15:07:48 +03:00
|
|
|
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ex: set tabstop=8 softtabstop=2 shiftwidth=2 expandtab: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-09-07 21:55:27 +04:00
|
|
|
|
|
|
|
#ifndef nsCUPSShim_h___
|
|
|
|
#define nsCUPSShim_h___
|
|
|
|
|
2020-07-22 02:39:45 +03:00
|
|
|
#include <cups/cups.h>
|
2020-08-07 23:23:21 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
|
|
|
#include "mozilla/Mutex.h"
|
2004-09-07 21:55:27 +04:00
|
|
|
|
2020-08-11 03:25:18 +03:00
|
|
|
// TODO: This should be a configure option, ideally.
|
|
|
|
#ifndef XP_MACOSX
|
|
|
|
# define CUPS_SHIM_RUNTIME_LINK
|
|
|
|
#endif
|
|
|
|
|
2004-09-07 21:55:27 +04:00
|
|
|
struct PRLibrary;
|
|
|
|
|
2010-06-28 21:36:17 +04:00
|
|
|
class nsCUPSShim {
|
2004-09-07 21:55:27 +04:00
|
|
|
public:
|
2020-11-04 21:56:13 +03:00
|
|
|
#ifdef CUPS_SHIM_RUNTIME_LINK
|
|
|
|
nsCUPSShim();
|
|
|
|
bool InitOkay() { return mInitOkay; }
|
|
|
|
#else
|
|
|
|
nsCUPSShim() = default;
|
|
|
|
bool InitOkay() { return true; }
|
|
|
|
#endif
|
2020-08-07 15:07:48 +03:00
|
|
|
|
2021-03-29 13:08:44 +03:00
|
|
|
// We allow some functions to be missing, to degrade as gracefully as possible
|
|
|
|
// for older versions of CUPS.
|
|
|
|
//
|
|
|
|
// The current target is CUPS 1.6 (bug 1701019).
|
|
|
|
enum class Optional : bool { No, Yes };
|
|
|
|
|
2020-08-06 20:01:21 +03:00
|
|
|
/**
|
|
|
|
* Function pointers for supported functions. These are only
|
2004-09-07 21:55:27 +04:00
|
|
|
* valid after successful initialization.
|
|
|
|
*/
|
2021-03-29 13:08:44 +03:00
|
|
|
#define CUPS_SHIM_ALL_FUNCS(X) \
|
|
|
|
X(Optional::No, cupsAddOption) \
|
|
|
|
X(Optional::No, cupsCheckDestSupported) \
|
|
|
|
X(Optional::No, cupsConnectDest) \
|
|
|
|
X(Optional::No, cupsCopyDest) \
|
|
|
|
X(Optional::No, cupsCopyDestInfo) \
|
|
|
|
X(Optional::No, cupsDoRequest) \
|
|
|
|
X(Optional::No, cupsEnumDests) \
|
|
|
|
X(Optional::No, cupsFreeDestInfo) \
|
|
|
|
X(Optional::No, cupsFreeDests) \
|
|
|
|
X(Optional::No, cupsGetDestMediaByName) \
|
|
|
|
X(Optional::Yes, cupsFindDestDefault) \
|
|
|
|
X(Optional::Yes, cupsGetDestMediaDefault) \
|
|
|
|
X(Optional::Yes, cupsGetDestMediaCount) \
|
|
|
|
X(Optional::Yes, cupsGetDestMediaByIndex) \
|
|
|
|
X(Optional::Yes, cupsLocalizeDestMedia) \
|
|
|
|
X(Optional::No, cupsGetDest) \
|
|
|
|
X(Optional::No, cupsGetDests) \
|
2022-06-22 10:52:59 +03:00
|
|
|
X(Optional::No, cupsGetDests2) \
|
2021-03-29 13:08:44 +03:00
|
|
|
X(Optional::No, cupsGetNamedDest) \
|
|
|
|
X(Optional::No, cupsGetOption) \
|
2021-10-23 01:55:25 +03:00
|
|
|
X(Optional::No, cupsServer) \
|
|
|
|
X(Optional::Yes, httpAddrPort) \
|
2021-03-29 13:08:44 +03:00
|
|
|
X(Optional::No, httpClose) \
|
2021-10-23 01:55:25 +03:00
|
|
|
X(Optional::No, httpGetHostname) \
|
|
|
|
X(Optional::Yes, httpGetAddress) \
|
2021-03-29 13:08:44 +03:00
|
|
|
X(Optional::No, ippAddString) \
|
|
|
|
X(Optional::No, ippAddStrings) \
|
|
|
|
X(Optional::No, ippDelete) \
|
|
|
|
X(Optional::No, ippFindAttribute) \
|
|
|
|
X(Optional::No, ippGetCount) \
|
|
|
|
X(Optional::No, ippGetString) \
|
2021-10-23 01:55:25 +03:00
|
|
|
X(Optional::No, ippNewRequest) \
|
|
|
|
X(Optional::No, ippPort)
|
2020-08-06 20:01:21 +03:00
|
|
|
|
2020-08-11 03:25:18 +03:00
|
|
|
#ifdef CUPS_SHIM_RUNTIME_LINK
|
|
|
|
// Define a single field which holds a function pointer.
|
2021-03-29 13:08:44 +03:00
|
|
|
# define CUPS_SHIM_FUNC_DECL(opt_, fn_) decltype(::fn_)* fn_ = nullptr;
|
2020-08-11 03:25:18 +03:00
|
|
|
#else
|
|
|
|
// Define a static constexpr function pointer. GCC can sometimes optimize
|
|
|
|
// away the pointer fetch for this.
|
2021-03-29 13:08:44 +03:00
|
|
|
# define CUPS_SHIM_FUNC_DECL(opt_, fn_) \
|
|
|
|
static constexpr decltype(::fn_)* const fn_ = ::fn_;
|
2020-08-11 03:25:18 +03:00
|
|
|
#endif
|
|
|
|
|
2020-08-06 20:01:21 +03:00
|
|
|
CUPS_SHIM_ALL_FUNCS(CUPS_SHIM_FUNC_DECL)
|
|
|
|
#undef CUPS_SHIM_FUNC_DECL
|
2004-09-07 21:55:27 +04:00
|
|
|
|
2020-11-04 05:23:47 +03:00
|
|
|
#ifdef CUPS_SHIM_RUNTIME_LINK
|
2020-11-04 21:56:13 +03:00
|
|
|
private:
|
|
|
|
bool mInitOkay = false;
|
|
|
|
PRLibrary* mCupsLib = nullptr;
|
2020-08-11 03:25:18 +03:00
|
|
|
#endif
|
2004-09-07 21:55:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsCUPSShim_h___ */
|