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