1*9877b273SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9877b273SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9877b273SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9877b273SAndrew Rist * distributed with this work for additional information 6*9877b273SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9877b273SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9877b273SAndrew Rist * "License"); you may not use this file except in compliance 9*9877b273SAndrew Rist * with the License. You may obtain a copy of the License at 10*9877b273SAndrew Rist * 11*9877b273SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*9877b273SAndrew Rist * 13*9877b273SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9877b273SAndrew Rist * software distributed under the License is distributed on an 15*9877b273SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9877b273SAndrew Rist * KIND, either express or implied. See the License for the 17*9877b273SAndrew Rist * specific language governing permissions and limitations 18*9877b273SAndrew Rist * under the License. 19*9877b273SAndrew Rist * 20*9877b273SAndrew Rist *************************************************************/ 21*9877b273SAndrew Rist 22*9877b273SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef __INSTANCELOCKER_HXX_ 25cdf0e10cSrcweir #define __INSTANCELOCKER_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 28cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 29cdf0e10cSrcweir #include <com/sun/star/util/XCloseListener.hpp> 30cdf0e10cSrcweir #include <com/sun/star/frame/XTerminateListener.hpp> 31cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 32cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 33cdf0e10cSrcweir #include <com/sun/star/embed/XActionsApproval.hpp> 34cdf0e10cSrcweir #include <com/sun/star/embed/Actions.hpp> 35cdf0e10cSrcweir #include <cppuhelper/weakref.hxx> 36cdf0e10cSrcweir #include <osl/mutex.hxx> 37cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 38cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 39cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.h> 40cdf0e10cSrcweir 41cdf0e10cSrcweir 42cdf0e10cSrcweir class OLockListener; 43cdf0e10cSrcweir 44cdf0e10cSrcweir // the service is implemented as a wrapper to be able to die by refcount 45cdf0e10cSrcweir // the disposing mechanics is required for java related scenarios 46cdf0e10cSrcweir class OInstanceLocker : public ::cppu::WeakImplHelper3< ::com::sun::star::lang::XComponent, 47cdf0e10cSrcweir ::com::sun::star::lang::XInitialization, 48cdf0e10cSrcweir ::com::sun::star::lang::XServiceInfo > 49cdf0e10cSrcweir { 50cdf0e10cSrcweir ::osl::Mutex m_aMutex; 51cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; 52cdf0e10cSrcweir 53cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xLockListener; 54cdf0e10cSrcweir OLockListener* m_pLockListener; 55cdf0e10cSrcweir 56cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners 57cdf0e10cSrcweir 58cdf0e10cSrcweir sal_Bool m_bDisposed; 59cdf0e10cSrcweir sal_Bool m_bInitialized; 60cdf0e10cSrcweir 61cdf0e10cSrcweir public: 62cdf0e10cSrcweir OInstanceLocker( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext ); 63cdf0e10cSrcweir ~OInstanceLocker(); 64cdf0e10cSrcweir 65cdf0e10cSrcweir static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 66cdf0e10cSrcweir getSupportedServiceNames_static(); 67cdf0e10cSrcweir 68cdf0e10cSrcweir static ::rtl::OUString SAL_CALL getImplementationName_static(); 69cdf0e10cSrcweir 70cdf0e10cSrcweir static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL 71cdf0e10cSrcweir Create( 72cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir // XComponent 75cdf0e10cSrcweir virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); 76cdf0e10cSrcweir virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 77cdf0e10cSrcweir virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 78cdf0e10cSrcweir 79cdf0e10cSrcweir // XInitialization 80cdf0e10cSrcweir virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 81cdf0e10cSrcweir 82cdf0e10cSrcweir // XServiceInfo 83cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException); 84cdf0e10cSrcweir virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); 85cdf0e10cSrcweir virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); 86cdf0e10cSrcweir 87cdf0e10cSrcweir }; 88cdf0e10cSrcweir 89cdf0e10cSrcweir 90cdf0e10cSrcweir class OLockListener : public ::cppu::WeakImplHelper2< ::com::sun::star::util::XCloseListener, 91cdf0e10cSrcweir ::com::sun::star::frame::XTerminateListener > 92cdf0e10cSrcweir { 93cdf0e10cSrcweir ::osl::Mutex m_aMutex; 94cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xInstance; 95cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::embed::XActionsApproval > m_xApproval; 96cdf0e10cSrcweir 97cdf0e10cSrcweir ::com::sun::star::uno::WeakReference< ::com::sun::star::lang::XComponent > m_xWrapper; 98cdf0e10cSrcweir 99cdf0e10cSrcweir sal_Bool m_bDisposed; 100cdf0e10cSrcweir sal_Bool m_bInitialized; 101cdf0e10cSrcweir 102cdf0e10cSrcweir sal_Int32 m_nMode; 103cdf0e10cSrcweir 104cdf0e10cSrcweir public: 105cdf0e10cSrcweir OLockListener( const ::com::sun::star::uno::WeakReference< ::com::sun::star::lang::XComponent >& xWrapper, 106cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xInstance, 107cdf0e10cSrcweir sal_Int32 nMode, 108cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XActionsApproval > xApproval ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir ~OLockListener(); 111cdf0e10cSrcweir 112cdf0e10cSrcweir sal_Bool Init(); 113cdf0e10cSrcweir void Dispose(); 114cdf0e10cSrcweir 115cdf0e10cSrcweir // XEventListener 116cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 117cdf0e10cSrcweir 118cdf0e10cSrcweir // XCloseListener 119cdf0e10cSrcweir virtual void SAL_CALL queryClosing( const ::com::sun::star::lang::EventObject& Source, sal_Bool GetsOwnership ) throw (::com::sun::star::util::CloseVetoException, ::com::sun::star::uno::RuntimeException); 120cdf0e10cSrcweir virtual void SAL_CALL notifyClosing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 121cdf0e10cSrcweir 122cdf0e10cSrcweir // XTerminateListener 123cdf0e10cSrcweir virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException); 124cdf0e10cSrcweir virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException); 125cdf0e10cSrcweir 126cdf0e10cSrcweir }; 127cdf0e10cSrcweir 128cdf0e10cSrcweir #endif 129cdf0e10cSrcweir 130