fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / UnoControls / source / controls / OConnectionPointHelper.cxx
blobc580013111666469ae1a379d4122634356bc6668
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 "OConnectionPointHelper.hxx"
22 #include "OConnectionPointContainerHelper.hxx"
24 #include <cppuhelper/queryinterface.hxx>
26 // namespaces
28 using namespace ::osl;
29 using namespace ::cppu;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::lang;
33 namespace unocontrols{
35 // construct/destruct
37 OConnectionPointHelper::OConnectionPointHelper(
38 Mutex& aMutex ,
39 OConnectionPointContainerHelper* pContainerImplementation ,
40 Type aType
41 ) : m_aSharedMutex ( aMutex )
42 , m_oContainerWeakReference ( pContainerImplementation )
43 , m_pContainerImplementation ( pContainerImplementation )
44 , m_aInterfaceType ( aType )
48 OConnectionPointHelper::~OConnectionPointHelper()
52 // XInterface
54 Any SAL_CALL OConnectionPointHelper::queryInterface( const Type& aType ) throw( RuntimeException, std::exception )
56 // Attention:
57 // Don't use mutex or guard in this method!!! Is a method of XInterface.
59 // Ask for my own supported interfaces ...
60 Any aReturn ( ::cppu::queryInterface( aType ,
61 static_cast< XConnectionPoint* > ( this )
65 // If searched interface not supported by this class ...
66 if ( !aReturn.hasValue() )
68 // ... ask baseclasses.
69 aReturn = OWeakObject::queryInterface( aType );
72 return aReturn;
75 // XInterface
77 void SAL_CALL OConnectionPointHelper::acquire() throw()
79 // Attention:
80 // Don't use mutex or guard in this method!!! Is a method of XInterface.
82 // Forward to baseclass
83 OWeakObject::acquire();
86 // XInterface
88 void SAL_CALL OConnectionPointHelper::release() throw()
90 // Attention:
91 // Don't use mutex or guard in this method!!! Is a method of XInterface.
93 // Forward to baseclass
94 OWeakObject::release();
97 // XConnectionPoint
99 Type SAL_CALL OConnectionPointHelper::getConnectionType() throw( RuntimeException, std::exception )
101 // Ready for multithreading
102 MutexGuard aGuard( m_aSharedMutex );
104 // Set default return value, if method failed.
105 if ( !impl_LockContainer() )
107 // Container not exist! Its an runtime error.
108 throw RuntimeException();
111 // If container reference valid, return right type of supported interfaces of THIS connectionpoint.
112 Type aReturnType = m_aInterfaceType;
113 // Don't forget this!
114 impl_UnlockContainer();
116 return aReturnType;
119 // XConnectionPoint
121 Reference< XConnectionPointContainer > SAL_CALL OConnectionPointHelper::getConnectionPointContainer() throw( RuntimeException, std::exception )
123 // Ready for multithreading
124 MutexGuard aGuard( m_aSharedMutex );
125 // Convert weakreference to correct uno3-reference and return value. It can be NULL, if container destroyed!
126 return Reference< XConnectionPointContainer >( m_oContainerWeakReference.get(), UNO_QUERY );
129 // XConnectionPoint
131 void SAL_CALL OConnectionPointHelper::advise( const Reference< XInterface >& xListener ) throw( ListenerExistException ,
132 InvalidListenerException ,
133 RuntimeException, std::exception )
135 // Ready for multithreading
136 MutexGuard aGuard( m_aSharedMutex );
138 // If type of listener not the same for this special container ...
139 Any aCheckType = xListener->queryInterface( m_aInterfaceType );
140 if ( aCheckType.hasValue() )
142 // ... throw an exception.
143 throw InvalidListenerException();
146 // ListenerExistException is obsolete!?
147 // Its the same container for XConnectionPointContainer and XConnectionPoint. But only here we must control, if a listener already exist!?
148 // You can add a listener more than one time at XConnectionPointContainer, but here only one ...
150 // Operation is permitted only, if reference to container is valid!
151 if ( !impl_LockContainer() )
153 // Container not exist! Its an runtime error.
154 throw RuntimeException();
156 // Forward it to OConnectionPointHelperContainer!
157 m_pContainerImplementation->advise( m_aInterfaceType, xListener );
158 // Don't forget this!
159 impl_UnlockContainer();
162 // XConnectionPoint
164 void SAL_CALL OConnectionPointHelper::unadvise( const Reference< XInterface >& xListener ) throw( RuntimeException, std::exception )
166 // Ready for multithreading
167 MutexGuard aGuard( m_aSharedMutex );
168 // Operation is permitted only, if reference to container is valid!
169 if ( !impl_LockContainer() )
171 // Container not exist! Its an runtime error.
172 throw RuntimeException();
175 // Forward it to OConnectionPointHelperContainer!
176 m_pContainerImplementation->unadvise( m_aInterfaceType, xListener );
177 // Don't forget this!
178 impl_UnlockContainer();
181 // XConnectionPoint
183 Sequence< Reference< XInterface > > SAL_CALL OConnectionPointHelper::getConnections() throw( RuntimeException, std::exception )
185 // Ready for multithreading
186 MutexGuard aGuard( m_aSharedMutex );
187 // Operation is permitted only, if reference to container is valid!
188 if ( !impl_LockContainer() )
190 // Container not exist! Its an runtime error.
191 throw RuntimeException();
193 // Set default return value, if method failed.
194 Sequence< Reference< XInterface > > seqReturnConnections = Sequence< Reference< XInterface > >();
195 // Get reference to private member of OConnectionPointHelperContainer!
196 OMultiTypeInterfaceContainerHelper& aSharedContainer = m_pContainerImplementation->impl_getMultiTypeContainer();
197 // Get pointer to specialized container which hold all interfaces of searched type.
198 OInterfaceContainerHelper* pSpecialContainer = aSharedContainer.getContainer( m_aInterfaceType );
199 // Get elements of searched type, if somelse exist.
200 if ( pSpecialContainer != NULL )
202 seqReturnConnections = pSpecialContainer->getElements();
204 // Don't forget this!
205 impl_UnlockContainer();
207 return seqReturnConnections;
210 // private method
212 bool OConnectionPointHelper::impl_LockContainer()
214 // Convert weakreference to hard uno3-reference and return state.
215 // If this reference different from NULL, there exist a hard reference to container. Container-instance can't be destroyed.
216 // Don't forget to "unlock" this reference!
217 m_xLock = m_oContainerWeakReference.get();
218 return m_xLock.is();
221 // private method
223 void OConnectionPointHelper::impl_UnlockContainer()
225 // Free hard uno3-reference to container.
226 // see also "impl_LockContainer()"
227 m_xLock.clear();
230 } // namespace unocontrols
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */