From 3e5bca1893f08b9372c1e0ab96a32aabf989acd4 Mon Sep 17 00:00:00 2001 From: Chris Sherlock Date: Sun, 2 Apr 2017 15:21:38 +1000 Subject: vcl: PrinterInfoManager no longer a singleton Let's just create the PrinterInfoManager via the SalData constructor. There is no real need to lazy-load this, so the singleton is sort of pointless. This allows more RAII-type behaviour. Change-Id: Id860a40e92eea36b1aeb4da646f1134e8a4d70aa --- include/vcl/printerinfomanager.hxx | 6 +- vcl/android/androidinst.cxx | 9 ++- vcl/headless/headlessinst.cxx | 9 ++- vcl/headless/svpprn.cxx | 6 +- vcl/inc/unx/cupsmgr.hxx | 4 +- vcl/null/printerinfomanager.cxx | 15 ---- vcl/unx/generic/plugadapt/salplug.cxx | 9 ++- vcl/unx/generic/print/common_gfx.cxx | 9 ++- vcl/unx/generic/print/genprnpsp.cxx | 50 +++++++------- vcl/unx/generic/print/printerjob.cxx | 16 +++-- vcl/unx/generic/printer/cupsmgr.cxx | 95 +++++++++++++------------- vcl/unx/generic/printer/jobdata.cxx | 6 +- vcl/unx/generic/printer/ppdparser.cxx | 4 +- vcl/unx/generic/printer/printerinfomanager.cxx | 28 +------- 14 files changed, 128 insertions(+), 138 deletions(-) diff --git a/include/vcl/printerinfomanager.hxx b/include/vcl/printerinfomanager.hxx index 738bba14f17d..997496b99c30 100644 --- a/include/vcl/printerinfomanager.hxx +++ b/include/vcl/printerinfomanager.hxx @@ -92,8 +92,6 @@ protected: bool m_bUseJobPatch; OUString m_aSystemDefaultPaper; - PrinterInfoManager( Type eType = Type::Default ); - virtual void initialize(); // fill default paper if not configured in config file @@ -103,8 +101,8 @@ protected: public: - // there can only be one - static PrinterInfoManager& get(); + PrinterInfoManager( Type eType = Type::Default ); + // only called by SalData destructor, frees the global instance static void release(); diff --git a/vcl/android/androidinst.cxx b/vcl/android/androidinst.cxx index c976a7c89732..e08a68f6645d 100644 --- a/vcl/android/androidinst.cxx +++ b/vcl/android/androidinst.cxx @@ -180,13 +180,18 @@ const OUString& SalGetDesktopEnvironment() SalData::SalData() : m_pInstance( 0 ), - m_pPlugin( 0 ), - m_pPIManager(0 ) + m_pPlugin( 0 ) { + m_pPIManager = CUPSManager::tryLoadCUPS(); + if (!m_pPIManager) + m_pPIManager = new PrinterInfoManager(); + + pSalData->m_pPIManager->initialize(); } SalData::~SalData() { + delete m_pPIManager; } // This is our main entry point: diff --git a/vcl/headless/headlessinst.cxx b/vcl/headless/headlessinst.cxx index b5d9a66a802f..17962e95ffa5 100644 --- a/vcl/headless/headlessinst.cxx +++ b/vcl/headless/headlessinst.cxx @@ -80,13 +80,18 @@ const OUString& SalGetDesktopEnvironment() SalData::SalData() : m_pInstance( nullptr ), - m_pPlugin( nullptr ), - m_pPIManager( nullptr ) + m_pPlugin( nullptr ) { + m_pPIManager = CUPSManager::tryLoadCUPS(); + if (!m_pPIManager) + m_pPIManager = new PrinterInfoManager(); + + pSalData->m_pPIManager->initialize(); } SalData::~SalData() { + delete m_PIManager; } // This is our main entry point: diff --git a/vcl/headless/svpprn.cxx b/vcl/headless/svpprn.cxx index b158fc632103..5cc78773a8f8 100644 --- a/vcl/headless/svpprn.cxx +++ b/vcl/headless/svpprn.cxx @@ -165,7 +165,7 @@ SalInfoPrinter* SvpSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueIn if( pJobSetup ) { - PrinterInfoManager& rManager( PrinterInfoManager::get() ); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); JobData aInfo( rManager.getPrinterInfo( pQueueInfo->maPrinterName ) ); pPrinter->m_aJobData = aInfo; pPrinter->m_aPrinterGfx.Init( pPrinter->m_aJobData ); @@ -204,7 +204,7 @@ void SvpSalInstance::DestroyPrinter( SalPrinter* pPrinter ) void SvpSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList ) { - PrinterInfoManager& rManager( PrinterInfoManager::get() ); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); static const char* pNoSyncDetection = getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" ); if( ! pNoSyncDetection || ! *pNoSyncDetection ) { @@ -251,7 +251,7 @@ void SvpSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* ) OUString SvpSalInstance::GetDefaultPrinter() { - PrinterInfoManager& rManager( PrinterInfoManager::get() ); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); return rManager.getDefaultPrinter(); } diff --git a/vcl/inc/unx/cupsmgr.hxx b/vcl/inc/unx/cupsmgr.hxx index 8a7025dd78e3..3d71f5085487 100644 --- a/vcl/inc/unx/cupsmgr.hxx +++ b/vcl/inc/unx/cupsmgr.hxx @@ -63,11 +63,11 @@ class CUPSManager : public PrinterInfoManager CUPSManager(); virtual ~CUPSManager() override; - virtual void initialize() override; - static void getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner, int& rNumOptions, void** rOptions ); void runDests(); OString threadedCupsGetPPD(const char* pPrinter); + + virtual void initialize() override; public: static void runDestThread(void* pMgr); diff --git a/vcl/null/printerinfomanager.cxx b/vcl/null/printerinfomanager.cxx index 39571144c47d..4c7e7b860729 100644 --- a/vcl/null/printerinfomanager.cxx +++ b/vcl/null/printerinfomanager.cxx @@ -33,21 +33,6 @@ using namespace psp; using namespace osl; -PrinterInfoManager& PrinterInfoManager::get() -{ - SalData* pSalData = GetSalData(); - if( ! pSalData->m_pPIManager ) - pSalData->m_pPIManager = new PrinterInfoManager(); - return *pSalData->m_pPIManager; -} - -void PrinterInfoManager::release() -{ - SalData* pSalData = GetSalData(); - delete pSalData->m_pPIManager; - pSalData->m_pPIManager = nullptr; -} - PrinterInfoManager::PrinterInfoManager( Type eType ) : m_pQueueInfo( nullptr ), m_eType( eType ), diff --git a/vcl/unx/generic/plugadapt/salplug.cxx b/vcl/unx/generic/plugadapt/salplug.cxx index ce032538044b..4163a6d38441 100644 --- a/vcl/unx/generic/plugadapt/salplug.cxx +++ b/vcl/unx/generic/plugadapt/salplug.cxx @@ -26,6 +26,7 @@ #include "salinst.hxx" #include "unx/gensys.h" #include "unx/gendata.hxx" +#include "unx/cupsmgr.hxx" #include "headless/svpinst.hxx" #include "unx/desktops.hxx" #include @@ -317,14 +318,16 @@ const OUString& SalGetDesktopEnvironment() SalData::SalData() : m_pInstance(nullptr), - m_pPlugin(nullptr), - m_pPIManager(nullptr) + m_pPlugin(nullptr) { + m_pPIManager = psp::CUPSManager::tryLoadCUPS(); + if (!m_pPIManager) + m_pPIManager = new psp::PrinterInfoManager(); } SalData::~SalData() { - psp::PrinterInfoManager::release(); + delete m_pPIManager; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/print/common_gfx.cxx b/vcl/unx/generic/print/common_gfx.cxx index d9801a155207..6b745abc096c 100644 --- a/vcl/unx/generic/print/common_gfx.cxx +++ b/vcl/unx/generic/print/common_gfx.cxx @@ -23,6 +23,7 @@ #include "psputil.hxx" #include "glyphset.hxx" +#include "saldatabasic.hxx" #include "unx/printergfx.hxx" #include "unx/printerjob.hxx" @@ -63,7 +64,9 @@ PrinterGfx::Init (PrinterJob &rPrinterJob) mnDpi = rPrinterJob.GetResolution(); rPrinterJob.GetScale (mfScaleX, mfScaleY); - const JobData& rInfo( PrinterInfoManager::get().getPrinterInfo( rPrinterJob.GetPrinterName() ) ); + + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); + const JobData& rInfo( rManager.getPrinterInfo( rPrinterJob.GetPrinterName() ) ); mbUploadPS42Fonts = rInfo.m_pParser && rInfo.m_pParser->isType42Capable(); } @@ -79,7 +82,9 @@ PrinterGfx::Init (const JobData& rData) mnDpi = nRes; mfScaleX = (double)72.0 / (double)mnDpi; mfScaleY = (double)72.0 / (double)mnDpi; - const JobData& rInfo( PrinterInfoManager::get().getPrinterInfo( rData.m_aPrinterName ) ); + + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); + const JobData& rInfo( rManager.getPrinterInfo( rData.m_aPrinterName ) ); mbUploadPS42Fonts = rInfo.m_pParser && rInfo.m_pParser->isType42Capable(); } diff --git a/vcl/unx/generic/print/genprnpsp.cxx b/vcl/unx/generic/print/genprnpsp.cxx index c0d6f0a35823..6832d207d21d 100644 --- a/vcl/unx/generic/print/genprnpsp.cxx +++ b/vcl/unx/generic/print/genprnpsp.cxx @@ -370,7 +370,7 @@ void SalGenericInstance::configurePspInfoPrinter(PspSalInfoPrinter *pPrinter, { if( pJobSetup ) { - PrinterInfoManager& rManager( PrinterInfoManager::get() ); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); JobData aInfo( rManager.getPrinterInfo( pQueueInfo->maPrinterName ) ); pPrinter->m_aJobData = aInfo; pPrinter->m_aPrinterGfx.Init( pPrinter->m_aJobData ); @@ -419,7 +419,7 @@ void SalGenericInstance::DestroyPrinter( SalPrinter* pPrinter ) void SalGenericInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList ) { mbPrinterInit = true; - PrinterInfoManager& rManager( PrinterInfoManager::get() ); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); static const char* pNoSyncDetection = getenv( "SAL_DISABLE_SYNCHRONOUS_PRINTER_DETECTION" ); if( ! pNoSyncDetection || ! *pNoSyncDetection ) { @@ -468,7 +468,7 @@ void SalGenericInstance::GetPrinterQueueState( SalPrinterQueueInfo* ) OUString SalGenericInstance::GetDefaultPrinter() { mbPrinterInit = true; - PrinterInfoManager& rManager( PrinterInfoManager::get() ); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); return rManager.getDefaultPrinter(); } @@ -545,7 +545,7 @@ bool PspSalInfoPrinter::Setup( SalFrame* pFrame, ImplJobSetup* pJobSetup ) if( ! pFrame || ! pJobSetup ) return false; - PrinterInfoManager& rManager = PrinterInfoManager::get(); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); JobData aInfo( rManager.getPrinterInfo( pJobSetup->GetPrinterName() ) ); if ( pJobSetup->GetDriverData() ) @@ -776,6 +776,8 @@ OUString PspSalInfoPrinter::GetPaperBinName( const ImplJobSetup* pJobSetup, sal_ sal_uInt32 PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, PrinterCapType nType ) { + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); + switch( nType ) { case PrinterCapType::SupportDialog: @@ -798,7 +800,7 @@ sal_uInt32 PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, Pr { // see if the PPD contains the fax4CUPS "Dial" option and that it's not set // to "manually" - JobData aData = PrinterInfoManager::get().getPrinterInfo(pJobSetup->GetPrinterName()); + JobData aData = rManager.getPrinterInfo(pJobSetup->GetPrinterName()); if( pJobSetup->GetDriverData() ) JobData::constructFromStreamBuffer( pJobSetup->GetDriverData(), pJobSetup->GetDriverDataLen(), aData ); const PPDKey* pKey = aData.m_pParser ? aData.m_pParser->getKey(OUString("Dial")) : nullptr; @@ -809,22 +811,24 @@ sal_uInt32 PspSalInfoPrinter::GetCapabilities( const ImplJobSetup* pJobSetup, Pr } case PrinterCapType::PDF: - if( PrinterInfoManager::get().checkFeatureToken( pJobSetup->GetPrinterName(), "pdf" ) ) + if( rManager.checkFeatureToken( pJobSetup->GetPrinterName(), "pdf" ) ) + { return 1; + } else { // see if the PPD contains a value to set PDF device - JobData aData = PrinterInfoManager::get().getPrinterInfo( pJobSetup->GetPrinterName() ); + JobData aData = rManager.getPrinterInfo( pJobSetup->GetPrinterName() ); if( pJobSetup->GetDriverData() ) JobData::constructFromStreamBuffer( pJobSetup->GetDriverData(), pJobSetup->GetDriverDataLen(), aData ); return aData.m_nPDFDevice > 0 ? 1 : 0; } case PrinterCapType::ExternalDialog: - return PrinterInfoManager::get().checkFeatureToken( pJobSetup->GetPrinterName(), "external_dialog" ) ? 1 : 0; + return rManager.checkFeatureToken( pJobSetup->GetPrinterName(), "external_dialog" ) ? 1 : 0; case PrinterCapType::UsePullModel: { // see if the PPD contains a value to set PDF device - JobData aData = PrinterInfoManager::get().getPrinterInfo( pJobSetup->GetPrinterName() ); + JobData aData = rManager.getPrinterInfo( pJobSetup->GetPrinterName() ); if( pJobSetup->GetDriverData() ) JobData::constructFromStreamBuffer( pJobSetup->GetDriverData(), pJobSetup->GetDriverDataLen(), aData ); return aData.m_nPDFDevice > 0 ? 1 : 0; @@ -892,7 +896,9 @@ bool PspSalPrinter::StartJob( int nMode = 0; // check whether this printer is configured as fax sal_Int32 nIndex = 0; - const JobData& rInfo( PrinterInfoManager::get().getPrinterInfo( m_aJobData.m_aPrinterName ) ); + + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); + const JobData& rInfo( rManager.getPrinterInfo( m_aJobData.m_aPrinterName ) ); while( nIndex != -1 ) { OUString aToken( rInfo.m_aFeatures.getToken( 0, ',', nIndex ) ); @@ -930,7 +936,8 @@ bool PspSalPrinter::EndJob() if( bSuccess && m_bPdf ) { - const JobData& rInfo( PrinterInfoManager::get().getPrinterInfo( m_aJobData.m_aPrinterName ) ); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); + const JobData& rInfo( rManager.getPrinterInfo( m_aJobData.m_aPrinterName ) ); bSuccess = createPdf( m_aFileName, m_aTmpFile, rInfo.m_aCommand ); } } @@ -1208,7 +1215,8 @@ bool PspSalPrinter::StartJob( const OUString* i_pFileName, const OUString& i_rJo m_aJobData.setPaperBin( aPDFFiles[i].maParameters.mnPaperBin ); // spool current file - FILE* fp = PrinterInfoManager::get().startSpool(xPrinter->GetName(), i_rController.isDirectPrint()); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); + FILE* fp = rManager.startSpool(xPrinter->GetName(), i_rController.isDirectPrint()); if( fp ) { sal_uInt64 nBytesRead = 0; @@ -1231,7 +1239,7 @@ bool PspSalPrinter::StartJob( const OUString* i_pFileName, const OUString& i_rJo aBuf.append( sal_Int32( i + nCurJob * aPDFFiles.size() ) ); } bSuccess &= - PrinterInfoManager::get().endSpool(xPrinter->GetName(), aBuf.makeStringAndClear(), fp, m_aJobData, bFirstJob, sFaxNumber); + rManager.endSpool(xPrinter->GetName(), aBuf.makeStringAndClear(), fp, m_aJobData, bFirstJob, sFaxNumber); bFirstJob = false; } } @@ -1269,7 +1277,7 @@ class PrinterUpdate static void doUpdate(); DECL_STATIC_LINK( PrinterUpdate, UpdateTimerHdl, Timer*, void ); public: - static void update(SalGenericInstance &rInstance); + static void update(); static void jobStarted() { nActiveJobs++; } static void jobEnded(); }; @@ -1279,7 +1287,8 @@ int PrinterUpdate::nActiveJobs = 0; void PrinterUpdate::doUpdate() { - ::psp::PrinterInfoManager& rManager( ::psp::PrinterInfoManager::get() ); + + psp::PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); SalGenericInstance *pInst = static_cast( GetSalData()->m_pInstance ); if( pInst && rManager.checkPrintersChanged( false ) ) pInst->PostPrintersChanged(); @@ -1297,18 +1306,11 @@ IMPL_STATIC_LINK_NOARG( PrinterUpdate, UpdateTimerHdl, Timer*, void ) pPrinterUpdateIdle->Start(); } -void PrinterUpdate::update(SalGenericInstance &rInstance) +void PrinterUpdate::update() { if( Application::GetSettings().GetMiscSettings().GetDisablePrinting() ) return; - if( ! rInstance.isPrinterInit() ) - { - // #i45389# start background printer detection - psp::PrinterInfoManager::get(); - return; - } - if( nActiveJobs < 1 ) doUpdate(); else if( ! pPrinterUpdateIdle ) @@ -1322,7 +1324,7 @@ void PrinterUpdate::update(SalGenericInstance &rInstance) void SalGenericInstance::updatePrinterUpdate() { - PrinterUpdate::update(*this); + PrinterUpdate::update(); } void SalGenericInstance::jobStartedPrinterUpdate() diff --git a/vcl/unx/generic/print/printerjob.cxx b/vcl/unx/generic/print/printerjob.cxx index 13dd71711c2e..ed0822ace553 100644 --- a/vcl/unx/generic/print/printerjob.cxx +++ b/vcl/unx/generic/print/printerjob.cxx @@ -25,6 +25,7 @@ #include "psputil.hxx" #include "glyphset.hxx" +#include "saldatabasic.hxx" #include "unx/printerjob.hxx" #include "unx/printergfx.hxx" @@ -477,7 +478,7 @@ PrinterJob::EndJob() } else { - PrinterInfoManager& rPrinterInfoManager = PrinterInfoManager::get (); + PrinterInfoManager& rPrinterInfoManager = *(GetSalData()->m_pPIManager); pDestFILE = rPrinterInfoManager.startSpool( m_aLastJobData.m_aPrinterName, m_bQuickJob ); if (pDestFILE == nullptr) return false; @@ -530,7 +531,8 @@ PrinterJob::EndJob() fclose (pDestFILE); else { - PrinterInfoManager& rPrinterInfoManager = PrinterInfoManager::get(); + + PrinterInfoManager& rPrinterInfoManager = *(GetSalData()->m_pPIManager); if (!rPrinterInfoManager.endSpool( m_aLastJobData.m_aPrinterName, maJobTitle, pDestFILE, m_aDocumentJobData, true, OUString())) { @@ -754,7 +756,9 @@ bool PrinterJob::writeFeatureList( osl::File* pFile, const JobData& rJob, bool b if( bHavePS2 ) continue; } - bSuccess = writeFeature( pFile, pKey, pValue, PrinterInfoManager::get().getUseIncludeFeature() ); + + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); + bSuccess = writeFeature( pFile, pKey, pValue, rManager.getUseIncludeFeature() ); } } } @@ -813,7 +817,8 @@ bool PrinterJob::writePageSetup( osl::File* pFile, const JobData& rJob, bool bWr void PrinterJob::writeJobPatch( osl::File* pFile, const JobData& rJobData ) { - if( ! PrinterInfoManager::get().getUseJobPatch() ) + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); + if( ! rManager.getUseJobPatch() ) return; const PPDKey* pKey = nullptr; @@ -983,7 +988,8 @@ bool PrinterJob::writeSetup( osl::File* pFile, const JobData& rJob ) bool bSuccess = true; // in case of external print dialog the number of copies is prepended // to the job, let us not complicate things by emitting our own copy count - bool bExternalDialog = PrinterInfoManager::get().checkFeatureToken( GetPrinterName(), "external_dialog" ); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); + bool bExternalDialog = rManager.checkFeatureToken( GetPrinterName(), "external_dialog" ); if( ! bExternalDialog && rJob.m_nCopies > 1 ) { // setup code diff --git a/vcl/unx/generic/printer/cupsmgr.cxx b/vcl/unx/generic/printer/cupsmgr.cxx index 9df3d3a7ee43..f3dac8e1942f 100644 --- a/vcl/unx/generic/printer/cupsmgr.cxx +++ b/vcl/unx/generic/printer/cupsmgr.cxx @@ -38,6 +38,8 @@ #include #include +#include "saldatabasic.hxx" + #include #include #include @@ -156,7 +158,7 @@ static const char* setPasswordCallback( const char* pIn ) { const char* pRet = nullptr; - PrinterInfoManager& rMgr = PrinterInfoManager::get(); + PrinterInfoManager& rMgr = *(GetSalData()->m_pPIManager); if( rMgr.getType() == PrinterInfoManager::Type::CUPS ) // sanity check pRet = static_cast(rMgr).authenticateUser( pIn ); return pRet; @@ -193,57 +195,12 @@ CUPSManager::CUPSManager() : m_bPPDThreadRunning( false ) { m_aDestThread = osl_createThread( run_dest_thread_stub, this ); -} - -CUPSManager::~CUPSManager() -{ - if( m_aDestThread ) - { - // if the thread is still running here, then - // cupsGetDests is hung; terminate the thread instead of joining - osl_terminateThread( m_aDestThread ); - osl_destroyThread( m_aDestThread ); - } - if (m_nDests && m_pDests) - cupsFreeDests( m_nDests, static_cast(m_pDests) ); -} - -void CUPSManager::runDestThread( void* pThis ) -{ - static_cast(pThis)->runDests(); -} - -void CUPSManager::runDests() -{ - SAL_INFO("vcl.unx.print", "starting cupsGetDests"); - cups_dest_t* pDests = nullptr; - - // n#722902 - do a fast-failing check for cups working *at all* first - http_t* p_http; - if( (p_http=httpConnectEncrypt( - cupsServer(), - ippPort(), - cupsEncryption())) != nullptr ) - { - int nDests = cupsGetDests2(p_http, &pDests); - SAL_INFO("vcl.unx.print", "came out of cupsGetDests"); - - osl::MutexGuard aGuard( m_aCUPSMutex ); - m_nDests = nDests; - m_pDests = pDests; - m_bNewDests = true; - SAL_INFO("vcl.unx.print", "finished cupsGetDests"); - - httpClose(p_http); - } + initialize(); } void CUPSManager::initialize() { - // get normal printers, clear printer list - PrinterInfoManager::initialize(); - // check whether thread has completed // if not behave like old printing system osl::MutexGuard aGuard( m_aCUPSMutex ); @@ -376,6 +333,50 @@ void CUPSManager::initialize() cupsSetPasswordCB( setPasswordCallback ); } +CUPSManager::~CUPSManager() +{ + if( m_aDestThread ) + { + // if the thread is still running here, then + // cupsGetDests is hung; terminate the thread instead of joining + osl_terminateThread( m_aDestThread ); + osl_destroyThread( m_aDestThread ); + } + + if (m_nDests && m_pDests) + cupsFreeDests( m_nDests, static_cast(m_pDests) ); +} + +void CUPSManager::runDestThread( void* pThis ) +{ + static_cast(pThis)->runDests(); +} + +void CUPSManager::runDests() +{ + SAL_INFO("vcl.unx.print", "starting cupsGetDests"); + cups_dest_t* pDests = nullptr; + + // n#722902 - do a fast-failing check for cups working *at all* first + http_t* p_http; + if( (p_http=httpConnectEncrypt( + cupsServer(), + ippPort(), + cupsEncryption())) != nullptr ) + { + int nDests = cupsGetDests2(p_http, &pDests); + SAL_INFO("vcl.unx.print", "came out of cupsGetDests"); + + osl::MutexGuard aGuard( m_aCUPSMutex ); + m_nDests = nDests; + m_pDests = pDests; + m_bNewDests = true; + SAL_INFO("vcl.unx.print", "finished cupsGetDests"); + + httpClose(p_http); + } +} + static void updatePrinterContextInfo( ppd_group_t* pPPDGroup, PPDContext& rContext ) { rtl_TextEncoding aEncoding = osl_getThreadTextEncoding(); diff --git a/vcl/unx/generic/printer/jobdata.cxx b/vcl/unx/generic/printer/jobdata.cxx index 920e430f6376..388c973ca8f3 100644 --- a/vcl/unx/generic/printer/jobdata.cxx +++ b/vcl/unx/generic/printer/jobdata.cxx @@ -25,6 +25,8 @@ #include #include +#include "saldatabasic.hxx" + using namespace psp; JobData& JobData::operator=(const JobData& rRight) @@ -46,7 +48,7 @@ JobData& JobData::operator=(const JobData& rRight) if( !m_pParser && !m_aPrinterName.isEmpty() ) { - PrinterInfoManager& rMgr = PrinterInfoManager::get(); + PrinterInfoManager& rMgr = *(GetSalData()->m_pPIManager); rMgr.setupJobContextData( *this ); } return *this; @@ -268,7 +270,7 @@ bool JobData::constructFromStreamBuffer( const void* pData, sal_uInt32 bytes, Jo { if( bPrinter ) { - PrinterInfoManager& rManager = PrinterInfoManager::get(); + PrinterInfoManager& rManager = *(GetSalData()->m_pPIManager); const JobData& rInfo = rManager.getPrinterInfo( rJobData.m_aPrinterName ); rJobData.m_pParser = PPDParser::getParser( rInfo.m_aDriverName ); if( rJobData.m_pParser ) diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx index 5d6ad5e90b13..40bf177a69d8 100644 --- a/vcl/unx/generic/printer/ppdparser.cxx +++ b/vcl/unx/generic/printer/ppdparser.cxx @@ -41,6 +41,8 @@ #include #include +#include "saldatabasic.hxx" + #include "com/sun/star/lang/Locale.hpp" #include @@ -566,7 +568,7 @@ const PPDParser* PPDParser::getParser( const OUString& rFile ) pNewParser = new PPDParser( aFile ); else { - PrinterInfoManager& rMgr = PrinterInfoManager::get(); + PrinterInfoManager& rMgr = *(GetSalData()->m_pPIManager); if( rMgr.getType() == PrinterInfoManager::Type::CUPS ) { #ifdef ENABLE_CUPS diff --git a/vcl/unx/generic/printer/printerinfomanager.cxx b/vcl/unx/generic/printer/printerinfomanager.cxx index 86fac391429d..08a315b818e4 100644 --- a/vcl/unx/generic/printer/printerinfomanager.cxx +++ b/vcl/unx/generic/printer/printerinfomanager.cxx @@ -78,32 +78,6 @@ namespace psp * class PrinterInfoManager */ -PrinterInfoManager& PrinterInfoManager::get() -{ - SalData* pSalData = GetSalData(); - - if( ! pSalData->m_pPIManager ) - { - pSalData->m_pPIManager = CUPSManager::tryLoadCUPS(); - if( ! pSalData->m_pPIManager ) - pSalData->m_pPIManager = new PrinterInfoManager(); - - pSalData->m_pPIManager->initialize(); -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, "PrinterInfoManager::get create Manager of type %d\n", pSalData->m_pPIManager->getType() ); -#endif - } - - return *pSalData->m_pPIManager; -} - -void PrinterInfoManager::release() -{ - SalData* pSalData = GetSalData(); - delete pSalData->m_pPIManager; - pSalData->m_pPIManager = nullptr; -} - PrinterInfoManager::PrinterInfoManager( Type eType ) : m_pQueueInfo( nullptr ), m_eType( eType ), @@ -117,6 +91,8 @@ PrinterInfoManager::PrinterInfoManager( Type eType ) : m_aSystemDefaultPaper = OStringToOUString( PaperInfo::toPSName(PaperInfo::getSystemDefaultPaper().getPaper()), RTL_TEXTENCODING_UTF8); + + initialize(); } PrinterInfoManager::~PrinterInfoManager() -- cgit