xref: /aoo41x/main/stoc/source/javavm/interact.cxx (revision 647a425c)
1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*647a425cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*647a425cSAndrew Rist  * distributed with this work for additional information
6*647a425cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*647a425cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist  * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*647a425cSAndrew Rist  *
11*647a425cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist  *
13*647a425cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist  * software distributed under the License is distributed on an
15*647a425cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*647a425cSAndrew Rist  * specific language governing permissions and limitations
18*647a425cSAndrew Rist  * under the License.
19*647a425cSAndrew Rist  *
20*647a425cSAndrew Rist  *************************************************************/
21*647a425cSAndrew Rist 
22*647a425cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_stoc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "interact.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "com/sun/star/java/JavaDisabledException.hpp"
30cdf0e10cSrcweir #include "com/sun/star/java/JavaVMCreationFailureException.hpp"
31cdf0e10cSrcweir #include "com/sun/star/task/XInteractionAbort.hpp"
32cdf0e10cSrcweir #include "com/sun/star/task/XInteractionRetry.hpp"
33cdf0e10cSrcweir #include "com/sun/star/task/XInteractionContinuation.hpp"
34cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
35cdf0e10cSrcweir #include "osl/mutex.hxx"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir namespace css = com::sun::star;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using stoc_javavm::InteractionRequest;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir class AbortContinuation:
44cdf0e10cSrcweir     public cppu::WeakImplHelper1< css::task::XInteractionAbort >
45cdf0e10cSrcweir {
46cdf0e10cSrcweir public:
AbortContinuation()47cdf0e10cSrcweir     inline AbortContinuation() {}
48cdf0e10cSrcweir 
select()49cdf0e10cSrcweir     virtual inline void SAL_CALL select() throw (css::uno::RuntimeException) {}
50cdf0e10cSrcweir 
51cdf0e10cSrcweir private:
52cdf0e10cSrcweir     AbortContinuation(AbortContinuation &); // not implemented
53cdf0e10cSrcweir     void operator =(AbortContinuation); // not implemented
54cdf0e10cSrcweir 
~AbortContinuation()55cdf0e10cSrcweir     virtual inline ~AbortContinuation() {}
56cdf0e10cSrcweir };
57cdf0e10cSrcweir 
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir class InteractionRequest::RetryContinuation:
61cdf0e10cSrcweir     public cppu::WeakImplHelper1< css::task::XInteractionRetry >
62cdf0e10cSrcweir {
63cdf0e10cSrcweir public:
RetryContinuation()64cdf0e10cSrcweir     inline RetryContinuation(): m_bSelected(false) {}
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     virtual void SAL_CALL select() throw (css::uno::RuntimeException);
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     bool isSelected() const;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir private:
71cdf0e10cSrcweir     RetryContinuation(RetryContinuation &); // not implemented
72cdf0e10cSrcweir     void operator =(RetryContinuation); // not implemented
73cdf0e10cSrcweir 
~RetryContinuation()74cdf0e10cSrcweir     virtual inline ~RetryContinuation() {}
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     mutable osl::Mutex m_aMutex;
77cdf0e10cSrcweir     bool m_bSelected;
78cdf0e10cSrcweir };
79cdf0e10cSrcweir 
select()80cdf0e10cSrcweir void SAL_CALL InteractionRequest::RetryContinuation::select()
81cdf0e10cSrcweir     throw (css::uno::RuntimeException)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     osl::MutexGuard aGuard(m_aMutex);
84cdf0e10cSrcweir     m_bSelected = true;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
isSelected() const87cdf0e10cSrcweir bool InteractionRequest::RetryContinuation::isSelected() const
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     osl::MutexGuard aGuard(m_aMutex);
90cdf0e10cSrcweir     return m_bSelected;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
InteractionRequest(css::uno::Any const & rRequest)93cdf0e10cSrcweir InteractionRequest::InteractionRequest(css::uno::Any const & rRequest):
94cdf0e10cSrcweir     m_aRequest(rRequest)
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     m_aContinuations.realloc(2);
97cdf0e10cSrcweir     m_xRetryContinuation = new RetryContinuation;
98cdf0e10cSrcweir     m_aContinuations[0] = new AbortContinuation;
99cdf0e10cSrcweir     m_aContinuations[1] = m_xRetryContinuation.get();
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
getRequest()102cdf0e10cSrcweir css::uno::Any SAL_CALL InteractionRequest::getRequest()
103cdf0e10cSrcweir     throw (css::uno::RuntimeException)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     return m_aRequest;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > >
getContinuations()109cdf0e10cSrcweir SAL_CALL InteractionRequest::getContinuations()
110cdf0e10cSrcweir     throw (css::uno::RuntimeException)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     return m_aContinuations;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
retry() const115cdf0e10cSrcweir bool InteractionRequest::retry() const
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     return m_xRetryContinuation.is() && m_xRetryContinuation->isSelected();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
~InteractionRequest()120cdf0e10cSrcweir InteractionRequest::~InteractionRequest()
121cdf0e10cSrcweir {}
122