LibreOffice Module comphelper (master) 1
instancelocker.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
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>
30#include <rtl/ref.hxx>
31#include <mutex>
32
33namespace com::sun::star::embed { class XActionsApproval; }
34
35
36class OLockListener;
37
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
40class OInstanceLocker : public ::cppu::WeakImplHelper< css::lang::XComponent,
41 css::lang::XInitialization,
42 css::lang::XServiceInfo >
43{
45
47
49
52
53public:
54 explicit OInstanceLocker();
55 virtual ~OInstanceLocker() override;
56
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;
61
62// XInitialization
63 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
64
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;
69
70};
71
72
73class OLockListener : public ::cppu::WeakImplHelper< css::util::XCloseListener,
74 css::frame::XTerminateListener >
75{
77 css::uno::Reference< css::uno::XInterface > m_xInstance;
78 css::uno::Reference< css::embed::XActionsApproval > m_xApproval;
79
80 css::uno::WeakReference< css::lang::XComponent > m_xWrapper;
81
84
85 sal_Int32 m_nMode;
86
87public:
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 );
92
93 virtual ~OLockListener() override;
94
95 void Init();
96 void Dispose();
97
98// XEventListener
99 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
100
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;
104
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;
108
109};
110
111/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_aListenersContainer
virtual ~OInstanceLocker() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
std::mutex m_aMutex
rtl::Reference< OLockListener > m_xLockListener
virtual OUString SAL_CALL getImplementationName() override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual void SAL_CALL dispose() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
css::uno::WeakReference< css::lang::XComponent > m_xWrapper
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
std::mutex m_aMutex
css::uno::Reference< css::uno::XInterface > m_xInstance
sal_Int32 m_nMode
virtual void SAL_CALL queryClosing(const css::lang::EventObject &Source, sal_Bool GetsOwnership) override
virtual void SAL_CALL notifyClosing(const css::lang::EventObject &Source) override
css::uno::Reference< css::embed::XActionsApproval > m_xApproval
virtual void SAL_CALL queryTermination(const css::lang::EventObject &Event) override
virtual ~OLockListener() override
virtual void SAL_CALL notifyTermination(const css::lang::EventObject &Event) override
OLockListener(css::uno::WeakReference< css::lang::XComponent > xWrapper, css::uno::Reference< css::uno::XInterface > xInstance, sal_Int32 nMode, css::uno::Reference< css::embed::XActionsApproval > xApproval)
std::mutex mutex
Definition: random.cxx:41
unsigned char sal_Bool