android: Update app-specific/MIME type icons
[LibreOffice.git] / comphelper / source / misc / instancelocker.hxx
blob6a050c7f437c68588ae0c035e2196be1fa62b998
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 #pragma once
22 #include <com/sun/star/lang/XComponent.hpp>
23 #include <com/sun/star/util/XCloseListener.hpp>
24 #include <com/sun/star/frame/XTerminateListener.hpp>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <comphelper/interfacecontainer4.hxx>
28 #include <cppuhelper/weakref.hxx>
29 #include <cppuhelper/implbase.hxx>
30 #include <rtl/ref.hxx>
31 #include <mutex>
33 namespace com::sun::star::embed { class XActionsApproval; }
36 class OLockListener;
38 // the service is implemented as a wrapper to be able to die by refcount
39 // the disposing mechanics is required for java related scenarios
40 class OInstanceLocker : public ::cppu::WeakImplHelper< css::lang::XComponent,
41 css::lang::XInitialization,
42 css::lang::XServiceInfo >
44 std::mutex m_aMutex;
46 rtl::Reference< OLockListener > m_xLockListener;
48 comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aListenersContainer; // list of listeners
50 bool m_bDisposed;
51 bool m_bInitialized;
53 public:
54 explicit OInstanceLocker();
55 virtual ~OInstanceLocker() override;
57 // XComponent
58 virtual void SAL_CALL dispose() override;
59 virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
60 virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
62 // XInitialization
63 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
65 // XServiceInfo
66 virtual OUString SAL_CALL getImplementationName( ) override;
67 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
68 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
73 class OLockListener : public ::cppu::WeakImplHelper< css::util::XCloseListener,
74 css::frame::XTerminateListener >
76 std::mutex m_aMutex;
77 css::uno::Reference< css::uno::XInterface > m_xInstance;
78 css::uno::Reference< css::embed::XActionsApproval > m_xApproval;
80 css::uno::WeakReference< css::lang::XComponent > m_xWrapper;
82 bool m_bDisposed;
83 bool m_bInitialized;
85 sal_Int32 m_nMode;
87 public:
88 OLockListener( css::uno::WeakReference< css::lang::XComponent > xWrapper,
89 css::uno::Reference< css::uno::XInterface > xInstance,
90 sal_Int32 nMode,
91 css::uno::Reference< css::embed::XActionsApproval > xApproval );
93 virtual ~OLockListener() override;
95 void Init();
96 void Dispose();
98 // XEventListener
99 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
101 // XCloseListener
102 virtual void SAL_CALL queryClosing( const css::lang::EventObject& Source, sal_Bool GetsOwnership ) override;
103 virtual void SAL_CALL notifyClosing( const css::lang::EventObject& Source ) override;
105 // XTerminateListener
106 virtual void SAL_CALL queryTermination( const css::lang::EventObject& Event ) override;
107 virtual void SAL_CALL notifyTermination( const css::lang::EventObject& Event ) override;
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */