cid#1640468 Dereference after null check
[LibreOffice.git] / stoc / source / javavm / javavm.hxx
blobb4f79d1f9f34b81c9deea14d5fbd49f0c33c79b3
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 #if defined __clang__
24 #pragma clang diagnostic push
25 #pragma clang diagnostic ignored "-Wunknown-attributes"
26 #endif
27 #include <jni.h>
28 #if defined __clang__
29 #pragma clang diagnostic pop
30 #endif
32 #include <com/sun/star/container/XContainerListener.hpp>
33 #include <com/sun/star/lang/XInitialization.hpp>
34 #include <com/sun/star/java/XJavaThreadRegister_11.hpp>
35 #include <com/sun/star/java/XJavaVM.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/uno/Reference.hxx>
38 #include <cppuhelper/basemutex.hxx>
39 #include <cppuhelper/compbase.hxx>
40 #include <osl/thread.hxx>
41 #include <rtl/ref.hxx>
42 #include <rtl/ustring.hxx>
44 namespace com::sun::star {
45 namespace container { class XContainer; }
46 namespace uno { class XComponentContext; }
48 namespace jvmaccess {
49 class UnoVirtualMachine;
50 class VirtualMachine;
53 namespace stoc_javavm {
55 class JavaVirtualMachine:
56 private cppu::BaseMutex,
57 public cppu::WeakComponentImplHelper<
58 css::lang::XInitialization, css::lang::XServiceInfo, css::java::XJavaVM,
59 css::java::XJavaThreadRegister_11, css::container::XContainerListener>
61 public:
62 explicit JavaVirtualMachine(
63 css::uno::Reference<
64 css::uno::XComponentContext > xContext);
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 const &) = 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: */