xref: /aoo42x/main/stoc/source/javavm/interact.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_stoc.hxx"
30 
31 #include "interact.hxx"
32 
33 #include "com/sun/star/java/JavaDisabledException.hpp"
34 #include "com/sun/star/java/JavaVMCreationFailureException.hpp"
35 #include "com/sun/star/task/XInteractionAbort.hpp"
36 #include "com/sun/star/task/XInteractionRetry.hpp"
37 #include "com/sun/star/task/XInteractionContinuation.hpp"
38 #include "cppuhelper/implbase1.hxx"
39 #include "osl/mutex.hxx"
40 
41 namespace css = com::sun::star;
42 
43 using stoc_javavm::InteractionRequest;
44 
45 namespace {
46 
47 class AbortContinuation:
48     public cppu::WeakImplHelper1< css::task::XInteractionAbort >
49 {
50 public:
51     inline AbortContinuation() {}
52 
53     virtual inline void SAL_CALL select() throw (css::uno::RuntimeException) {}
54 
55 private:
56     AbortContinuation(AbortContinuation &); // not implemented
57     void operator =(AbortContinuation); // not implemented
58 
59     virtual inline ~AbortContinuation() {}
60 };
61 
62 }
63 
64 class InteractionRequest::RetryContinuation:
65     public cppu::WeakImplHelper1< css::task::XInteractionRetry >
66 {
67 public:
68     inline RetryContinuation(): m_bSelected(false) {}
69 
70     virtual void SAL_CALL select() throw (css::uno::RuntimeException);
71 
72     bool isSelected() const;
73 
74 private:
75     RetryContinuation(RetryContinuation &); // not implemented
76     void operator =(RetryContinuation); // not implemented
77 
78     virtual inline ~RetryContinuation() {}
79 
80     mutable osl::Mutex m_aMutex;
81     bool m_bSelected;
82 };
83 
84 void SAL_CALL InteractionRequest::RetryContinuation::select()
85     throw (css::uno::RuntimeException)
86 {
87     osl::MutexGuard aGuard(m_aMutex);
88     m_bSelected = true;
89 }
90 
91 bool InteractionRequest::RetryContinuation::isSelected() const
92 {
93     osl::MutexGuard aGuard(m_aMutex);
94     return m_bSelected;
95 }
96 
97 InteractionRequest::InteractionRequest(css::uno::Any const & rRequest):
98     m_aRequest(rRequest)
99 {
100     m_aContinuations.realloc(2);
101     m_xRetryContinuation = new RetryContinuation;
102     m_aContinuations[0] = new AbortContinuation;
103     m_aContinuations[1] = m_xRetryContinuation.get();
104 }
105 
106 css::uno::Any SAL_CALL InteractionRequest::getRequest()
107     throw (css::uno::RuntimeException)
108 {
109     return m_aRequest;
110 }
111 
112 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > >
113 SAL_CALL InteractionRequest::getContinuations()
114     throw (css::uno::RuntimeException)
115 {
116     return m_aContinuations;
117 }
118 
119 bool InteractionRequest::retry() const
120 {
121     return m_xRetryContinuation.is() && m_xRetryContinuation->isSelected();
122 }
123 
124 InteractionRequest::~InteractionRequest()
125 {}
126