1*6df1ea1fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6df1ea1fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6df1ea1fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6df1ea1fSAndrew Rist * distributed with this work for additional information 6*6df1ea1fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6df1ea1fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6df1ea1fSAndrew Rist * "License"); you may not use this file except in compliance 9*6df1ea1fSAndrew Rist * with the License. You may obtain a copy of the License at 10*6df1ea1fSAndrew Rist * 11*6df1ea1fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*6df1ea1fSAndrew Rist * 13*6df1ea1fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6df1ea1fSAndrew Rist * software distributed under the License is distributed on an 15*6df1ea1fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6df1ea1fSAndrew Rist * KIND, either express or implied. See the License for the 17*6df1ea1fSAndrew Rist * specific language governing permissions and limitations 18*6df1ea1fSAndrew Rist * under the License. 19*6df1ea1fSAndrew Rist * 20*6df1ea1fSAndrew Rist *************************************************************/ 21*6df1ea1fSAndrew Rist 22*6df1ea1fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _DYNAMIC_RESULTSET_WRAPPER_HXX 25cdf0e10cSrcweir #define _DYNAMIC_RESULTSET_WRAPPER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <osl/mutex.hxx> 28cdf0e10cSrcweir #include <osl/conditn.hxx> 29cdf0e10cSrcweir #include <ucbhelper/macros.hxx> 30cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 31cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp> 32cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 33cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 34cdf0e10cSrcweir #include <com/sun/star/ucb/XDynamicResultSet.hpp> 35cdf0e10cSrcweir #include <com/sun/star/ucb/XSourceInitialization.hpp> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #ifndef __com_sun_star_lang_DisposedException_idl__ 38cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 39cdf0e10cSrcweir #endif 40cdf0e10cSrcweir #include <com/sun/star/ucb/XDynamicResultSetListener.hpp> 41cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 42cdf0e10cSrcweir 43cdf0e10cSrcweir //#define CACHED_CRS_STUB_SERVICE_NAME "com.sun.star.ucb.CachedContentResultSetStub" 44cdf0e10cSrcweir //#define CACHED_CRS_STUB_FACTORY_NAME "com.sun.star.ucb.CachedContentResultSetStubFactory" 45cdf0e10cSrcweir 46cdf0e10cSrcweir //========================================================================= 47cdf0e10cSrcweir 48cdf0e10cSrcweir class DynamicResultSetWrapperListener; 49cdf0e10cSrcweir class DynamicResultSetWrapper 50cdf0e10cSrcweir : public cppu::OWeakObject 51cdf0e10cSrcweir , public com::sun::star::ucb::XDynamicResultSet 52cdf0e10cSrcweir , public com::sun::star::ucb::XSourceInitialization 53cdf0e10cSrcweir { 54cdf0e10cSrcweir private: 55cdf0e10cSrcweir //management of listeners 56cdf0e10cSrcweir sal_Bool m_bDisposed; ///Dispose call ready. 57cdf0e10cSrcweir sal_Bool m_bInDispose;///In dispose call 58cdf0e10cSrcweir osl::Mutex m_aContainerMutex; 59cdf0e10cSrcweir cppu::OInterfaceContainerHelper* 60cdf0e10cSrcweir m_pDisposeEventListeners; 61cdf0e10cSrcweir protected: 62cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener > 63cdf0e10cSrcweir m_xMyListenerImpl; 64cdf0e10cSrcweir DynamicResultSetWrapperListener* 65cdf0e10cSrcweir m_pMyListenerImpl; 66cdf0e10cSrcweir 67cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > 68cdf0e10cSrcweir m_xSMgr; 69cdf0e10cSrcweir 70cdf0e10cSrcweir osl::Mutex m_aMutex; 71cdf0e10cSrcweir sal_Bool m_bStatic; 72cdf0e10cSrcweir sal_Bool m_bGotWelcome; 73cdf0e10cSrcweir 74cdf0e10cSrcweir //different Interfaces from Origin: 75cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSet > 76cdf0e10cSrcweir m_xSource; 77cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 78cdf0e10cSrcweir m_xSourceResultOne; 79cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 80cdf0e10cSrcweir m_xSourceResultTwo; 81cdf0e10cSrcweir //com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 82cdf0e10cSrcweir // m_xSourceResultCurrent; 83cdf0e10cSrcweir //sal_Bool m_bUseOne; 84cdf0e10cSrcweir // 85cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 86cdf0e10cSrcweir m_xMyResultOne; 87cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > 88cdf0e10cSrcweir m_xMyResultTwo; 89cdf0e10cSrcweir // 90cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XDynamicResultSetListener > 91cdf0e10cSrcweir m_xListener; 92cdf0e10cSrcweir 93cdf0e10cSrcweir osl::Condition m_aSourceSet; 94cdf0e10cSrcweir osl::Condition m_aListenerSet; 95cdf0e10cSrcweir 96cdf0e10cSrcweir protected: 97cdf0e10cSrcweir void SAL_CALL impl_init(); 98cdf0e10cSrcweir void SAL_CALL impl_deinit(); 99cdf0e10cSrcweir void SAL_CALL 100cdf0e10cSrcweir impl_EnsureNotDisposed() 101cdf0e10cSrcweir throw( com::sun::star::lang::DisposedException, 102cdf0e10cSrcweir com::sun::star::uno::RuntimeException ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir virtual void SAL_CALL 105cdf0e10cSrcweir impl_InitResultSetOne( const com::sun::star::uno::Reference< 106cdf0e10cSrcweir com::sun::star::sdbc::XResultSet >& xResultSet ); 107cdf0e10cSrcweir virtual void SAL_CALL 108cdf0e10cSrcweir impl_InitResultSetTwo( const com::sun::star::uno::Reference< 109cdf0e10cSrcweir com::sun::star::sdbc::XResultSet >& xResultSet ); 110cdf0e10cSrcweir 111cdf0e10cSrcweir public: 112cdf0e10cSrcweir 113cdf0e10cSrcweir DynamicResultSetWrapper( 114cdf0e10cSrcweir com::sun::star::uno::Reference< 115cdf0e10cSrcweir com::sun::star::ucb::XDynamicResultSet > xOrigin 116cdf0e10cSrcweir , const com::sun::star::uno::Reference< 117cdf0e10cSrcweir com::sun::star::lang::XMultiServiceFactory > & xSMgr ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir virtual ~DynamicResultSetWrapper(); 120cdf0e10cSrcweir 121cdf0e10cSrcweir //----------------------------------------------------------------- 122cdf0e10cSrcweir // XInterface 123cdf0e10cSrcweir virtual com::sun::star::uno::Any SAL_CALL 124cdf0e10cSrcweir queryInterface( const com::sun::star::uno::Type & rType ) 125cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir //----------------------------------------------------------------- 128cdf0e10cSrcweir // XDynamicResultSet 129cdf0e10cSrcweir virtual com::sun::star::uno::Reference< com::sun::star::sdbc::XResultSet > SAL_CALL 130cdf0e10cSrcweir getStaticResultSet() 131cdf0e10cSrcweir throw( com::sun::star::ucb::ListenerAlreadySetException 132cdf0e10cSrcweir , com::sun::star::uno::RuntimeException ); 133cdf0e10cSrcweir 134cdf0e10cSrcweir virtual void SAL_CALL 135cdf0e10cSrcweir setListener( const com::sun::star::uno::Reference< 136cdf0e10cSrcweir com::sun::star::ucb::XDynamicResultSetListener > & Listener ) 137cdf0e10cSrcweir throw( com::sun::star::ucb::ListenerAlreadySetException 138cdf0e10cSrcweir , com::sun::star::uno::RuntimeException ); 139cdf0e10cSrcweir 140cdf0e10cSrcweir virtual void SAL_CALL 141cdf0e10cSrcweir connectToCache( const com::sun::star::uno::Reference< 142cdf0e10cSrcweir com::sun::star::ucb::XDynamicResultSet > & xCache ) 143cdf0e10cSrcweir throw( com::sun::star::ucb::ListenerAlreadySetException 144cdf0e10cSrcweir , com::sun::star::ucb::AlreadyInitializedException 145cdf0e10cSrcweir , com::sun::star::ucb::ServiceNotFoundException 146cdf0e10cSrcweir , com::sun::star::uno::RuntimeException ); 147cdf0e10cSrcweir 148cdf0e10cSrcweir virtual sal_Int16 SAL_CALL 149cdf0e10cSrcweir getCapabilities() throw( com::sun::star::uno::RuntimeException ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir //----------------------------------------------------------------- 152cdf0e10cSrcweir // XComponent ( base of XDynamicResultSet ) 153cdf0e10cSrcweir virtual void SAL_CALL 154cdf0e10cSrcweir dispose() throw( com::sun::star::uno::RuntimeException ); 155cdf0e10cSrcweir 156cdf0e10cSrcweir virtual void SAL_CALL 157cdf0e10cSrcweir addEventListener( const com::sun::star::uno::Reference< 158cdf0e10cSrcweir com::sun::star::lang::XEventListener >& Listener ) 159cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 160cdf0e10cSrcweir 161cdf0e10cSrcweir virtual void SAL_CALL 162cdf0e10cSrcweir removeEventListener( const com::sun::star::uno::Reference< 163cdf0e10cSrcweir com::sun::star::lang::XEventListener >& Listener ) 164cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 165cdf0e10cSrcweir 166cdf0e10cSrcweir //----------------------------------------------------------------- 167cdf0e10cSrcweir // XSourceInitialization 168cdf0e10cSrcweir 169cdf0e10cSrcweir virtual void SAL_CALL 170cdf0e10cSrcweir setSource( const com::sun::star::uno::Reference< 171cdf0e10cSrcweir com::sun::star::uno::XInterface > & Source ) 172cdf0e10cSrcweir throw( com::sun::star::ucb::AlreadyInitializedException 173cdf0e10cSrcweir , com::sun::star::uno::RuntimeException ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir //----------------------------------------------------------------- 176cdf0e10cSrcweir // own methods: 177cdf0e10cSrcweir virtual void SAL_CALL 178cdf0e10cSrcweir impl_disposing( const com::sun::star::lang::EventObject& Source ) 179cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir virtual void SAL_CALL 182cdf0e10cSrcweir impl_notify( const ::com::sun::star::ucb::ListEvent& Changes ) 183cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 184cdf0e10cSrcweir }; 185cdf0e10cSrcweir 186cdf0e10cSrcweir //========================================================================= 187cdf0e10cSrcweir 188cdf0e10cSrcweir class DynamicResultSetWrapperListener 189cdf0e10cSrcweir : public cppu::OWeakObject 190cdf0e10cSrcweir , public com::sun::star::ucb::XDynamicResultSetListener 191cdf0e10cSrcweir { 192cdf0e10cSrcweir protected: 193cdf0e10cSrcweir DynamicResultSetWrapper* m_pOwner; 194cdf0e10cSrcweir osl::Mutex m_aMutex; 195cdf0e10cSrcweir 196cdf0e10cSrcweir public: 197cdf0e10cSrcweir DynamicResultSetWrapperListener( DynamicResultSetWrapper* pOwner ); 198cdf0e10cSrcweir 199cdf0e10cSrcweir virtual ~DynamicResultSetWrapperListener(); 200cdf0e10cSrcweir 201cdf0e10cSrcweir //----------------------------------------------------------------- 202cdf0e10cSrcweir // XInterface 203cdf0e10cSrcweir //----------------------------------------------------------------- 204cdf0e10cSrcweir XINTERFACE_DECL() 205cdf0e10cSrcweir 206cdf0e10cSrcweir //----------------------------------------------------------------- 207cdf0e10cSrcweir // XEventListener ( base of XDynamicResultSetListener ) 208cdf0e10cSrcweir //----------------------------------------------------------------- 209cdf0e10cSrcweir virtual void SAL_CALL 210cdf0e10cSrcweir disposing( const com::sun::star::lang::EventObject& Source ) 211cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 212cdf0e10cSrcweir //----------------------------------------------------------------- 213cdf0e10cSrcweir // XDynamicResultSetListener 214cdf0e10cSrcweir virtual void SAL_CALL 215cdf0e10cSrcweir notify( const ::com::sun::star::ucb::ListEvent& Changes ) 216cdf0e10cSrcweir throw( com::sun::star::uno::RuntimeException ); 217cdf0e10cSrcweir 218cdf0e10cSrcweir //----------------------------------------------------------------- 219cdf0e10cSrcweir // own methods: 220cdf0e10cSrcweir void SAL_CALL impl_OwnerDies(); 221cdf0e10cSrcweir }; 222cdf0e10cSrcweir 223cdf0e10cSrcweir 224cdf0e10cSrcweir #endif 225cdf0e10cSrcweir 226