summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-04-29 15:49:46 +0200
committerCaolán McNamara <caolanm@redhat.com>2015-04-30 08:08:54 +0000
commite8777783db81279a6b0e9cc7b308f10719bd8a7b (patch)
tree406311c43502f1d4f46313abd1dbe1d4d24359ac
parent121a2c44c90004300b41bee1492c614dc0fe57aa (diff)
rhbz#1213173: connectivity: Calc driver: prevent document being disposed
... by adding a XCloseListener that vetoes any attempt to close it. The Calc document can be opened by the user in the UI and closed again. (cherry picked from commit 7368b6ca3f61e750765f42e97d0a00e10fcac516) Conflicts: unotools/source/misc/closeveto.cxx Change-Id: Ied427b67274d925c911e516c0a50a4c0b2b18db9 Reviewed-on: https://gerrit.libreoffice.org/15567 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--connectivity/source/drivers/calc/CConnection.cxx10
-rw-r--r--connectivity/source/inc/calc/CConnection.hxx10
-rw-r--r--include/unotools/closeveto.hxx3
-rw-r--r--unotools/source/misc/closeveto.cxx17
4 files changed, 26 insertions, 14 deletions
diff --git a/connectivity/source/drivers/calc/CConnection.cxx b/connectivity/source/drivers/calc/CConnection.cxx
index c71f345ca40a..2e739d28324d 100644
--- a/connectivity/source/drivers/calc/CConnection.cxx
+++ b/connectivity/source/drivers/calc/CConnection.cxx
@@ -31,6 +31,7 @@
#include "calc/CPreparedStatement.hxx"
#include "calc/CStatement.hxx"
#include <unotools/pathoptions.hxx>
+#include <unotools/closeveto.hxx>
#include <connectivity/dbexception.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <comphelper/processfactory.hxx>
@@ -165,13 +166,17 @@ Reference< XSpreadsheetDocument> OCalcConnection::acquireDoc()
::dbtools::throwGenericSQLException( sError, *this, aErrorDetails );
}
osl_atomic_increment(&m_nDocCount);
+ m_pCloseListener.reset(new utl::CloseVeto(m_xDoc, true));
return m_xDoc;
}
void OCalcConnection::releaseDoc()
{
if ( osl_atomic_decrement(&m_nDocCount) == 0 )
- ::comphelper::disposeComponent( m_xDoc );
+ {
+ m_pCloseListener.reset(); // dispose m_xDoc
+ m_xDoc.clear();
+ }
}
void OCalcConnection::disposing()
@@ -179,7 +184,8 @@ void OCalcConnection::disposing()
::osl::MutexGuard aGuard(m_aMutex);
m_nDocCount = 0;
- ::comphelper::disposeComponent( m_xDoc );
+ m_pCloseListener.reset(); // dispose m_xDoc
+ m_xDoc.clear();
OConnection::disposing();
}
diff --git a/connectivity/source/inc/calc/CConnection.hxx b/connectivity/source/inc/calc/CConnection.hxx
index b66d892570ac..14e85808451d 100644
--- a/connectivity/source/inc/calc/CConnection.hxx
+++ b/connectivity/source/inc/calc/CConnection.hxx
@@ -23,9 +23,11 @@
#include "file/FConnection.hxx"
#include <com/sun/star/uno/DeploymentException.hpp>
-namespace com { namespace sun { namespace star { namespace sheet {
- class XSpreadsheetDocument;
-} } } }
+namespace com { namespace sun { namespace star {
+ namespace sheet { class XSpreadsheetDocument; }
+} } }
+
+namespace utl { class CloseVeto; }
namespace connectivity
@@ -37,6 +39,8 @@ namespace connectivity
{
// the spreadsheet document:
::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument > m_xDoc;
+ /// close listener that vetoes so nobody disposes m_xDoc
+ ::std::unique_ptr< ::utl::CloseVeto> m_pCloseListener;
OUString m_sPassword;
OUString m_aFileName;
oslInterlockedCount m_nDocCount;
diff --git a/include/unotools/closeveto.hxx b/include/unotools/closeveto.hxx
index 9beb0b55361e..9ed27a754f76 100644
--- a/include/unotools/closeveto.hxx
+++ b/include/unotools/closeveto.hxx
@@ -41,7 +41,8 @@ namespace utl
class UNOTOOLS_DLLPUBLIC CloseVeto
{
public:
- CloseVeto( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& i_closeable );
+ CloseVeto( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& i_closeable,
+ bool bHasOwnership = false);
~CloseVeto();
private:
diff --git a/unotools/source/misc/closeveto.cxx b/unotools/source/misc/closeveto.cxx
index 4044fa775e4b..9ecf82e96852 100644
--- a/unotools/source/misc/closeveto.cxx
+++ b/unotools/source/misc/closeveto.cxx
@@ -51,8 +51,8 @@ namespace utl
class CloseListener_Impl : public CloseListener_Base
{
public:
- CloseListener_Impl()
- :m_bHasOwnership( false )
+ CloseListener_Impl(bool const bHasOwnership)
+ : m_bHasOwnership(bHasOwnership)
{
}
@@ -107,12 +107,13 @@ namespace utl
namespace
{
- void lcl_init( CloseVeto_Data& i_data, const Reference< XInterface >& i_closeable )
+ void lcl_init( CloseVeto_Data& i_data, const Reference< XInterface >& i_closeable,
+ bool const hasOwnership)
{
i_data.xCloseable.set( i_closeable, UNO_QUERY );
ENSURE_OR_RETURN_VOID( i_data.xCloseable.is(), "CloseVeto: the component is not closeable!" );
- i_data.pListener = new CloseListener_Impl;
+ i_data.pListener = new CloseListener_Impl(hasOwnership);
i_data.xCloseable->addCloseListener( i_data.pListener.get() );
}
@@ -138,11 +139,11 @@ namespace utl
}
//= CloseVeto
-
- CloseVeto::CloseVeto( const Reference< XInterface >& i_closeable )
- :m_pData( new CloseVeto_Data )
+ CloseVeto::CloseVeto(const Reference< XInterface >& i_closeable,
+ bool const hasOwnership)
+ : m_pData(new CloseVeto_Data)
{
- lcl_init( *m_pData, i_closeable );
+ lcl_init(*m_pData, i_closeable, hasOwnership);
}
CloseVeto::~CloseVeto()