1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
31 #include "interaction/preventduplicateinteraction.hxx"
33 //_________________________________________________________________________________________________________________
35 //_________________________________________________________________________________________________________________
37 //_________________________________________________________________________________________________________________
39 //_________________________________________________________________________________________________________________
40 #include <com/sun/star/task/XInteractionAbort.hpp>
41 #include <com/sun/star/task/XInteractionRetry.hpp>
43 //_________________________________________________________________________________________________________________
45 //_________________________________________________________________________________________________________________
47 //_________________________________________________________________________________________________________________
49 //_________________________________________________________________________________________________________________
53 namespace css
= ::com::sun::star
;
55 //_________________________________________________________________________________________________________________
57 //_________________________________________________________________________________________________________________
59 #define IMPLEMENTATIONNAME_UIINTERACTIONHANDLER ::rtl::OUString::createFromAscii("com.sun.star.comp.uui.UUIInteractionHandler")
61 //_________________________________________________________________________________________________________________
62 // exported definitions
63 //_________________________________________________________________________________________________________________
65 //_________________________________________________________________________________________________________________
67 PreventDuplicateInteraction::PreventDuplicateInteraction(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
)
73 //_________________________________________________________________________________________________________________
75 PreventDuplicateInteraction::~PreventDuplicateInteraction()
79 //_________________________________________________________________________________________________________________
81 void PreventDuplicateInteraction::setHandler(const css::uno::Reference
< css::task::XInteractionHandler
>& xHandler
)
84 ::osl::ResettableMutexGuard
aLock(m_aLock
);
85 m_xHandler
= xHandler
;
90 //_________________________________________________________________________________________________________________
92 void PreventDuplicateInteraction::useDefaultUUIHandler()
95 ::osl::ResettableMutexGuard
aLock(m_aLock
);
96 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
100 css::uno::Reference
< css::task::XInteractionHandler
> xHandler(
101 xSMGR
->createInstance(IMPLEMENTATIONNAME_UIINTERACTIONHANDLER
),
102 css::uno::UNO_QUERY_THROW
);
106 m_xHandler
= xHandler
;
111 //_________________________________________________________________________________________________________________
112 css::uno::Any SAL_CALL
PreventDuplicateInteraction::queryInterface( const css::uno::Type
& aType
)
113 throw (css::uno::RuntimeException
)
115 if ( aType
.equals( XInteractionHandler2::static_type() ) )
117 ::osl::ResettableMutexGuard
aLock(m_aLock
);
118 css::uno::Reference
< css::task::XInteractionHandler2
> xHandler( m_xHandler
, css::uno::UNO_QUERY
);
119 if ( !xHandler
.is() )
120 return css::uno::Any();
122 return ::cppu::WeakImplHelper1
< css::task::XInteractionHandler2
>::queryInterface( aType
);
125 //_________________________________________________________________________________________________________________
127 void SAL_CALL
PreventDuplicateInteraction::handle(const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
)
128 throw(css::uno::RuntimeException
)
130 css::uno::Any aRequest
= xRequest
->getRequest();
131 sal_Bool bHandleIt
= sal_True
;
134 ::osl::ResettableMutexGuard
aLock(m_aLock
);
136 InteractionList::iterator pIt
;
137 for ( pIt
= m_lInteractionRules
.begin();
138 pIt
!= m_lInteractionRules
.end() ;
141 InteractionInfo
& rInfo
= *pIt
;
143 if (aRequest
.isExtractableTo(rInfo
.m_aInteraction
))
145 ++rInfo
.m_nCallCount
;
146 rInfo
.m_xRequest
= xRequest
;
147 bHandleIt
= (rInfo
.m_nCallCount
<= rInfo
.m_nMaxCount
);
152 css::uno::Reference
< css::task::XInteractionHandler
> xHandler
= m_xHandler
;
162 xHandler
->handle(xRequest
);
166 const css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > lContinuations
= xRequest
->getContinuations();
167 sal_Int32 c
= lContinuations
.getLength();
171 css::uno::Reference
< css::task::XInteractionAbort
> xAbort(lContinuations
[i
], css::uno::UNO_QUERY
);
181 //_________________________________________________________________________________________________________________
183 ::sal_Bool SAL_CALL
PreventDuplicateInteraction::handleInteractionRequest( const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
)
184 throw (css::uno::RuntimeException
)
186 css::uno::Any aRequest
= xRequest
->getRequest();
187 sal_Bool bHandleIt
= sal_True
;
190 ::osl::ResettableMutexGuard
aLock(m_aLock
);
192 InteractionList::iterator pIt
;
193 for ( pIt
= m_lInteractionRules
.begin();
194 pIt
!= m_lInteractionRules
.end() ;
197 InteractionInfo
& rInfo
= *pIt
;
199 if (aRequest
.isExtractableTo(rInfo
.m_aInteraction
))
201 ++rInfo
.m_nCallCount
;
202 rInfo
.m_xRequest
= xRequest
;
203 bHandleIt
= (rInfo
.m_nCallCount
<= rInfo
.m_nMaxCount
);
208 css::uno::Reference
< css::task::XInteractionHandler2
> xHandler( m_xHandler
, css::uno::UNO_QUERY
);
209 OSL_ENSURE( xHandler
.is() || !m_xHandler
.is(),
210 "PreventDuplicateInteraction::handleInteractionRequest: inconsistency!" );
220 return xHandler
->handleInteractionRequest(xRequest
);
224 const css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > lContinuations
= xRequest
->getContinuations();
225 sal_Int32 c
= lContinuations
.getLength();
229 css::uno::Reference
< css::task::XInteractionAbort
> xAbort(lContinuations
[i
], css::uno::UNO_QUERY
);
240 //_________________________________________________________________________________________________________________
242 void PreventDuplicateInteraction::addInteractionRule(const PreventDuplicateInteraction::InteractionInfo
& aInteractionInfo
)
245 ::osl::ResettableMutexGuard
aLock(m_aLock
);
247 InteractionList::iterator pIt
;
248 for ( pIt
= m_lInteractionRules
.begin();
249 pIt
!= m_lInteractionRules
.end() ;
252 InteractionInfo
& rInfo
= *pIt
;
253 if (rInfo
.m_aInteraction
== aInteractionInfo
.m_aInteraction
)
255 rInfo
.m_nMaxCount
= aInteractionInfo
.m_nMaxCount
;
256 rInfo
.m_nCallCount
= aInteractionInfo
.m_nCallCount
;
261 m_lInteractionRules
.push_back(aInteractionInfo
);
267 //_________________________________________________________________________________________________________________
269 sal_Bool
PreventDuplicateInteraction::getInteractionInfo(const css::uno::Type
& aInteraction
,
270 PreventDuplicateInteraction::InteractionInfo
* pReturn
) const
273 ::osl::ResettableMutexGuard
aLock(m_aLock
);
275 PreventDuplicateInteraction::InteractionList::const_iterator pIt
;
276 for ( pIt
= m_lInteractionRules
.begin();
277 pIt
!= m_lInteractionRules
.end() ;
280 const PreventDuplicateInteraction::InteractionInfo
& rInfo
= *pIt
;
281 if (rInfo
.m_aInteraction
== aInteraction
)
294 } // namespace framework