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/containermultiplexer.hxx"
21 : : #include "comphelper/uno3.hxx"
22 : : #include <osl/diagnose.h>
23 : : //.........................................................................
24 : : namespace comphelper
25 : : {
26 : : //.........................................................................
27 : :
28 : : using namespace ::com::sun::star::uno;
29 : : using namespace ::com::sun::star::lang;
30 : : using namespace ::com::sun::star::container;
31 : :
32 : : //=====================================================================
33 : : //= OContainerListener
34 : : //=====================================================================
35 : : //---------------------------------------------------------------------
36 : 0 : OContainerListener::OContainerListener(::osl::Mutex& _rMutex)
37 : : :m_pAdapter(NULL)
38 : 0 : ,m_rMutex(_rMutex)
39 : : {
40 : 0 : }
41 : :
42 : : //---------------------------------------------------------------------
43 : 0 : OContainerListener::~OContainerListener()
44 : : {
45 [ # # ]: 0 : if (m_pAdapter)
46 : : {
47 : 0 : m_pAdapter->dispose();
48 : 0 : m_pAdapter = NULL;
49 : : }
50 [ # # ]: 0 : }
51 : :
52 : : //---------------------------------------------------------------------
53 : 0 : void OContainerListener::_elementInserted( const ContainerEvent& /*_rEvent*/ ) throw(RuntimeException)
54 : : {
55 : 0 : }
56 : :
57 : : //---------------------------------------------------------------------
58 : 0 : void OContainerListener::_elementRemoved( const ContainerEvent& ) throw(RuntimeException)
59 : : {
60 : 0 : }
61 : :
62 : : //---------------------------------------------------------------------
63 : 0 : void OContainerListener::_elementReplaced( const ContainerEvent& /*_rEvent*/ ) throw(RuntimeException)
64 : : {
65 : 0 : }
66 : :
67 : : //---------------------------------------------------------------------
68 : 0 : void OContainerListener::_disposing(const EventObject& ) throw( RuntimeException)
69 : : {
70 : 0 : }
71 : :
72 : : //------------------------------------------------------------------
73 : 0 : void OContainerListener::setAdapter(OContainerListenerAdapter* pAdapter)
74 : : {
75 [ # # ]: 0 : if (m_pAdapter)
76 : : {
77 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_rMutex);
78 : 0 : m_pAdapter->release();
79 [ # # ]: 0 : m_pAdapter = NULL;
80 : : }
81 : :
82 [ # # ]: 0 : if (pAdapter)
83 : : {
84 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_rMutex);
85 : 0 : m_pAdapter = pAdapter;
86 [ # # ]: 0 : m_pAdapter->acquire();
87 : : }
88 : 0 : }
89 : :
90 : : //=====================================================================
91 : : //= OContainerListenerAdapter
92 : : //=====================================================================
93 : : //---------------------------------------------------------------------
94 : 0 : OContainerListenerAdapter::OContainerListenerAdapter(OContainerListener* _pListener,
95 : : const Reference< XContainer >& _rxContainer)
96 : : :m_xContainer(_rxContainer)
97 : : ,m_pListener(_pListener)
98 : 0 : ,m_nLockCount(0)
99 : : {
100 [ # # ]: 0 : if (m_pListener)
101 [ # # ]: 0 : m_pListener->setAdapter(this);
102 : :
103 [ # # ]: 0 : ::comphelper::increment(m_refCount);
104 : : try
105 : : {
106 [ # # ][ # # ]: 0 : m_xContainer->addContainerListener(this);
[ # # ][ # # ]
107 : : }
108 [ # # ]: 0 : catch(const Exception&)
109 : : {
110 : : OSL_FAIL("Exceptiopn caught!");
111 : : }
112 [ # # ]: 0 : ::comphelper::decrement(m_refCount);
113 : 0 : }
114 : :
115 : : //---------------------------------------------------------------------
116 : 0 : OContainerListenerAdapter::~OContainerListenerAdapter()
117 : : {
118 [ # # ]: 0 : }
119 : :
120 : : //------------------------------------------------------------------
121 : 0 : void OContainerListenerAdapter::dispose()
122 : : {
123 [ # # ]: 0 : if (m_xContainer.is())
124 : : {
125 : : try
126 : : {
127 [ # # ]: 0 : Reference< XContainerListener > xPreventDelete(this);
128 [ # # ][ # # ]: 0 : m_xContainer->removeContainerListener(xPreventDelete);
129 [ # # ][ # # ]: 0 : m_pListener->setAdapter(NULL);
130 : : }
131 : 0 : catch(const Exception&)
132 : : {
133 : : OSL_FAIL("Exception caught!");
134 : : }
135 : 0 : m_xContainer = NULL;
136 : 0 : m_pListener = NULL;
137 : : }
138 : 0 : }
139 : :
140 : : //------------------------------------------------------------------
141 : 0 : void SAL_CALL OContainerListenerAdapter::disposing( const EventObject& _rSource) throw(RuntimeException)
142 : : {
143 [ # # ]: 0 : if (m_pListener)
144 : : {
145 : : // tell the listener
146 [ # # ]: 0 : if (!locked())
147 : 0 : m_pListener->_disposing(_rSource);
148 : : // disconnect the listener
149 [ # # ]: 0 : if ( m_pListener )
150 : 0 : m_pListener->setAdapter(NULL);
151 : : }
152 : :
153 : 0 : m_xContainer = NULL;
154 : 0 : m_pListener = NULL;
155 : 0 : }
156 : :
157 : : //------------------------------------------------------------------
158 : 0 : void SAL_CALL OContainerListenerAdapter::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException)
159 : : {
160 [ # # ][ # # ]: 0 : if (m_pListener && !locked())
[ # # ]
161 : 0 : m_pListener->_elementInserted(_rEvent);
162 : 0 : }
163 : :
164 : : //------------------------------------------------------------------
165 : 0 : void SAL_CALL OContainerListenerAdapter::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException)
166 : : {
167 [ # # ][ # # ]: 0 : if (m_pListener && !locked())
[ # # ]
168 : 0 : m_pListener->_elementRemoved(_rEvent);
169 : 0 : }
170 : :
171 : : //------------------------------------------------------------------
172 : 0 : void SAL_CALL OContainerListenerAdapter::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException)
173 : : {
174 [ # # ][ # # ]: 0 : if (m_pListener && !locked())
[ # # ]
175 : 0 : m_pListener->_elementReplaced(_rEvent);
176 : 0 : }
177 : :
178 : : //.........................................................................
179 : : } // namespace comphelper
180 : : //.........................................................................
181 : :
182 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|