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 __INSTANCELOCKER_HXX_
25 #define __INSTANCELOCKER_HXX_
26 
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/lang/XComponent.hpp>
29 #include <com/sun/star/util/XCloseListener.hpp>
30 #include <com/sun/star/frame/XTerminateListener.hpp>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/embed/XActionsApproval.hpp>
34 #include <com/sun/star/embed/Actions.hpp>
35 #include <cppuhelper/weakref.hxx>
36 #include <osl/mutex.hxx>
37 #include <cppuhelper/implbase3.hxx>
38 #include <cppuhelper/implbase2.hxx>
39 #include <cppuhelper/interfacecontainer.h>
40 
41 
42 class OLockListener;
43 
44 // the service is implemented as a wrapper to be able to die by refcount
45 // the disposing mechanics is required for java related scenarios
46 class OInstanceLocker : public ::cppu::WeakImplHelper3< ::com::sun::star::lang::XComponent,
47 														::com::sun::star::lang::XInitialization,
48 														::com::sun::star::lang::XServiceInfo >
49 {
50 	::osl::Mutex m_aMutex;
51 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
52 
53 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xLockListener;
54 	OLockListener* m_pLockListener;
55 
56 	::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners
57 
58 	sal_Bool m_bDisposed;
59 	sal_Bool m_bInitialized;
60 
61 public:
62 	OInstanceLocker( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext );
63 	~OInstanceLocker();
64 
65 	static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
66 			getSupportedServiceNames_static();
67 
68 	static ::rtl::OUString SAL_CALL getImplementationName_static();
69 
70 	static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
71 		Create(
72 			const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );
73 
74 // XComponent
75     virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);
76     virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
77     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
78 
79 // XInitialization
80     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);
81 
82 // XServiceInfo
83     virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
84     virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
85     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
86 
87 };
88 
89 
90 class OLockListener : public ::cppu::WeakImplHelper2< ::com::sun::star::util::XCloseListener,
91 													::com::sun::star::frame::XTerminateListener >
92 {
93 	::osl::Mutex m_aMutex;
94 	::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xInstance;
95 	::com::sun::star::uno::Reference< ::com::sun::star::embed::XActionsApproval > m_xApproval;
96 
97 	::com::sun::star::uno::WeakReference< ::com::sun::star::lang::XComponent > m_xWrapper;
98 
99 	sal_Bool m_bDisposed;
100 	sal_Bool m_bInitialized;
101 
102 	sal_Int32 m_nMode;
103 
104 public:
105 	OLockListener(	const ::com::sun::star::uno::WeakReference< ::com::sun::star::lang::XComponent >& xWrapper,
106 					const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xInstance,
107 					sal_Int32 nMode,
108 					const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XActionsApproval > xApproval );
109 
110 	~OLockListener();
111 
112 	sal_Bool Init();
113 	void Dispose();
114 
115 // XEventListener
116     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
117 
118 // XCloseListener
119     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);
120     virtual void SAL_CALL notifyClosing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
121 
122 // XTerminateListener
123     virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException);
124     virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException);
125 
126 };
127 
128 #endif
129 
130