Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / stoc / source / javavm / javavm.hxx
bloba8883f1ddffb2816c546073b6a93cc88898fd1e5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_STOC_SOURCE_JAVAVM_JAVAVM_HXX
21 #define INCLUDED_STOC_SOURCE_JAVAVM_JAVAVM_HXX
23 #include "jvmargs.hxx"
25 #include <com/sun/star/container/XContainerListener.hpp>
26 #include <com/sun/star/lang/XInitialization.hpp>
27 #include <com/sun/star/java/XJavaThreadRegister_11.hpp>
28 #include <com/sun/star/java/XJavaVM.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
31 #include <cppuhelper/basemutex.hxx>
32 #include <cppuhelper/compbase.hxx>
33 #include <osl/thread.hxx>
34 #include <rtl/ref.hxx>
35 #include <rtl/ustring.hxx>
37 namespace com { namespace sun { namespace star {
38 namespace container { class XContainer; }
39 namespace uno { class XComponentContext; }
40 } } }
41 namespace jvmaccess {
42 class UnoVirtualMachine;
43 class VirtualMachine;
46 namespace stoc_javavm {
48 // The MS compiler needs a typedef here, so the JavaVirtualMachine ctor can call
49 // its base class ctor:
50 typedef
51 cppu::WeakComponentImplHelper< css::lang::XInitialization,
52 css::lang::XServiceInfo,
53 css::java::XJavaVM,
54 css::java::XJavaThreadRegister_11,
55 css::container::XContainerListener >
56 JavaVirtualMachine_Impl;
58 class JavaVirtualMachine:
59 private cppu::BaseMutex, public JavaVirtualMachine_Impl
61 public:
62 explicit JavaVirtualMachine(
63 css::uno::Reference<
64 css::uno::XComponentContext > const & rContext);
66 // XInitialization
67 virtual void SAL_CALL
68 initialize(css::uno::Sequence< css::uno::Any > const &
69 rArguments) override;
71 // XServiceInfo
72 virtual OUString SAL_CALL getImplementationName() override;
74 virtual sal_Bool SAL_CALL
75 supportsService(OUString const & rServiceName) override;
77 virtual css::uno::Sequence< OUString > SAL_CALL
78 getSupportedServiceNames() override;
80 // XJavaVM
81 virtual css::uno::Any SAL_CALL
82 getJavaVM(css::uno::Sequence< sal_Int8 > const & rProcessId) override;
84 virtual sal_Bool SAL_CALL isVMStarted() override;
86 virtual sal_Bool SAL_CALL isVMEnabled() override;
88 // XJavaThreadRegister_11
89 virtual sal_Bool SAL_CALL isThreadAttached() override;
91 virtual void SAL_CALL registerThread() override;
93 virtual void SAL_CALL revokeThread() override;
95 // XContainerListener
96 virtual void SAL_CALL
97 disposing(css::lang::EventObject const & rSource) override;
99 virtual void SAL_CALL
100 elementInserted(css::container::ContainerEvent const & rEvent) override;
102 virtual void SAL_CALL
103 elementRemoved(css::container::ContainerEvent const & rEvent) override;
105 virtual void SAL_CALL
106 elementReplaced(css::container::ContainerEvent const & rEvent) override;
108 private:
109 JavaVirtualMachine(JavaVirtualMachine &) = delete;
110 void operator =(const JavaVirtualMachine&) = delete;
112 virtual ~JavaVirtualMachine() override;
114 virtual void SAL_CALL disposing() override;
116 void registerConfigChangesListener();
118 void setINetSettingsInVM(bool set_reset);
120 void setUpUnoVirtualMachine(JNIEnv * environment);
122 void handleJniException(JNIEnv * environment);
124 css::uno::Reference< css::uno::XComponentContext >
125 m_xContext;
127 // the following are controlled by BaseMutex::m_aMutex:
128 bool m_bDisposed;
129 rtl::Reference< jvmaccess::VirtualMachine > m_xVirtualMachine;
130 rtl::Reference< jvmaccess::UnoVirtualMachine > m_xUnoVirtualMachine;
131 JavaVM * m_pJavaVm;
132 // If the first creation of Java failed and this flag is set then the
133 // next call to getJavaVM throws a RuntimException. This is useful when
134 // the second attempt to create Java might cause a crash.
135 css::uno::Reference< css::container::XContainer >
136 m_xInetConfiguration;
137 css::uno::Reference< css::container::XContainer >
138 m_xJavaConfiguration; // for Java settings
140 osl::ThreadData m_aAttachGuards;
145 #endif // INCLUDED_STOC_SOURCE_JAVAVM_JAVAVM_HXX
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */