ucb/source/ucp/file/bc.cxx     |   65 +++++++++++++++++++++++++++++++++++++----
 ucb/source/ucp/file/filnot.cxx |   20 ++----------
 ucb/source/ucp/file/filnot.hxx |    3 +
 3 files changed, 65 insertions(+), 23 deletions(-)

New commits:
commit 75a1a63108d39eab905058d1bd295b74ecf34663
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sun Nov 28 21:25:02 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Nov 30 13:11:49 2021 +0100

    use more OInterfaceContainerHelper3 in PropertyListeners
    
    Change-Id: I44b06c1ab469e99a9d3b8f4e2b0f3058959fc202
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126063
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/ucb/source/ucp/file/bc.cxx b/ucb/source/ucp/file/bc.cxx
index acf68ce65c61..3575ac7f0f85 100644
--- a/ucb/source/ucp/file/bc.cxx
+++ b/ucb/source/ucp/file/bc.cxx
@@ -54,16 +54,69 @@ using namespace com::sun::star::ucb;
 #define THROW_WHERE ""
 #endif
 
-typedef comphelper::OMultiTypeInterfaceContainerHelperVar2<OUString>
-    PropertyListeners_impl;
-
 class fileaccess::PropertyListeners
-    : public PropertyListeners_impl
 {
+    typedef 
comphelper::OInterfaceContainerHelper3<beans::XPropertiesChangeListener> 
ContainerHelper;
+    osl::Mutex& rMutex;
+    std::unordered_map<OUString, ContainerHelper> m_aMap;
 public:
     explicit PropertyListeners( ::osl::Mutex& aMutex )
-        : PropertyListeners_impl( aMutex )
+        : rMutex( aMutex )
+    {
+    }
+    void disposeAndClear(const lang::EventObject& rEvt)
+    {
+        // create a copy, because do not fire event in a guarded section
+        std::unordered_map<OUString, ContainerHelper> tempMap;
+        {
+            ::osl::MutexGuard aGuard(rMutex);
+            tempMap = std::move(m_aMap);
+        }
+        for (auto& rPair : tempMap)
+            rPair.second.disposeAndClear(rEvt);
+    }
+    void addInterface(const OUString& rKey, const 
uno::Reference<beans::XPropertiesChangeListener>& rListener)
+    {
+        ::osl::MutexGuard aGuard(rMutex);
+        auto iter = m_aMap.find(rKey);
+        if (iter == m_aMap.end())
+        {
+            auto ret = m_aMap.emplace(rKey, rMutex);
+            ret.first->second.addInterface(rListener);
+        }
+        else
+            iter->second.addInterface(rListener);
+    }
+    void removeInterface(const OUString& rKey, const 
uno::Reference<beans::XPropertiesChangeListener>& rListener)
     {
+        ::osl::MutexGuard aGuard(rMutex);
+
+        // search container with id rKey
+        auto iter = m_aMap.find(rKey);
+        // container found?
+        if (iter != m_aMap.end())
+            iter->second.removeInterface(rListener);
+    }
+    std::vector< OUString > getContainedTypes() const
+    {
+        ::osl::MutexGuard aGuard(rMutex);
+        std::vector<OUString> aInterfaceTypes;
+        aInterfaceTypes.reserve(m_aMap.size());
+        for (const auto& rPair : m_aMap)
+            // are interfaces added to this container?
+            if (rPair.second.getLength())
+                // yes, put the type in the array
+                aInterfaceTypes.push_back(rPair.first);
+        return aInterfaceTypes;
+    }
+    comphelper::OInterfaceContainerHelper3<beans::XPropertiesChangeListener>* 
getContainer(const OUString& rKey)
+    {
+        ::osl::MutexGuard aGuard(rMutex);
+
+        auto iter = m_aMap.find(rKey);
+        if (iter != m_aMap.end())
+            return &iter->second;
+        return nullptr;
     }
 };
 
@@ -1153,7 +1206,7 @@ BaseContent::cPCL()
     ListenerMap listener;
     for( const auto& rName : seqNames )
     {
-        comphelper::OInterfaceContainerHelper2* pContainer = 
m_pPropertyListener->getContainer(rName);
+        
comphelper::OInterfaceContainerHelper3<beans::XPropertiesChangeListener>* 
pContainer = m_pPropertyListener->getContainer(rName);
         if (!pContainer)
             continue;
         listener[rName] = pContainer->getElements();
diff --git a/ucb/source/ucp/file/filnot.cxx b/ucb/source/ucp/file/filnot.cxx
index 6dce30f03cd8..013311e2d1bc 100644
--- a/ucb/source/ucp/file/filnot.cxx
+++ b/ucb/source/ucp/file/filnot.cxx
@@ -187,15 +187,9 @@ void PropertyChangeNotifier::notifyPropertyChanged(
     auto it = m_aListeners.find( OUString() );
     if (it != m_aListeners.end())
     {
-        const std::vector< uno::Reference< uno::XInterface > >& seqList = 
it->second;
+        const std::vector< uno::Reference< beans::XPropertiesChangeListener > 
>& seqList = it->second;
         for( const auto& rListener : seqList )
-        {
-            uno::Reference< beans::XPropertiesChangeListener > aListener( 
rListener,uno::UNO_QUERY );
-            if( aListener.is() )
-            {
-                aListener->propertiesChange( Changes );
-            }
-        }
+            rListener->propertiesChange( Changes );
     }
 
     for( const auto& rChange : std::as_const(Changes) )
@@ -204,15 +198,9 @@ void PropertyChangeNotifier::notifyPropertyChanged(
         it = m_aListeners.find( rChange.PropertyName );
         if (it != m_aListeners.end())
         {
-            const std::vector< uno::Reference< uno::XInterface > >& seqList = 
it->second;
+            const std::vector< uno::Reference< 
beans::XPropertiesChangeListener > >& seqList = it->second;
             for( const auto& rListener : seqList )
-            {
-                uno::Reference< beans::XPropertiesChangeListener > aListener( 
rListener,uno::UNO_QUERY );
-                if( aListener.is() )
-                {
-                    aListener->propertiesChange( seq );
-                }
-            }
+                rListener->propertiesChange( seq );
         }
     }
 }
diff --git a/ucb/source/ucp/file/filnot.hxx b/ucb/source/ucp/file/filnot.hxx
index 0d336ad0697b..f51a0e67332c 100644
--- a/ucb/source/ucp/file/filnot.hxx
+++ b/ucb/source/ucp/file/filnot.hxx
@@ -22,6 +22,7 @@
 #include <com/sun/star/uno/XInterface.hpp>
 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
 #include <com/sun/star/beans/XPropertySetInfoChangeListener.hpp>
+#include <com/sun/star/beans/XPropertiesChangeListener.hpp>
 #include <com/sun/star/ucb/XContentIdentifier.hpp>
 #include <com/sun/star/ucb/XContent.hpp>
 #include <memory>
@@ -79,7 +80,7 @@ namespace fileaccess {
 
 
     typedef std::unordered_map< OUString,
-                           std::vector< css::uno::Reference< 
css::uno::XInterface > > >  ListenerMap;
+                           std::vector< css::uno::Reference< 
css::beans::XPropertiesChangeListener > > >  ListenerMap;
 
     class PropertyChangeNotifier
     {

Reply via email to