android: Update app-specific/MIME type icons
[LibreOffice.git] / comphelper / source / misc / weakeventlistener.cxx
blob0543816d0593c61edf9673d694016519147f6392
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 #include <comphelper/weakeventlistener.hxx>
21 #include <osl/diagnose.h>
24 namespace comphelper
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::lang;
31 OWeakListenerAdapterBase::~OWeakListenerAdapterBase()
35 OWeakEventListenerAdapter::OWeakEventListenerAdapter( Reference< XWeak > const & _rxListener, Reference< XComponent > const & _rxBroadcaster )
36 :OWeakEventListenerAdapter_Base( _rxListener, _rxBroadcaster )
38 // add ourself as listener to the broadcaster
39 OSL_ENSURE( _rxBroadcaster.is(), "OWeakEventListenerAdapter::OWeakEventListenerAdapter: invalid broadcaster!" );
40 if ( _rxBroadcaster.is() )
42 osl_atomic_increment( &m_refCount );
44 _rxBroadcaster->addEventListener( this );
46 osl_atomic_decrement( &m_refCount );
47 OSL_ENSURE( m_refCount > 0, "OWeakEventListenerAdapter::OWeakEventListenerAdapter: oops - not to be used with implementations which hold their listeners weak!" );
48 // the one and only reason for this adapter class (A) is to add as listener to a component (C) which
49 // holds its listeners hard, and forward all calls then to another listener (L) which is
50 // held weak by A.
51 // Now if C holds listeners weak, then we do not need A, we can add L directly to C.
54 OSL_ENSURE( getListener().is(), "OWeakEventListenerAdapter::OWeakEventListenerAdapter: invalid listener (does not support the XEventListener interface)!" );
58 void OWeakEventListenerAdapter::disposing( std::unique_lock<std::mutex>& /*rGuard*/ )
60 Reference< XComponent > xBroadcaster( getBroadcaster( ), UNO_QUERY );
61 OSL_ENSURE( xBroadcaster.is(), "OWeakEventListenerAdapter::disposing: broadcaster is invalid in the meantime! How this?" );
62 if ( xBroadcaster.is() )
64 xBroadcaster->removeEventListener( this );
67 resetListener();
71 } // namespace comphelper
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */