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-12-23 03:59:41 +03:00
|
|
|
/* Note: this class relies on static initialization. */
|
2010-06-28 21:36:17 +04:00
|
|
|
class nsCUPSShim {
|
2004-09-07 21:55:27 +04:00
|
|
|
public:
|
2020-08-17 20:39:17 +03:00
|
|
|
bool EnsureInitialized() { return mInited || Init(); }
|
2020-08-07 15:07:48 +03:00
|
|
|
|
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.
|
|
|
|
*/
|
2020-08-06 20:01:21 +03:00
|
|
|
#define CUPS_SHIM_ALL_FUNCS(X) \
|
|
|
|
X(cupsAddOption) \
|
|
|
|
X(cupsCheckDestSupported) \
|
|
|
|
X(cupsConnectDest) \
|
|
|
|
X(cupsCopyDest) \
|
|
|
|
X(cupsCopyDestInfo) \
|
2020-09-03 02:49:04 +03:00
|
|
|
X(cupsDoRequest) \
|
2020-10-15 08:02:46 +03:00
|
|
|
X(cupsEnumDests) \
|
2020-09-25 05:00:46 +03:00
|
|
|
X(cupsFindDestDefault) \
|
2020-08-06 20:01:21 +03:00
|
|
|
X(cupsFreeDestInfo) \
|
|
|
|
X(cupsFreeDests) \
|
2020-08-20 09:11:08 +03:00
|
|
|
X(cupsGetDestMediaDefault) \
|
2020-08-06 20:01:21 +03:00
|
|
|
X(cupsGetDestMediaCount) \
|
|
|
|
X(cupsGetDestMediaByIndex) \
|
2020-09-25 05:00:46 +03:00
|
|
|
X(cupsGetDestMediaByName) \
|
2020-08-06 20:01:21 +03:00
|
|
|
X(cupsGetDest) \
|
|
|
|
X(cupsGetDests) \
|
2020-08-06 20:26:04 +03:00
|
|
|
X(cupsGetNamedDest) \
|
2020-08-10 22:22:27 +03:00
|
|
|
X(cupsGetOption) \
|
2020-08-06 20:01:21 +03:00
|
|
|
X(cupsLocalizeDestMedia) \
|
|
|
|
X(cupsPrintFile) \
|
|
|
|
X(cupsTempFd) \
|
2020-09-03 02:49:04 +03:00
|
|
|
X(httpClose) \
|
|
|
|
X(ippAddString) \
|
|
|
|
X(ippAddStrings) \
|
|
|
|
X(ippDelete) \
|
|
|
|
X(ippFindAttribute) \
|
|
|
|
X(ippGetCount) \
|
|
|
|
X(ippGetString) \
|
|
|
|
X(ippNewRequest)
|
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.
|
|
|
|
# define CUPS_SHIM_FUNC_DECL(X) decltype(::X)* X;
|
|
|
|
#else
|
|
|
|
// Define a static constexpr function pointer. GCC can sometimes optimize
|
|
|
|
// away the pointer fetch for this.
|
|
|
|
# define CUPS_SHIM_FUNC_DECL(X) static constexpr decltype(::X)* const X = ::X;
|
|
|
|
#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
|
|
|
|
|
|
|
private:
|
2020-08-07 23:23:21 +03:00
|
|
|
/**
|
|
|
|
* Initialize this object. Attempt to load the CUPS shared
|
|
|
|
* library and find function pointers for the supported
|
|
|
|
* functions (see below).
|
|
|
|
* @return false if the shared library could not be loaded, or if
|
|
|
|
* any of the functions could not be found.
|
|
|
|
* true for successful initialization.
|
|
|
|
*/
|
|
|
|
bool Init();
|
|
|
|
|
|
|
|
// We can try to get initialized from multiple threads at the same time, this
|
|
|
|
// boolean and the mutex below make it safe.
|
|
|
|
//
|
|
|
|
// The boolean can't be Relaxed, because it guards our function pointers.
|
2020-08-17 20:39:17 +03:00
|
|
|
mozilla::Atomic<bool, mozilla::ReleaseAcquire> mInited{false};
|
2020-08-11 03:25:18 +03:00
|
|
|
#ifdef CUPS_SHIM_RUNTIME_LINK
|
2020-08-17 20:39:17 +03:00
|
|
|
mozilla::OffTheBooksMutex mInitMutex{"nsCUPSShim::mInitMutex"};
|
2004-09-07 21:55:27 +04:00
|
|
|
PRLibrary* mCupsLib;
|
2020-08-11 03:25:18 +03:00
|
|
|
#endif
|
2004-09-07 21:55:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsCUPSShim_h___ */
|