1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_VCL_INC_UNX_CUPSMGR_HXX 21 #define INCLUDED_VCL_INC_UNX_CUPSMGR_HXX 22 23 #include <printerinfomanager.hxx> 24 #include <osl/thread.h> 25 #include <osl/mutex.hxx> 26 27 namespace psp 28 { 29 30 class PPDParser; 31 32 struct FPtrHash 33 { operator ()psp::FPtrHash34 size_t operator()(const FILE* pPtr) const 35 { return reinterpret_cast<size_t>(pPtr); } 36 }; 37 38 class CUPSManager : public PrinterInfoManager 39 { 40 std::unordered_map< FILE*, OString, FPtrHash > m_aSpoolFiles; 41 int m_nDests; 42 void* m_pDests; 43 bool m_bNewDests; 44 std::unordered_map< OUString, int > m_aCUPSDestMap; 45 46 std::unordered_map< OUString, PPDContext > m_aDefaultContexts; 47 48 OString m_aUser; 49 /** this is a security risk, but the CUPS API demands 50 to deliver a pointer to a static buffer containing 51 the password, so this cannot be helped*/ 52 OString m_aPassword; 53 54 osl::Mutex m_aCUPSMutex; 55 oslThread m_aDestThread; 56 57 osl::Mutex m_aGetPPDMutex; 58 bool m_bPPDThreadRunning; 59 60 CUPSManager(); 61 virtual ~CUPSManager() override; 62 63 virtual void initialize() override; 64 65 static void getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner, int& rNumOptions, void** rOptions ); 66 void runDests(); 67 OString threadedCupsGetPPD(const char* pPrinter); 68 public: 69 static void runDestThread(void* pMgr); 70 71 static CUPSManager* tryLoadCUPS(); 72 73 /// wraps cupsGetPPD, so unlink after use ! 74 const PPDParser* createCUPSParser( const OUString& rPrinter ); 75 76 const char* authenticateUser(); 77 78 virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand ) override; 79 virtual bool endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner, const OUString& rFaxNumber ) override; 80 virtual void setupJobContextData( JobData& rData ) override; 81 82 /// check if the printer configuration has changed 83 virtual bool checkPrintersChanged( bool bWait ) override; 84 }; 85 86 } // namespace psp 87 88 #endif 89 90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 91