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