1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: instancelocker.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __INSTANCELOCKER_HXX_
32 #define __INSTANCELOCKER_HXX_
34 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/util/XCloseListener.hpp>
37 #include <com/sun/star/frame/XTerminateListener.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/embed/XActionsApproval.hpp>
41 #include <com/sun/star/embed/Actions.hpp>
42 #include <cppuhelper/weakref.hxx>
43 #include <osl/mutex.hxx>
44 #include <cppuhelper/implbase3.hxx>
45 #include <cppuhelper/implbase2.hxx>
46 #include <cppuhelper/interfacecontainer.h>
51 // the service is implemented as a wrapper to be able to die by refcount
52 // the disposing mechanics is required for java related scenarios
53 class OInstanceLocker
: public ::cppu::WeakImplHelper3
< ::com::sun::star::lang::XComponent
,
54 ::com::sun::star::lang::XInitialization
,
55 ::com::sun::star::lang::XServiceInfo
>
57 ::osl::Mutex m_aMutex
;
58 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
60 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xLockListener
;
61 OLockListener
* m_pLockListener
;
63 ::cppu::OInterfaceContainerHelper
* m_pListenersContainer
; // list of listeners
66 sal_Bool m_bInitialized
;
69 OInstanceLocker( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& xContext
);
72 static ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
73 getSupportedServiceNames_static();
75 static ::rtl::OUString SAL_CALL
getImplementationName_static();
77 static ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
79 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
);
82 virtual void SAL_CALL
dispose() throw (::com::sun::star::uno::RuntimeException
);
83 virtual void SAL_CALL
addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
84 virtual void SAL_CALL
removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& aListener
) throw (::com::sun::star::uno::RuntimeException
);
87 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
);
90 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw (::com::sun::star::uno::RuntimeException
);
91 virtual ::sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw (::com::sun::star::uno::RuntimeException
);
92 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException
);
97 class OLockListener
: public ::cppu::WeakImplHelper2
< ::com::sun::star::util::XCloseListener
,
98 ::com::sun::star::frame::XTerminateListener
>
100 ::osl::Mutex m_aMutex
;
101 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xInstance
;
102 ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XActionsApproval
> m_xApproval
;
104 ::com::sun::star::uno::WeakReference
< ::com::sun::star::lang::XComponent
> m_xWrapper
;
106 sal_Bool m_bDisposed
;
107 sal_Bool m_bInitialized
;
112 OLockListener( const ::com::sun::star::uno::WeakReference
< ::com::sun::star::lang::XComponent
>& xWrapper
,
113 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xInstance
,
115 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XActionsApproval
> xApproval
);
123 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
);
126 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
);
127 virtual void SAL_CALL
notifyClosing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
);
129 // XTerminateListener
130 virtual void SAL_CALL
queryTermination( const ::com::sun::star::lang::EventObject
& Event
) throw (::com::sun::star::frame::TerminationVetoException
, ::com::sun::star::uno::RuntimeException
);
131 virtual void SAL_CALL
notifyTermination( const ::com::sun::star::lang::EventObject
& Event
) throw (::com::sun::star::uno::RuntimeException
);