[Libreoffice-commits] core.git: dbaccess/Library_dba.mk dbaccess/source
Stephan Bergmann
sbergman at redhat.com
Fri Aug 16 06:02:52 PDT 2013
dbaccess/Library_dba.mk | 1
dbaccess/source/core/api/querycontainer.cxx | 72 +++++++-------
dbaccess/source/core/dataaccess/connection.cxx | 2
dbaccess/source/core/inc/ContainerListener.hxx | 80 ----------------
dbaccess/source/core/inc/querycontainer.hxx | 20 ++--
dbaccess/source/core/misc/ContainerListener.cxx | 119 ------------------------
6 files changed, 51 insertions(+), 243 deletions(-)
New commits:
commit c9db5e6f083aea2622559efcb9fcccef7926fd16
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Fri Aug 16 14:57:24 2013 +0200
Do not use this ptr in ctor
...offload to init() instead and wrap ctor in create(). That removes the need
for refcount fiddling and additional OContainerListener class. Which in turn
removes code using dynamic_cast on UNO interface classes, which my claim at
<http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130812/
086127.html> "ubsan: check type_info equality via strcmp" that "there should not
be uses of dynamic_cast involving [UNO] classes in the LibreOffice code base"
made me wonder about...
Change-Id: I5d72650f6bf081f971f7bd6bb65f4e58a342f791
diff --git a/dbaccess/Library_dba.mk b/dbaccess/Library_dba.mk
index 08d13df..27d2e99 100644
--- a/dbaccess/Library_dba.mk
+++ b/dbaccess/Library_dba.mk
@@ -115,7 +115,6 @@ $(eval $(call gb_Library_add_exception_objects,dba,\
dbaccess/source/core/dataaccess/myucp_resultset \
dbaccess/source/core/dataaccess/SharedConnection \
dbaccess/source/core/misc/apitools \
- dbaccess/source/core/misc/ContainerListener \
dbaccess/source/core/misc/ContainerMediator \
dbaccess/source/core/misc/DatabaseDataProvider \
dbaccess/source/core/misc/dsntypes \
diff --git a/dbaccess/source/core/api/querycontainer.cxx b/dbaccess/source/core/api/querycontainer.cxx
index 7e0e05e..fc5ccfc 100644
--- a/dbaccess/source/core/api/querycontainer.cxx
+++ b/dbaccess/source/core/api/querycontainer.cxx
@@ -22,7 +22,6 @@
#include "dbastrings.hrc"
#include "query.hxx"
#include "objectnameapproval.hxx"
-#include "ContainerListener.hxx"
#include "veto.hxx"
#include <com/sun/star/beans/XPropertySet.hpp>
@@ -75,32 +74,41 @@ OQueryContainer::OQueryContainer(
,m_xConnection(_rxConn)
{
DBG_CTOR(OQueryContainer, NULL);
+}
- increment(m_refCount);
+void OQueryContainer::init()
+{
+ Reference< XContainer > xContainer( m_xCommandDefinitions, UNO_QUERY_THROW );
+ xContainer->addContainerListener( this );
+
+ Reference< XContainerApproveBroadcaster > xContainerApprove( m_xCommandDefinitions, UNO_QUERY_THROW );
+ xContainerApprove->addContainerApproveListener( this );
+
+ // fill my structures
+ ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
+ Sequence< OUString > sDefinitionNames = m_xCommandDefinitions->getElementNames();
+ const OUString* pDefinitionName = sDefinitionNames.getConstArray();
+ const OUString* pEnd = pDefinitionName + sDefinitionNames.getLength();
+ for ( ; pDefinitionName != pEnd; ++pDefinitionName )
{
- m_pCommandsListener = new OContainerListener( *this, m_aMutex );
- m_pCommandsListener->acquire();
-
- Reference< XContainer > xContainer( m_xCommandDefinitions, UNO_QUERY_THROW );
- xContainer->addContainerListener( m_pCommandsListener );
-
- Reference< XContainerApproveBroadcaster > xContainerApprove( m_xCommandDefinitions, UNO_QUERY_THROW );
- xContainerApprove->addContainerApproveListener( m_pCommandsListener );
-
- // fill my structures
- ODefinitionContainer_Impl& rDefinitions( getDefinitions() );
- Sequence< OUString > sDefinitionNames = m_xCommandDefinitions->getElementNames();
- const OUString* pDefinitionName = sDefinitionNames.getConstArray();
- const OUString* pEnd = pDefinitionName + sDefinitionNames.getLength();
- for ( ; pDefinitionName != pEnd; ++pDefinitionName )
- {
- rDefinitions.insert( *pDefinitionName, TContentPtr() );
- m_aDocuments.push_back(m_aDocumentMap.insert(Documents::value_type(*pDefinitionName,Documents::mapped_type())).first);
- }
+ rDefinitions.insert( *pDefinitionName, TContentPtr() );
+ m_aDocuments.push_back(m_aDocumentMap.insert(Documents::value_type(*pDefinitionName,Documents::mapped_type())).first);
}
- decrement(m_refCount);
- setElementApproval( PContainerApprove( new ObjectNameApproval( _rxConn, ObjectNameApproval::TypeQuery ) ) );
+ setElementApproval( PContainerApprove( new ObjectNameApproval( m_xConnection, ObjectNameApproval::TypeQuery ) ) );
+}
+
+rtl::Reference<OQueryContainer> OQueryContainer::create(
+ const Reference< XNameContainer >& _rxCommandDefinitions
+ , const Reference< XConnection >& _rxConn
+ , const Reference< XComponentContext >& _rxORB,
+ ::dbtools::IWarningsContainer* _pWarnings)
+{
+ rtl::Reference<OQueryContainer> c(
+ new OQueryContainer(
+ _rxCommandDefinitions, _rxConn, _rxORB, _pWarnings));
+ c->init();
+ return c;
}
OQueryContainer::~OQueryContainer()
@@ -122,17 +130,10 @@ void OQueryContainer::disposing()
// already disposed
return;
- if ( m_pCommandsListener )
- {
- Reference< XContainer > xContainer( m_xCommandDefinitions, UNO_QUERY );
- xContainer->removeContainerListener( m_pCommandsListener );
- Reference< XContainerApproveBroadcaster > xContainerApprove( m_xCommandDefinitions, UNO_QUERY );
- xContainerApprove->removeContainerApproveListener( m_pCommandsListener );
-
- m_pCommandsListener->dispose();
- m_pCommandsListener->release();
- m_pCommandsListener = NULL;
- }
+ Reference< XContainer > xContainer( m_xCommandDefinitions, UNO_QUERY );
+ xContainer->removeContainerListener( this );
+ Reference< XContainerApproveBroadcaster > xContainerApprove( m_xCommandDefinitions, UNO_QUERY );
+ xContainerApprove->removeContainerApproveListener( this );
m_xCommandDefinitions = NULL;
m_xConnection = NULL;
@@ -345,7 +346,8 @@ Reference< XContent > OQueryContainer::implCreateWrapper(const Reference< XConte
Reference< XContent > xReturn;
if ( xContainer .is() )
{
- xReturn = new OQueryContainer( xContainer, m_xConnection, m_aContext, m_pWarnings );
+ xReturn = create( xContainer, m_xConnection, m_aContext, m_pWarnings ).
+ get();
}
else
{
diff --git a/dbaccess/source/core/dataaccess/connection.cxx b/dbaccess/source/core/dataaccess/connection.cxx
index 5ab0029..3675c83 100644
--- a/dbaccess/source/core/dataaccess/connection.cxx
+++ b/dbaccess/source/core/dataaccess/connection.cxx
@@ -319,7 +319,7 @@ OConnection::OConnection(ODatabaseSource& _rDB
try
{
- m_xQueries = new OQueryContainer(Reference< XNameContainer >(_rDB.getQueryDefinitions(), UNO_QUERY), this, _rxORB, &m_aWarnings);
+ m_xQueries = OQueryContainer::create(Reference< XNameContainer >(_rDB.getQueryDefinitions(), UNO_QUERY), this, _rxORB, &m_aWarnings).get();
sal_Bool bCase = sal_True;
Reference<XDatabaseMetaData> xMeta;
diff --git a/dbaccess/source/core/inc/ContainerListener.hxx b/dbaccess/source/core/inc/ContainerListener.hxx
deleted file mode 100644
index b910b20..0000000
--- a/dbaccess/source/core/inc/ContainerListener.hxx
+++ /dev/null
@@ -1,80 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-#ifndef DBA_CONTAINERLISTENER_HXX
-#define DBA_CONTAINERLISTENER_HXX
-
-#include <cppuhelper/implbase2.hxx>
-#include <com/sun/star/container/XContainerListener.hpp>
-#include <com/sun/star/container/XContainerApproveListener.hpp>
-
-#include <cppuhelper/weak.hxx>
-
-namespace dbaccess
-{
-
- //==========================================================================
- //= OContainerListener
- //==========================================================================
- typedef ::cppu::WeakImplHelper2 < ::com::sun::star::container::XContainerListener
- , ::com::sun::star::container::XContainerApproveListener
- > OContainerListener_BASE;
-
- /** is helper class to avoid a cycle in refcount
- */
- class OContainerListener : public OContainerListener_BASE
- {
- ::osl::Mutex& m_rMutex;
- OWeakObject& m_rDestination;
- bool m_bDisposed;
-
- public:
- OContainerListener( OWeakObject& _rDestination, ::osl::Mutex& _rMutex )
- :m_rMutex( _rMutex )
- ,m_rDestination( _rDestination )
- ,m_bDisposed( false )
- {
- }
-
- // XContainerApproveListener
- virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XVeto > SAL_CALL approveInsertElement( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
- virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XVeto > SAL_CALL approveReplaceElement( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
- virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XVeto > SAL_CALL approveRemoveElement( const ::com::sun::star::container::ContainerEvent& Event ) throw (::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
-
- // XContainerListener
- virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
- virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
-
- // XEventListener
- virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
-
- void SAL_CALL dispose()
- {
- m_bDisposed = true;
- }
-
- protected:
- virtual ~OContainerListener();
- };
-
-} // namespace dbaccess
-
-#endif // DBA_CONTAINERLISTENER_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dbaccess/source/core/inc/querycontainer.hxx b/dbaccess/source/core/inc/querycontainer.hxx
index ff89cb4..0dd74c0 100644
--- a/dbaccess/source/core/inc/querycontainer.hxx
+++ b/dbaccess/source/core/inc/querycontainer.hxx
@@ -62,11 +62,10 @@ namespace dbaccess
//==========================================================================
//= OQueryContainer
//==========================================================================
- class OContainerListener;
class OQueryContainer : public ODefinitionContainer
, public OQueryContainer_Base
{
- protected:
+ private:
::dbtools::IWarningsContainer* m_pWarnings;
::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
m_xCommandDefinitions;
@@ -76,8 +75,6 @@ namespace dbaccess
enum AGGREGATE_ACTION { NONE, INSERTING, FLUSHING };
AGGREGATE_ACTION m_eDoingCurrently;
- OContainerListener* m_pCommandsListener;
-
/** a class which automatically resets m_eDoingCurrently in it's destructor
*/
class OAutoActionReset; // just for the following friend declaration
@@ -97,7 +94,7 @@ namespace dbaccess
// helper
virtual void SAL_CALL disposing();
virtual ~OQueryContainer();
- public:
+
/** ctor of the container. The parent has to support the <type scope="com::sun::star::sdbc">XConnection</type>
interface.<BR>
@@ -116,6 +113,16 @@ namespace dbaccess
::dbtools::IWarningsContainer* _pWarnings
);
+ void init();
+
+ public:
+ static rtl::Reference<OQueryContainer> create(
+ const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& _rxCommandDefinitions,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConn,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxORB,
+ ::dbtools::IWarningsContainer* _pWarnings
+ );
+
DECLARE_XINTERFACE( )
DECLARE_XTYPEPROVIDER( )
DECLARE_SERVICE_INFO();
@@ -150,11 +157,10 @@ namespace dbaccess
// ::com::sun::star::container::XNameAccess
virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getElementNames( ) throw(::com::sun::star::uno::RuntimeException);
- protected:
+ private:
// OContentHelper overridables
virtual OUString determineContentType() const;
- private:
// helper
/** create a query object wrapping a CommandDefinition given by name. To retrieve the object, the CommandDescription
container will be asked for the given name.<BR>
diff --git a/dbaccess/source/core/misc/ContainerListener.cxx b/dbaccess/source/core/misc/ContainerListener.cxx
deleted file mode 100644
index 66c5126..0000000
--- a/dbaccess/source/core/misc/ContainerListener.cxx
+++ /dev/null
@@ -1,119 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-
-#include "ContainerListener.hxx"
-
-//........................................................................
-namespace dbaccess
-{
-//........................................................................
-
- using ::com::sun::star::container::ContainerEvent;
- using ::com::sun::star::lang::WrappedTargetException;
- using ::com::sun::star::uno::RuntimeException;
- using ::com::sun::star::container::XContainerApproveListener;
- using ::com::sun::star::container::XContainerListener;
- using ::com::sun::star::lang::EventObject;
- using ::com::sun::star::util::XVeto;
- using ::com::sun::star::uno::Reference;
-
- //====================================================================
- //= OContainerListener
- //====================================================================
- //--------------------------------------------------------------------
- OContainerListener::~OContainerListener()
- {
- }
-
- //--------------------------------------------------------------------
- Reference< XVeto > SAL_CALL OContainerListener::approveInsertElement( const ContainerEvent& _Event ) throw (WrappedTargetException, RuntimeException)
- {
- ::osl::MutexGuard aGuard( m_rMutex );
- if ( m_bDisposed )
- return NULL;
-
- return dynamic_cast< XContainerApproveListener& >( m_rDestination ).approveInsertElement( _Event );
- }
-
- //--------------------------------------------------------------------
- Reference< XVeto > SAL_CALL OContainerListener::approveReplaceElement( const ContainerEvent& _Event ) throw (WrappedTargetException, RuntimeException)
- {
- ::osl::MutexGuard aGuard( m_rMutex );
- if ( m_bDisposed )
- return NULL;
-
- return dynamic_cast< XContainerApproveListener& >( m_rDestination ).approveReplaceElement( _Event );
- }
-
- //--------------------------------------------------------------------
- Reference< XVeto > SAL_CALL OContainerListener::approveRemoveElement( const ContainerEvent& _Event ) throw (WrappedTargetException, RuntimeException)
- {
- ::osl::MutexGuard aGuard( m_rMutex );
- if ( m_bDisposed )
- return NULL;
-
- return dynamic_cast< XContainerApproveListener& >( m_rDestination ).approveRemoveElement( _Event );
- }
-
- //--------------------------------------------------------------------
- void SAL_CALL OContainerListener::elementInserted( const ContainerEvent& _Event ) throw(RuntimeException)
- {
- ::osl::MutexGuard aGuard( m_rMutex );
- if ( m_bDisposed )
- return;
-
- dynamic_cast< XContainerListener& >( m_rDestination ).elementInserted( _Event );
- }
-
- //--------------------------------------------------------------------
- void SAL_CALL OContainerListener::elementRemoved( const ContainerEvent& _Event ) throw(RuntimeException)
- {
- ::osl::MutexGuard aGuard( m_rMutex );
- if ( m_bDisposed )
- return;
-
- dynamic_cast< XContainerListener& >( m_rDestination ).elementRemoved( _Event );
- }
-
- //--------------------------------------------------------------------
- void SAL_CALL OContainerListener::elementReplaced( const ContainerEvent& _Event ) throw(RuntimeException)
- {
- ::osl::MutexGuard aGuard( m_rMutex );
- if ( m_bDisposed )
- return;
-
- dynamic_cast< XContainerListener& >( m_rDestination ).elementReplaced( _Event );
- }
-
- //--------------------------------------------------------------------
- void SAL_CALL OContainerListener::disposing( const EventObject& _Source ) throw(RuntimeException)
- {
- ::osl::MutexGuard aGuard( m_rMutex );
- if ( m_bDisposed )
- return;
-
- dynamic_cast< XContainerListener& >( m_rDestination ).disposing( _Source );
- }
-
-//........................................................................
-} // namespace dbaccess
-//........................................................................
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list