vcl/inc/printerinfomanager.hxx                 |    2 -
 vcl/inc/saldatabasic.hxx                       |    8 ----
 vcl/inc/unx/gendata.hxx                        |    5 ++
 vcl/null/printerinfomanager.cxx                |   16 ++------
 vcl/source/app/salplug.cxx                     |    6 ---
 vcl/unx/generic/app/gendata.cxx                |    8 +++-
 vcl/unx/generic/printer/printerinfomanager.cxx |   45 ++++++++++---------------
 7 files changed, 34 insertions(+), 56 deletions(-)

New commits:
commit bc3f70f220091f09ad02c148a6a49fdccb7b85c5
Author:     Jan-Marek Glogowski <glo...@fbihome.de>
AuthorDate: Thu Jan 13 20:15:39 2022 +0100
Commit:     Jan-Marek Glogowski <glo...@fbihome.de>
CommitDate: Fri Jan 14 09:07:28 2022 +0100

    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 <glo...@fbihome.de>

diff --git a/vcl/inc/printerinfomanager.hxx b/vcl/inc/printerinfomanager.hxx
index 2286158d66af..3b5394ace0e9 100644
--- a/vcl/inc/printerinfomanager.hxx
+++ b/vcl/inc/printerinfomanager.hxx
@@ -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; }
diff --git a/vcl/inc/saldatabasic.hxx b/vcl/inc/saldatabasic.hxx
index 85911718815a..4703dddd61d6 100644
--- a/vcl/inc/saldatabasic.hxx
+++ b/vcl/inc/saldatabasic.hxx
@@ -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;
diff --git a/vcl/inc/unx/gendata.hxx b/vcl/inc/unx/gendata.hxx
index f20281ff0602..fc55125fe199 100644
--- a/vcl/inc/unx/gendata.hxx
+++ b/vcl/inc/unx/gendata.hxx
@@ -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();
diff --git a/vcl/null/printerinfomanager.cxx b/vcl/null/printerinfomanager.cxx
index c51ed6a9d73a..24515dbc149e 100644
--- a/vcl/null/printerinfomanager.cxx
+++ b/vcl/null/printerinfomanager.cxx
@@ -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 ) :
diff --git a/vcl/source/app/salplug.cxx b/vcl/source/app/salplug.cxx
index 968ec902a4e0..f01bd6e5a2c0 100644
--- a/vcl/source/app/salplug.cxx
+++ b/vcl/source/app/salplug.cxx
@@ -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
diff --git a/vcl/unx/generic/app/gendata.cxx b/vcl/unx/generic/app/gendata.cxx
index 39dbc6224e5a..479694c6dd73 100644
--- a/vcl/unx/generic/app/gendata.cxx
+++ b/vcl/unx/generic/app/gendata.cxx
@@ -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); }
 
diff --git a/vcl/unx/generic/printer/printerinfomanager.cxx 
b/vcl/unx/generic/printer/printerinfomanager.cxx
index 2a1dbbfc41a4..f5af9b0b0c8c 100644
--- a/vcl/unx/generic/printer/printerinfomanager.cxx
+++ b/vcl/unx/generic/printer/printerinfomanager.cxx
@@ -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();
-
-    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
-    }
-
-    return *pSalData->m_pPIManager;
-}
-
-void PrinterInfoManager::release()
-{
-    SalData* pSalData = GetSalData();
-    delete pSalData->m_pPIManager;
-    pSalData->m_pPIManager = nullptr;
+    // can't move to GenericUnixSalData, because of 
vcl/null/printerinfomanager.cxx
+    GenericUnixSalData* pSalData = GetGenericUnixSalData();
+    PrinterInfoManager* pPIM = pSalData->m_pPrinterInfoManager.get();
+    if (pPIM)
+        return *pPIM;
+
+    pPIM = CPDManager::tryLoadCPD();
+    if (!pPIM)
+        pPIM = CUPSManager::tryLoadCUPS();
+    if (!pPIM)
+        pPIM = new PrinterInfoManager();
+    pSalData->m_pPrinterInfoManager.reset(pPIM);
+    pPIM->initialize();
+
+    SAL_INFO("vcl.unx.print", "created PrinterInfoManager of type "
+                               << static_cast<int>(pPIM->getType()));
+    return *pPIM;
 }
 
 PrinterInfoManager::PrinterInfoManager( Type eType ) :

Reply via email to