1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <OConnectionPointContainerHelper.hxx>
22 #include <OConnectionPointHelper.hxx>
24 #include <cppuhelper/queryinterface.hxx>
25 #include <comphelper/sequence.hxx>
29 using namespace ::osl
;
30 using namespace ::cppu
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::lang
;
34 namespace unocontrols
{
38 OConnectionPointContainerHelper::OConnectionPointContainerHelper( Mutex
& aMutex
)
39 : m_aSharedMutex ( aMutex
)
40 , m_aMultiTypeContainer ( aMutex
)
44 OConnectionPointContainerHelper::~OConnectionPointContainerHelper()
49 Any SAL_CALL
OConnectionPointContainerHelper::queryInterface( const Type
& aType
)
52 // Don't use mutex or guard in this method!!! Is a method of XInterface.
54 // Ask for my own supported interfaces ...
55 Any
aReturn ( ::cppu::queryInterface( aType
,
56 static_cast< XConnectionPointContainer
* > ( this )
60 if (aReturn
.hasValue())
63 // If searched interface not supported by this class ...
64 // ... ask baseclasses.
65 return OWeakObject::queryInterface( aType
);
69 void SAL_CALL
OConnectionPointContainerHelper::acquire() noexcept
72 // Don't use mutex or guard in this method!!! Is a method of XInterface.
74 // Forward to baseclass
75 OWeakObject::acquire();
79 void SAL_CALL
OConnectionPointContainerHelper::release() noexcept
82 // Don't use mutex or guard in this method!!! Is a method of XInterface.
84 // Forward to baseclass
85 OWeakObject::release();
88 // XConnectionPointContainer
90 Sequence
< Type
> SAL_CALL
OConnectionPointContainerHelper::getConnectionPointTypes()
92 // Container is threadsafe himself !
93 return comphelper::containerToSequence(m_aMultiTypeContainer
.getContainedTypes());
96 // XConnectionPointContainer
98 Reference
< XConnectionPoint
> SAL_CALL
OConnectionPointContainerHelper::queryConnectionPoint( const Type
& aType
)
100 // Set default return value, if method failed.
101 Reference
< XConnectionPoint
> xConnectionPoint
;
103 // Get all elements of the container, which have the searched type.
104 comphelper::OInterfaceContainerHelper2
* pSpecialContainer
= m_aMultiTypeContainer
.getContainer( aType
);
105 if ( pSpecialContainer
&& pSpecialContainer
->getLength() > 0 )
107 // Ready for multithreading
108 MutexGuard
aGuard( m_aSharedMutex
);
109 // If this container contains elements, build a connectionpoint-instance.
110 xConnectionPoint
= new OConnectionPointHelper( m_aSharedMutex
, this, aType
);
113 return xConnectionPoint
;
116 // XConnectionPointContainer
118 void SAL_CALL
OConnectionPointContainerHelper::advise( const Type
& aType
,
119 const Reference
< XInterface
>& xListener
)
121 // Container is threadsafe himself !
122 m_aMultiTypeContainer
.addInterface( aType
, xListener
);
125 // XConnectionPointContainer
127 void SAL_CALL
OConnectionPointContainerHelper::unadvise( const Type
& aType
,
128 const Reference
< XInterface
>& xListener
)
130 // Container is threadsafe himself !
131 m_aMultiTypeContainer
.removeInterface( aType
, xListener
);
134 } // namespace unocontrols
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */