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()
50 Any SAL_CALL
OConnectionPointContainerHelper::queryInterface( const Type
& aType
)
53 // Don't use mutex or guard in this method!!! Is a method of XInterface.
55 // Ask for my own supported interfaces ...
56 Any
aReturn ( ::cppu::queryInterface( aType
,
57 static_cast< XConnectionPointContainer
* > ( this )
61 // If searched interface not supported by this class ...
62 if ( !aReturn
.hasValue() )
64 // ... ask baseclasses.
65 aReturn
= OWeakObject::queryInterface( aType
);
73 void SAL_CALL
OConnectionPointContainerHelper::acquire() noexcept
76 // Don't use mutex or guard in this method!!! Is a method of XInterface.
78 // Forward to baseclass
79 OWeakObject::acquire();
84 void SAL_CALL
OConnectionPointContainerHelper::release() noexcept
87 // Don't use mutex or guard in this method!!! Is a method of XInterface.
89 // Forward to baseclass
90 OWeakObject::release();
93 // XConnectionPointContainer
95 Sequence
< Type
> SAL_CALL
OConnectionPointContainerHelper::getConnectionPointTypes()
97 // Container is threadsafe himself !
98 return comphelper::containerToSequence(m_aMultiTypeContainer
.getContainedTypes());
101 // XConnectionPointContainer
103 Reference
< XConnectionPoint
> SAL_CALL
OConnectionPointContainerHelper::queryConnectionPoint( const Type
& aType
)
105 // Set default return value, if method failed.
106 Reference
< XConnectionPoint
> xConnectionPoint
;
108 // Get all elements of the container, which have the searched type.
109 comphelper::OInterfaceContainerHelper2
* pSpecialContainer
= m_aMultiTypeContainer
.getContainer( aType
);
110 if ( pSpecialContainer
&& pSpecialContainer
->getLength() > 0 )
112 // Ready for multithreading
113 MutexGuard
aGuard( m_aSharedMutex
);
114 // If this container contains elements, build a connectionpoint-instance.
115 xConnectionPoint
= new OConnectionPointHelper( m_aSharedMutex
, this, aType
);
118 return xConnectionPoint
;
121 // XConnectionPointContainer
123 void SAL_CALL
OConnectionPointContainerHelper::advise( const Type
& aType
,
124 const Reference
< XInterface
>& xListener
)
126 // Container is threadsafe himself !
127 m_aMultiTypeContainer
.addInterface( aType
, xListener
);
130 // XConnectionPointContainer
132 void SAL_CALL
OConnectionPointContainerHelper::unadvise( const Type
& aType
,
133 const Reference
< XInterface
>& xListener
)
135 // Container is threadsafe himself !
136 m_aMultiTypeContainer
.removeInterface( aType
, xListener
);
139 } // namespace unocontrols
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */