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 "OConnectionPointContainerHelper.hxx"
21 :
22 : #include "OConnectionPointHelper.hxx"
23 :
24 : #include <cppuhelper/queryinterface.hxx>
25 :
26 : // namespaces
27 :
28 : using namespace ::osl;
29 : using namespace ::cppu;
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::lang;
32 :
33 : namespace unocontrols{
34 :
35 : // construct/destruct
36 :
37 1 : OConnectionPointContainerHelper::OConnectionPointContainerHelper( Mutex& aMutex )
38 : : m_aSharedMutex ( aMutex )
39 1 : , m_aMultiTypeContainer ( aMutex )
40 : {
41 1 : }
42 :
43 1 : OConnectionPointContainerHelper::~OConnectionPointContainerHelper()
44 : {
45 1 : }
46 :
47 : // XInterface
48 :
49 0 : Any SAL_CALL OConnectionPointContainerHelper::queryInterface( const Type& aType ) throw( RuntimeException, std::exception )
50 : {
51 : // Attention:
52 : // Don't use mutex or guard in this method!!! Is a method of XInterface.
53 :
54 : // Ask for my own supported interfaces ...
55 : Any aReturn ( ::cppu::queryInterface( aType ,
56 : static_cast< XConnectionPointContainer* > ( this )
57 : )
58 0 : );
59 :
60 : // If searched interface not supported by this class ...
61 0 : if ( !aReturn.hasValue() )
62 : {
63 : // ... ask baseclasses.
64 0 : aReturn = OWeakObject::queryInterface( aType );
65 : }
66 :
67 0 : return aReturn;
68 : }
69 :
70 : // XInterface
71 :
72 0 : void SAL_CALL OConnectionPointContainerHelper::acquire() throw()
73 : {
74 : // Attention:
75 : // Don't use mutex or guard in this method!!! Is a method of XInterface.
76 :
77 : // Forward to baseclass
78 0 : OWeakObject::acquire();
79 0 : }
80 :
81 : // XInterface
82 :
83 0 : void SAL_CALL OConnectionPointContainerHelper::release() throw()
84 : {
85 : // Attention:
86 : // Don't use mutex or guard in this method!!! Is a method of XInterface.
87 :
88 : // Forward to baseclass
89 0 : OWeakObject::release();
90 0 : }
91 :
92 : // XConnectionPointContainer
93 :
94 0 : Sequence< Type > SAL_CALL OConnectionPointContainerHelper::getConnectionPointTypes() throw( RuntimeException, std::exception )
95 : {
96 : // Container is threadsafe himself !
97 0 : return m_aMultiTypeContainer.getContainedTypes();
98 : }
99 :
100 : // XConnectionPointContainer
101 :
102 0 : Reference< XConnectionPoint > SAL_CALL OConnectionPointContainerHelper::queryConnectionPoint( const Type& aType ) throw( RuntimeException, std::exception )
103 : {
104 : // Set default return value, if method failed.
105 0 : Reference< XConnectionPoint > xConnectionPoint;
106 :
107 : // Get all elements of the container, which have the searched type.
108 0 : OInterfaceContainerHelper* pSpecialContainer = m_aMultiTypeContainer.getContainer( aType );
109 0 : if ( pSpecialContainer && pSpecialContainer->getLength() > 0 )
110 : {
111 : // Ready for multithreading
112 0 : MutexGuard aGuard( m_aSharedMutex );
113 : // If this container contains elements, build a connectionpoint-instance.
114 0 : OConnectionPointHelper* pNewConnectionPoint = new OConnectionPointHelper( m_aSharedMutex, this, aType );
115 0 : xConnectionPoint = Reference< XConnectionPoint >( static_cast<OWeakObject*>(pNewConnectionPoint), UNO_QUERY );
116 : }
117 :
118 0 : return xConnectionPoint;
119 : }
120 :
121 : // XConnectionPointContainer
122 :
123 0 : void SAL_CALL OConnectionPointContainerHelper::advise( const Type& aType ,
124 : const Reference< XInterface >& xListener ) throw( RuntimeException, std::exception )
125 : {
126 : // Container is threadsafe himself !
127 0 : m_aMultiTypeContainer.addInterface( aType, xListener );
128 0 : }
129 :
130 : // XConnectionPointContainer
131 :
132 0 : void SAL_CALL OConnectionPointContainerHelper::unadvise( const Type& aType ,
133 : const Reference< XInterface >& xListener ) throw( RuntimeException, std::exception )
134 : {
135 : // Container is threadsafe himself !
136 0 : m_aMultiTypeContainer.removeInterface( aType, xListener );
137 0 : }
138 :
139 : } // namespace unocontrols
140 :
141 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|