Line data Source code
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 _PSPRINT_CUPSMGR_HXX_
21 : #define _PSPRINT_CUPSMGR_HXX_
22 :
23 : #include "vcl/printerinfomanager.hxx"
24 : #include "osl/module.h"
25 : #include "osl/thread.h"
26 : #include "osl/mutex.hxx"
27 :
28 : namespace psp
29 : {
30 :
31 : class PPDParser;
32 :
33 : struct FPtrHash
34 : {
35 0 : size_t operator()(const FILE* pPtr) const
36 0 : { return (size_t)pPtr; }
37 : };
38 :
39 : class CUPSManager : public PrinterInfoManager
40 : {
41 : boost::unordered_map< FILE*, OString, FPtrHash > m_aSpoolFiles;
42 : int m_nDests;
43 : void* m_pDests;
44 : bool m_bNewDests;
45 : boost::unordered_map< OUString, int, OUStringHash > m_aCUPSDestMap;
46 :
47 : boost::unordered_map< OUString, PPDContext, OUStringHash > m_aDefaultContexts;
48 :
49 : OString m_aUser;
50 : // this is a security risk, but the CUPS API demands
51 : // to deliver a pointer to a static buffer containing
52 : // the password, so this cannot be helped
53 : OString m_aPassword;
54 :
55 : osl::Mutex m_aCUPSMutex;
56 : oslThread m_aDestThread;
57 :
58 : osl::Mutex m_aGetPPDMutex;
59 : bool m_bPPDThreadRunning;
60 :
61 : CUPSManager();
62 : virtual ~CUPSManager();
63 :
64 : virtual void initialize();
65 :
66 : void getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner, int& rNumOptions, void** rOptions ) const;
67 : void runDests();
68 : OString threadedCupsGetPPD(const char* pPrinter);
69 : public:
70 : // public for stub
71 : static void runDestThread(void* pMgr);
72 :
73 : static CUPSManager* tryLoadCUPS();
74 :
75 : const PPDParser* createCUPSParser( const OUString& rPrinter );
76 : // wraps cupsGetPPD, so unlink after use !
77 :
78 : const char* authenticateUser( const char* );
79 :
80 : virtual FILE* startSpool( const OUString& rPrinterName, bool bQuickCommand );
81 : virtual int endSpool( const OUString& rPrinterName, const OUString& rJobTitle, FILE* pFile, const JobData& rDocumentJobData, bool bBanner );
82 : virtual void setupJobContextData( JobData& rData );
83 :
84 : // changes the info about a named printer
85 : virtual void changePrinterInfo( const OUString& rPrinter, const PrinterInfo& rNewInfo );
86 :
87 : // check if the printer configuration has changed
88 : virtual bool checkPrintersChanged( bool bWait );
89 :
90 : // members for administration (->padmin)
91 : // disable for CUPS
92 : virtual bool addPrinter( const OUString& rPrinterName, const OUString& rDriverName );
93 : virtual bool removePrinter( const OUString& rPrinterName, bool bCheckOnly = false );
94 : virtual bool writePrinterConfig();
95 : virtual bool setDefaultPrinter( const OUString& rPrinterName );
96 :
97 : virtual bool addOrRemovePossible() const;
98 : };
99 :
100 : } // namespace psp
101 :
102 : #endif
103 :
104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|