summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-06-13 11:40:36 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-06-13 19:54:38 +0200
commit91955babdb99cddef764a8467ee7e2e5bfa6f7d3 (patch)
tree95cf97ab835fb91ffac15cccef50b2ea2f1ce1a9
parent5dc1d4453738876c0576c45b826b9f01d29e8905 (diff)
use more concrete UNO types in OStorage
Change-Id: Iab01137ad1ad8ea68b5a98ae4c251389a1748da1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168778 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--package/source/xstor/ohierarchyholder.cxx26
-rw-r--r--package/source/xstor/ohierarchyholder.hxx16
-rw-r--r--package/source/xstor/xstorage.cxx20
-rw-r--r--package/source/xstor/xstorage.hxx5
4 files changed, 37 insertions, 30 deletions
diff --git a/package/source/xstor/ohierarchyholder.cxx b/package/source/xstor/ohierarchyholder.cxx
index b2fb66cfc29e..d8dcb1e70723 100644
--- a/package/source/xstor/ohierarchyholder.cxx
+++ b/package/source/xstor/ohierarchyholder.cxx
@@ -31,6 +31,7 @@
#include <o3tl/string_view.hxx>
#include "ohierarchyholder.hxx"
+#include "xstorage.hxx"
using namespace ::com::sun::star;
@@ -38,7 +39,7 @@ using namespace ::com::sun::star;
uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, std::vector<OUString>& aListPath, sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData )
{
- uno::Reference< embed::XStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW );
+ rtl::Reference< OStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW );
if ( !( nStorageMode & embed::ElementModes::WRITE ) && ( nStreamMode & embed::ElementModes::WRITE ) )
throw io::IOException(u"invalid storage/stream mode combo"_ustr);
@@ -53,7 +54,7 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStream
void OHierarchyHolder_Impl::RemoveStreamHierarchically( std::vector<OUString>& aListPath )
{
- uno::Reference< embed::XStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW );
+ rtl::Reference< OStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW );
m_xChild->RemoveStreamHierarchically( aListPath );
}
@@ -93,19 +94,19 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStrea
uno::Reference< embed::XExtendedStorageStream > xResult;
- uno::Reference< embed::XStorage > xOwnStor = m_xOwnStorage.is() ? m_xOwnStorage
- : uno::Reference< embed::XStorage >( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW );
+ rtl::Reference< OStorage > xOwnStor = m_xOwnStorage.is() ? m_xOwnStorage
+ : rtl::Reference< OStorage >( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW );
if ( aListPath.empty() )
{
if ( aEncryptionData.empty() )
{
- uno::Reference< embed::XHierarchicalStorageAccess > xHStorage( xOwnStor, uno::UNO_QUERY_THROW );
+ rtl::Reference< OStorage > xHStorage( xOwnStor, uno::UNO_QUERY_THROW );
xResult = xHStorage->openStreamElementByHierarchicalName( aNextName, nStreamMode );
}
else
{
- uno::Reference< embed::XHierarchicalStorageAccess2 > xHStorage( xOwnStor, uno::UNO_QUERY_THROW );
+ rtl::Reference< OStorage > xHStorage( xOwnStor, uno::UNO_QUERY_THROW );
xResult = xHStorage->openEncryptedStreamByHierarchicalName( aNextName, nStreamMode, aEncryptionData.getAsConstNamedValueList() );
}
@@ -136,7 +137,7 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStrea
if ( !aElement.is() )
{
bNewElement = true;
- uno::Reference< embed::XStorage > xChildStorage = xOwnStor->openStorageElement( aNextName, nStorageMode );
+ rtl::Reference< OStorage > xChildStorage = xOwnStor->openStorageElement2( aNextName, nStorageMode );
if ( !xChildStorage.is() )
throw uno::RuntimeException();
@@ -170,8 +171,8 @@ void OHierarchyElement_Impl::RemoveStreamHierarchically( std::vector<OUString>&
OUString aNextName = *(aListPath.begin());
aListPath.erase( aListPath.begin() );
- uno::Reference< embed::XStorage > xOwnStor = m_xOwnStorage.is() ? m_xOwnStorage
- : uno::Reference< embed::XStorage >( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW );
+ rtl::Reference< OStorage > xOwnStor = m_xOwnStorage.is() ? m_xOwnStorage
+ : rtl::Reference< OStorage >( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW );
if ( aListPath.empty() )
{
@@ -186,7 +187,7 @@ void OHierarchyElement_Impl::RemoveStreamHierarchically( std::vector<OUString>&
if ( !aElement.is() )
{
- uno::Reference< embed::XStorage > xChildStorage = xOwnStor->openStorageElement( aNextName,
+ rtl::Reference< OStorage > xChildStorage = xOwnStor->openStorageElement2( aNextName,
embed::ElementModes::READWRITE );
if ( !xChildStorage.is() )
throw uno::RuntimeException();
@@ -197,9 +198,8 @@ void OHierarchyElement_Impl::RemoveStreamHierarchically( std::vector<OUString>&
aElement->RemoveStreamHierarchically( aListPath );
}
- uno::Reference< embed::XTransactedObject > xTransact( xOwnStor, uno::UNO_QUERY );
- if ( xTransact.is() )
- xTransact->commit();
+ if ( xOwnStor.is() )
+ xOwnStor->commit();
TestForClosing();
}
diff --git a/package/source/xstor/ohierarchyholder.hxx b/package/source/xstor/ohierarchyholder.hxx
index c3ceddabd1b1..6ab833870507 100644
--- a/package/source/xstor/ohierarchyholder.hxx
+++ b/package/source/xstor/ohierarchyholder.hxx
@@ -25,6 +25,7 @@
#include <com/sun/star/embed/XExtendedStorageStream.hpp>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/weakref.hxx>
+#include <unotools/weakref.hxx>
#include <comphelper/sequenceashashmap.hxx>
@@ -35,6 +36,7 @@
#include <vector>
class OHierarchyElement_Impl;
+class OStorage;
typedef std::unordered_map< OUString,
::rtl::Reference< OHierarchyElement_Impl > > OHierarchyElementList_Impl;
@@ -47,19 +49,19 @@ class OHierarchyElement_Impl : public cppu::WeakImplHelper< css::embed::XTransac
std::mutex m_aMutex;
::rtl::Reference< OHierarchyElement_Impl > m_rParent;
- css::uno::Reference< css::embed::XStorage > m_xOwnStorage;
- css::uno::WeakReference< css::embed::XStorage > m_xWeakOwnStorage;
+ rtl::Reference< OStorage > m_xOwnStorage;
+ unotools::WeakReference< OStorage > m_xWeakOwnStorage;
OHierarchyElementList_Impl m_aChildren;
OWeakStorRefVector_Impl m_aOpenStreams;
public:
- explicit OHierarchyElement_Impl( css::uno::Reference< css::embed::XStorage > xStorage )
+ explicit OHierarchyElement_Impl(rtl::Reference< OStorage > xStorage )
: m_xOwnStorage(std::move( xStorage ))
{}
- explicit OHierarchyElement_Impl( css::uno::WeakReference< css::embed::XStorage > xWeakStorage )
+ explicit OHierarchyElement_Impl( unotools::WeakReference< OStorage > xWeakStorage )
: m_xWeakOwnStorage(std::move( xWeakStorage ))
{}
@@ -92,12 +94,12 @@ public:
class OHierarchyHolder_Impl : public ::cppu::OWeakObject
{
- css::uno::WeakReference< css::embed::XStorage > m_xWeakOwnStorage;
+ unotools::WeakReference< OStorage > m_xWeakOwnStorage;
::rtl::Reference< OHierarchyElement_Impl > m_xChild;
public:
- explicit OHierarchyHolder_Impl( const css::uno::Reference< css::embed::XStorage >& xOwnStorage )
+ explicit OHierarchyHolder_Impl( const rtl::Reference< OStorage >& xOwnStorage )
: m_xWeakOwnStorage( xOwnStorage )
- , m_xChild( new OHierarchyElement_Impl( css::uno::WeakReference< css::embed::XStorage >( xOwnStorage ) ) )
+ , m_xChild( new OHierarchyElement_Impl( unotools::WeakReference< OStorage >( xOwnStorage ) ) )
{}
static std::vector<OUString> GetListPathFromString( std::u16string_view aPath );
diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx
index 1abfdf89be4a..9f72b0fd458a 100644
--- a/package/source/xstor/xstorage.cxx
+++ b/package/source/xstor/xstorage.cxx
@@ -2299,6 +2299,12 @@ uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStreamElement(
uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
const OUString& aStorName, sal_Int32 nStorageMode )
{
+ return openStorageElement2(aStorName, nStorageMode);
+}
+
+rtl::Reference< OStorage > OStorage::openStorageElement2(
+ const OUString& aStorName, sal_Int32 nStorageMode )
+{
::osl::MutexGuard aGuard( m_xSharedMutex->GetMutex() );
if ( !m_pImpl )
@@ -2323,7 +2329,7 @@ uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
// it's always possible to read written storage in this implementation
nStorageMode |= embed::ElementModes::READ;
- uno::Reference< embed::XStorage > xResult;
+ rtl::Reference< OStorage > xResult;
try
{
SotElement_Impl *pElement = m_pImpl->FindElement( aStorName );
@@ -2386,8 +2392,7 @@ uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
pElement->m_xStorage->SetReadOnlyWrap(*pResultStorage);
// before the storage disposes the stream it must deregister itself as listener
- uno::Reference< lang::XComponent > xStorageComponent( xResult, uno::UNO_QUERY_THROW );
- MakeLinkToSubComponent_Impl( xStorageComponent );
+ MakeLinkToSubComponent_Impl( xResult );
}
}
catch( const embed::InvalidStorageException& )
@@ -5384,8 +5389,7 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openStreamEle
{
// there are still storages in between
if ( !m_rHierarchyHolder.is() )
- m_rHierarchyHolder = new OHierarchyHolder_Impl(
- uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
+ m_rHierarchyHolder = new OHierarchyHolder_Impl( rtl::Reference< OStorage >( this ) );
xResult = m_rHierarchyHolder->GetStreamHierarchically(
( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ),
@@ -5424,8 +5428,7 @@ void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const OUString& a
OSL_ENSURE( aListPath.size(), "The result list must not be empty!" );
if ( !m_rHierarchyHolder.is() )
- m_rHierarchyHolder = new OHierarchyHolder_Impl(
- uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
+ m_rHierarchyHolder = new OHierarchyHolder_Impl( rtl::Reference< OStorage >( this ) );
m_rHierarchyHolder->RemoveStreamHierarchically( aListPath );
}
@@ -5473,8 +5476,7 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted
{
// there are still storages in between
if ( !m_rHierarchyHolder.is() )
- m_rHierarchyHolder = new OHierarchyHolder_Impl(
- uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) );
+ m_rHierarchyHolder = new OHierarchyHolder_Impl( rtl::Reference< OStorage >( this ) );
xResult = m_rHierarchyHolder->GetStreamHierarchically(
( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ),
diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx
index 54fe49a9d9ca..3d6186106de1 100644
--- a/package/source/xstor/xstorage.hxx
+++ b/package/source/xstor/xstorage.hxx
@@ -346,7 +346,10 @@ public:
const OUString& aStreamName, sal_Int32 nOpenMode, const OUString& aPass ) override;
virtual css::uno::Reference< css::embed::XStorage > SAL_CALL openStorageElement(
- const OUString& aStorName, sal_Int32 nStorageMode ) override;
+ const OUString& aStorName, sal_Int32 nStorageMode ) override final;
+
+ rtl::Reference< OStorage > openStorageElement2(
+ const OUString& aStorName, sal_Int32 nStorageMode );
virtual css::uno::Reference< css::io::XStream > SAL_CALL cloneStreamElement(
const OUString& aStreamName ) override;