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