bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / misc / instancelocker.hxx
blob058190827f81d4881034208283f62f012e47ad00
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_COMPHELPER_SOURCE_MISC_INSTANCELOCKER_HXX
21 #define INCLUDED_COMPHELPER_SOURCE_MISC_INSTANCELOCKER_HXX
23 #include <com/sun/star/uno/XComponentContext.hpp>
24 #include <com/sun/star/lang/XComponent.hpp>
25 #include <com/sun/star/util/XCloseListener.hpp>
26 #include <com/sun/star/frame/XTerminateListener.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/embed/XActionsApproval.hpp>
30 #include <com/sun/star/embed/Actions.hpp>
31 #include <cppuhelper/weakref.hxx>
32 #include <osl/mutex.hxx>
33 #include <cppuhelper/implbase3.hxx>
34 #include <cppuhelper/implbase2.hxx>
35 #include <cppuhelper/interfacecontainer.h>
38 class OLockListener;
40 // the service is implemented as a wrapper to be able to die by refcount
41 // the disposing mechanics is required for java related scenarios
42 class OInstanceLocker : public ::cppu::WeakImplHelper3< ::com::sun::star::lang::XComponent,
43 ::com::sun::star::lang::XInitialization,
44 ::com::sun::star::lang::XServiceInfo >
46 ::osl::Mutex m_aMutex;
47 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
49 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xLockListener;
50 OLockListener* m_pLockListener;
52 ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners
54 bool m_bDisposed;
55 bool m_bInitialized;
57 public:
58 OInstanceLocker( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext );
59 virtual ~OInstanceLocker();
61 static ::com::sun::star::uno::Sequence< OUString > SAL_CALL
62 getSupportedServiceNames_static();
64 static OUString SAL_CALL getImplementationName_static();
66 static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL
67 Create(
68 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );
70 // XComponent
71 virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
72 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
73 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
75 // XInitialization
76 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, std::exception) SAL_OVERRIDE;
78 // XServiceInfo
79 virtual OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
80 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
81 virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
86 class OLockListener : public ::cppu::WeakImplHelper2< ::com::sun::star::util::XCloseListener,
87 ::com::sun::star::frame::XTerminateListener >
89 ::osl::Mutex m_aMutex;
90 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xInstance;
91 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XActionsApproval > m_xApproval;
93 ::com::sun::star::uno::WeakReference< ::com::sun::star::lang::XComponent > m_xWrapper;
95 bool m_bDisposed;
96 bool m_bInitialized;
98 sal_Int32 m_nMode;
100 public:
101 OLockListener( const ::com::sun::star::uno::WeakReference< ::com::sun::star::lang::XComponent >& xWrapper,
102 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xInstance,
103 sal_Int32 nMode,
104 const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XActionsApproval >& rApproval );
106 virtual ~OLockListener();
108 bool Init();
109 void Dispose();
111 // XEventListener
112 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
114 // XCloseListener
115 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, std::exception) SAL_OVERRIDE;
116 virtual void SAL_CALL notifyClosing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
118 // XTerminateListener
119 virtual void SAL_CALL queryTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
120 virtual void SAL_CALL notifyTermination( const ::com::sun::star::lang::EventObject& Event ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
124 #endif
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */