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>
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
{
37 OConnectionPointContainerHelper::OConnectionPointContainerHelper( Mutex
& aMutex
)
38 : m_aSharedMutex ( aMutex
)
39 , m_aMultiTypeContainer ( aMutex
)
43 OConnectionPointContainerHelper::~OConnectionPointContainerHelper()
49 Any SAL_CALL
OConnectionPointContainerHelper::queryInterface( const Type
& aType
) throw( RuntimeException
, std::exception
)
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 searched interface not supported by this class ...
61 if ( !aReturn
.hasValue() )
63 // ... ask baseclasses.
64 aReturn
= OWeakObject::queryInterface( aType
);
72 void SAL_CALL
OConnectionPointContainerHelper::acquire() throw()
75 // Don't use mutex or guard in this method!!! Is a method of XInterface.
77 // Forward to baseclass
78 OWeakObject::acquire();
83 void SAL_CALL
OConnectionPointContainerHelper::release() throw()
86 // Don't use mutex or guard in this method!!! Is a method of XInterface.
88 // Forward to baseclass
89 OWeakObject::release();
92 // XConnectionPointContainer
94 Sequence
< Type
> SAL_CALL
OConnectionPointContainerHelper::getConnectionPointTypes() throw( RuntimeException
, std::exception
)
96 // Container is threadsafe himself !
97 return m_aMultiTypeContainer
.getContainedTypes();
100 // XConnectionPointContainer
102 Reference
< XConnectionPoint
> SAL_CALL
OConnectionPointContainerHelper::queryConnectionPoint( const Type
& aType
) throw( RuntimeException
, std::exception
)
104 // Set default return value, if method failed.
105 Reference
< XConnectionPoint
> xConnectionPoint
;
107 // Get all elements of the container, which have the searched type.
108 OInterfaceContainerHelper
* pSpecialContainer
= m_aMultiTypeContainer
.getContainer( aType
);
109 if ( pSpecialContainer
&& pSpecialContainer
->getLength() > 0 )
111 // Ready for multithreading
112 MutexGuard
aGuard( m_aSharedMutex
);
113 // If this container contains elements, build a connectionpoint-instance.
114 OConnectionPointHelper
* pNewConnectionPoint
= new OConnectionPointHelper( m_aSharedMutex
, this, aType
);
115 xConnectionPoint
= Reference
< XConnectionPoint
>( (OWeakObject
*)pNewConnectionPoint
, UNO_QUERY
);
118 return xConnectionPoint
;
121 // XConnectionPointContainer
123 void SAL_CALL
OConnectionPointContainerHelper::advise( const Type
& aType
,
124 const Reference
< XInterface
>& xListener
) throw( RuntimeException
, std::exception
)
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
) throw( RuntimeException
, std::exception
)
135 // Container is threadsafe himself !
136 m_aMultiTypeContainer
.removeInterface( aType
, xListener
);
139 } // namespace unocontrols
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */