Branch data Line data Source code
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 : : #include <comphelper/weakeventlistener.hxx>
21 : : #include <osl/diagnose.h>
22 : :
23 : :
24 : : //.........................................................................
25 : : namespace comphelper
26 : : {
27 : : //.........................................................................
28 : :
29 : : using namespace ::com::sun::star::uno;
30 : : using namespace ::com::sun::star::lang;
31 : :
32 : : //=====================================================================
33 : : //= OWeakListenerAdapter
34 : : //=====================================================================
35 : : //---------------------------------------------------------------------
36 [ # # ]: 0 : OWeakListenerAdapterBase::~OWeakListenerAdapterBase()
37 : : {
38 [ # # ]: 0 : }
39 : :
40 : : //=====================================================================
41 : : //= OWeakEventListenerAdapter
42 : : //=====================================================================
43 : : //---------------------------------------------------------------------
44 : 0 : OWeakEventListenerAdapter::OWeakEventListenerAdapter( Reference< XWeak > _rxListener, Reference< XComponent > _rxBroadcaster )
45 : 0 : :OWeakEventListenerAdapter_Base( _rxListener, _rxBroadcaster )
46 : : {
47 : : // add ourself as listener to the broadcaster
48 : : OSL_ENSURE( _rxBroadcaster.is(), "OWeakEventListenerAdapter::OWeakEventListenerAdapter: invalid broadcaster!" );
49 [ # # ]: 0 : if ( _rxBroadcaster.is() )
50 : : {
51 [ # # ]: 0 : osl_incrementInterlockedCount( &m_refCount );
52 : : {
53 [ # # ][ # # ]: 0 : _rxBroadcaster->addEventListener( this );
[ # # ]
54 : : }
55 [ # # ]: 0 : osl_decrementInterlockedCount( &m_refCount );
56 : : OSL_ENSURE( m_refCount > 0, "OWeakEventListenerAdapter::OWeakEventListenerAdapter: oops - not to be used with implementations which hold their listeners weak!" );
57 : : // the one and only reason for this adapter class (A) is to add as listener to a component (C) which
58 : : // holds its listeners hard, and forward all calls then to another listener (L) which is
59 : : // held weak by A.
60 : : // Now if C holds listeners weak, then we do not need A, we can add L directly to C.
61 : : }
62 : :
63 : : OSL_ENSURE( getListener().is(), "OWeakEventListenerAdapter::OWeakEventListenerAdapter: invalid listener (does not support the XEventListener interface)!" );
64 : 0 : }
65 : :
66 : : //---------------------------------------------------------------------
67 : 0 : void SAL_CALL OWeakEventListenerAdapter::disposing( )
68 : : {
69 [ # # ]: 0 : Reference< XComponent > xBroadcaster( getBroadcaster( ), UNO_QUERY );
70 : : OSL_ENSURE( xBroadcaster.is(), "OWeakEventListenerAdapter::disposing: broadcaster is invalid in the meantime! How this?" );
71 [ # # ]: 0 : if ( xBroadcaster.is() )
72 : : {
73 [ # # ][ # # ]: 0 : xBroadcaster->removeEventListener( this );
[ # # ]
74 : : }
75 : :
76 [ # # ]: 0 : resetListener();
77 : 0 : }
78 : :
79 : : //.........................................................................
80 : : } // namespace comphelper
81 : : //.........................................................................
82 : :
83 : :
84 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|