xref: /trunk/main/stoc/source/javavm/interact.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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:
47     inline AbortContinuation() {}
48 
49     virtual inline void SAL_CALL select() {}
50 
51 private:
52     AbortContinuation(AbortContinuation &); // not implemented
53     void operator =(AbortContinuation); // not implemented
54 
55     virtual inline ~AbortContinuation() {}
56 };
57 
58 }
59 
60 class InteractionRequest::RetryContinuation:
61     public cppu::WeakImplHelper1< css::task::XInteractionRetry >
62 {
63 public:
64     inline RetryContinuation(): m_bSelected(false) {}
65 
66     virtual void SAL_CALL select();
67 
68     bool isSelected() const;
69 
70 private:
71     RetryContinuation(RetryContinuation &); // not implemented
72     void operator =(RetryContinuation); // not implemented
73 
74     virtual inline ~RetryContinuation() {}
75 
76     mutable osl::Mutex m_aMutex;
77     bool m_bSelected;
78 };
79 
80 void SAL_CALL InteractionRequest::RetryContinuation::select()
81 {
82     osl::MutexGuard aGuard(m_aMutex);
83     m_bSelected = true;
84 }
85 
86 bool InteractionRequest::RetryContinuation::isSelected() const
87 {
88     osl::MutexGuard aGuard(m_aMutex);
89     return m_bSelected;
90 }
91 
92 InteractionRequest::InteractionRequest(css::uno::Any const & rRequest):
93     m_aRequest(rRequest)
94 {
95     m_aContinuations.realloc(2);
96     m_xRetryContinuation = new RetryContinuation;
97     m_aContinuations[0] = new AbortContinuation;
98     m_aContinuations[1] = m_xRetryContinuation.get();
99 }
100 
101 css::uno::Any SAL_CALL InteractionRequest::getRequest()
102 {
103     return m_aRequest;
104 }
105 
106 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > >
107 SAL_CALL InteractionRequest::getContinuations()
108 {
109     return m_aContinuations;
110 }
111 
112 bool InteractionRequest::retry() const
113 {
114     return m_xRetryContinuation.is() && m_xRetryContinuation->isSelected();
115 }
116 
117 InteractionRequest::~InteractionRequest()
118 {}
119