VCL move PrinterInfoManager into GenericUnixSalData

... and use a std::unique_ptr.

PrinterInfoManager::release() was just called from ~SalData(),
so this should make this more clear.

Change-Id: Ic4aade2db3813fdc96ede116a50604692ef3dbec
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128399
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
This commit is contained in:
Jan-Marek Glogowski
2022-01-14 09:07:28 +01:00
parent fa7389b430
commit bc3f70f220
7 changed files with 32 additions and 54 deletions
-2
View File
@@ -127,8 +127,6 @@ public:
// there can only be one
static PrinterInfoManager& get();
// only called by SalData destructor, frees the global instance
static void release();
// get PrinterInfoManager type
Type getType() const { return m_eType; }
-8
View File
@@ -29,18 +29,10 @@
#include "quartz/salgdi.h"
#endif
namespace psp
{
class PrinterInfoManager;
}
class VCL_PLUGIN_PUBLIC SalData
{
public:
SalInstance* m_pInstance; // pointer to instance
#ifndef IOS
psp::PrinterInfoManager* m_pPIManager;
#endif
SalData();
virtual ~SalData() COVERITY_NOEXCEPT_FALSE;
+4 -1
View File
@@ -21,11 +21,13 @@ class SalGenericDisplay;
namespace psp
{
class PrintFontManager;
class PrinterInfoManager;
}
class VCL_DLLPUBLIC GenericUnixSalData : public SalData
{
private:
friend class ::psp::PrinterInfoManager;
SalGenericDisplay* m_pDisplay;
// cached hostname to avoid slow lookup
OUString m_aHostname;
@@ -34,6 +36,7 @@ private:
std::unique_ptr<FreetypeManager> m_pFreetypeManager;
std::unique_ptr<psp::PrintFontManager> m_pPrintFontManager;
std::unique_ptr<psp::PrinterInfoManager> m_pPrinterInfoManager;
void InitFreetypeManager();
void InitPrintFontManager();
+4 -12
View File
@@ -32,20 +32,12 @@ namespace psp
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;
GenericUnixSalData* pSalData = GetGenericUnixSalData();
if (!pSalData->m_pPrinterInfoManager)
pSalData->m_pPrinterInfoManager.reset(new PrinterInfoManager());
return *pSalData->m_pPrinterInfoManager;
}
PrinterInfoManager::PrinterInfoManager( Type eType ) :
+1 -5
View File
@@ -404,16 +404,12 @@ const OUString& SalGetDesktopEnvironment()
}
SalData::SalData() :
m_pInstance(nullptr),
m_pPIManager(nullptr)
m_pInstance(nullptr)
{
}
SalData::~SalData() COVERITY_NOEXCEPT_FALSE
{
#if (defined UNX && !defined MACOSX)
psp::PrinterInfoManager::release();
#endif
}
#ifdef _WIN32
+7 -1
View File
@@ -21,6 +21,7 @@
#include <unx/fontmanager.hxx>
#include <unx/glyphcache.hxx>
#include <printerinfomanager.hxx>
GenericUnixSalData::GenericUnixSalData(SalInstance* const pInstance)
: m_pDisplay(nullptr)
@@ -29,7 +30,12 @@ GenericUnixSalData::GenericUnixSalData(SalInstance* const pInstance)
SetSalData(this);
}
GenericUnixSalData::~GenericUnixSalData() {}
GenericUnixSalData::~GenericUnixSalData()
{
m_pPrintFontManager.reset();
m_pFreetypeManager.reset();
m_pPrinterInfoManager.reset();
}
void GenericUnixSalData::InitFreetypeManager() { m_pFreetypeManager.reset(new FreetypeManager); }
+16 -25
View File
@@ -19,10 +19,9 @@
#include <unx/cpdmgr.hxx>
#include <unx/cupsmgr.hxx>
#include <unx/gendata.hxx>
#include <unx/helper.hxx>
#include <saldatabasic.hxx>
#include <tools/urlobj.hxx>
#include <tools/config.hxx>
@@ -75,31 +74,23 @@ namespace psp
PrinterInfoManager& PrinterInfoManager::get()
{
SalData* pSalData = GetSalData();
// can't move to GenericUnixSalData, because of vcl/null/printerinfomanager.cxx
GenericUnixSalData* pSalData = GetGenericUnixSalData();
PrinterInfoManager* pPIM = pSalData->m_pPrinterInfoManager.get();
if (pPIM)
return *pPIM;
if( ! pSalData->m_pPIManager )
{
pSalData->m_pPIManager = CPDManager::tryLoadCPD();
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
SAL_INFO("vcl.unx.print", "PrinterInfoManager::get "
<< "create Manager of type "
<< ((int) pSalData->m_pPIManager->getType()));
#endif
}
pPIM = CPDManager::tryLoadCPD();
if (!pPIM)
pPIM = CUPSManager::tryLoadCUPS();
if (!pPIM)
pPIM = new PrinterInfoManager();
pSalData->m_pPrinterInfoManager.reset(pPIM);
pPIM->initialize();
return *pSalData->m_pPIManager;
}
void PrinterInfoManager::release()
{
SalData* pSalData = GetSalData();
delete pSalData->m_pPIManager;
pSalData->m_pPIManager = nullptr;
SAL_INFO("vcl.unx.print", "created PrinterInfoManager of type "
<< static_cast<int>(pPIM->getType()));
return *pPIM;
}
PrinterInfoManager::PrinterInfoManager( Type eType ) :