1*1c4c525fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*1c4c525fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*1c4c525fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*1c4c525fSAndrew Rist * distributed with this work for additional information 6*1c4c525fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*1c4c525fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*1c4c525fSAndrew Rist * "License"); you may not use this file except in compliance 9*1c4c525fSAndrew Rist * with the License. You may obtain a copy of the License at 10*1c4c525fSAndrew Rist * 11*1c4c525fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*1c4c525fSAndrew Rist * 13*1c4c525fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*1c4c525fSAndrew Rist * software distributed under the License is distributed on an 15*1c4c525fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*1c4c525fSAndrew Rist * KIND, either express or implied. See the License for the 17*1c4c525fSAndrew Rist * specific language governing permissions and limitations 18*1c4c525fSAndrew Rist * under the License. 19*1c4c525fSAndrew Rist * 20*1c4c525fSAndrew Rist *************************************************************/ 21*1c4c525fSAndrew Rist 22*1c4c525fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #if !defined INCLUDED_STOC_JAVAVM_JAVAVM_HXX 25cdf0e10cSrcweir #define INCLUDED_STOC_JAVAVM_JAVAVM_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "jvmargs.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "com/sun/star/container/XContainerListener.hpp" 30cdf0e10cSrcweir #include "com/sun/star/lang/XInitialization.hpp" 31cdf0e10cSrcweir #include "com/sun/star/java/XJavaThreadRegister_11.hpp" 32cdf0e10cSrcweir #include "com/sun/star/java/XJavaVM.hpp" 33cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp" 34cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx" 35cdf0e10cSrcweir #include "cppuhelper/compbase5.hxx" 36cdf0e10cSrcweir #include "osl/thread.hxx" 37cdf0e10cSrcweir #include "rtl/ref.hxx" 38cdf0e10cSrcweir #include <osl/mutex.hxx> 39cdf0e10cSrcweir #include <rtl/ustring.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir namespace com { namespace sun { namespace star { 42cdf0e10cSrcweir namespace container { class XContainer; } 43cdf0e10cSrcweir namespace uno { class XComponentContext; } 44cdf0e10cSrcweir } } } 45cdf0e10cSrcweir namespace jvmaccess { 46cdf0e10cSrcweir class UnoVirtualMachine; 47cdf0e10cSrcweir class VirtualMachine; 48cdf0e10cSrcweir } 49cdf0e10cSrcweir 50cdf0e10cSrcweir namespace stoc_javavm { 51cdf0e10cSrcweir 52cdf0e10cSrcweir bool configureJava(const com::sun::star::uno::Reference< 53cdf0e10cSrcweir com::sun::star::uno::XComponentContext>& xContext); 54cdf0e10cSrcweir // The MS compiler needs a typedef here, so the JavaVirtualMachine ctor can call 55cdf0e10cSrcweir // its base class ctor: 56cdf0e10cSrcweir typedef 57cdf0e10cSrcweir cppu::WeakComponentImplHelper5< com::sun::star::lang::XInitialization, 58cdf0e10cSrcweir com::sun::star::lang::XServiceInfo, 59cdf0e10cSrcweir com::sun::star::java::XJavaVM, 60cdf0e10cSrcweir com::sun::star::java::XJavaThreadRegister_11, 61cdf0e10cSrcweir com::sun::star::container::XContainerListener > 62cdf0e10cSrcweir JavaVirtualMachine_Impl; 63cdf0e10cSrcweir 64cdf0e10cSrcweir class JavaVirtualMachine: private osl::Mutex, public JavaVirtualMachine_Impl 65cdf0e10cSrcweir { 66cdf0e10cSrcweir public: 67cdf0e10cSrcweir explicit JavaVirtualMachine( 68cdf0e10cSrcweir com::sun::star::uno::Reference< 69cdf0e10cSrcweir com::sun::star::uno::XComponentContext > const & rContext); 70cdf0e10cSrcweir 71cdf0e10cSrcweir // XInitialization 72cdf0e10cSrcweir virtual void SAL_CALL 73cdf0e10cSrcweir initialize(com::sun::star::uno::Sequence< com::sun::star::uno::Any > const & 74cdf0e10cSrcweir rArguments) 75cdf0e10cSrcweir throw (com::sun::star::uno::Exception); 76cdf0e10cSrcweir 77cdf0e10cSrcweir // XServiceInfo 78cdf0e10cSrcweir virtual rtl::OUString SAL_CALL getImplementationName() 79cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 80cdf0e10cSrcweir 81cdf0e10cSrcweir virtual sal_Bool SAL_CALL 82cdf0e10cSrcweir supportsService(rtl::OUString const & rServiceName) 83cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 84cdf0e10cSrcweir 85cdf0e10cSrcweir virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL 86cdf0e10cSrcweir getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException); 87cdf0e10cSrcweir 88cdf0e10cSrcweir // XJavaVM 89cdf0e10cSrcweir virtual com::sun::star::uno::Any SAL_CALL 90cdf0e10cSrcweir getJavaVM(com::sun::star::uno::Sequence< sal_Int8 > const & rProcessId) 91cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 92cdf0e10cSrcweir 93cdf0e10cSrcweir virtual sal_Bool SAL_CALL isVMStarted() 94cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 95cdf0e10cSrcweir 96cdf0e10cSrcweir virtual sal_Bool SAL_CALL isVMEnabled() 97cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 98cdf0e10cSrcweir 99cdf0e10cSrcweir // XJavaThreadRegister_11 100cdf0e10cSrcweir virtual sal_Bool SAL_CALL isThreadAttached() 101cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 102cdf0e10cSrcweir 103cdf0e10cSrcweir virtual void SAL_CALL registerThread() 104cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 105cdf0e10cSrcweir 106cdf0e10cSrcweir virtual void SAL_CALL revokeThread() 107cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 108cdf0e10cSrcweir 109cdf0e10cSrcweir // XContainerListener 110cdf0e10cSrcweir virtual void SAL_CALL 111cdf0e10cSrcweir disposing(com::sun::star::lang::EventObject const & rSource) 112cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 113cdf0e10cSrcweir 114cdf0e10cSrcweir virtual void SAL_CALL 115cdf0e10cSrcweir elementInserted(com::sun::star::container::ContainerEvent const & rEvent) 116cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 117cdf0e10cSrcweir 118cdf0e10cSrcweir virtual void SAL_CALL 119cdf0e10cSrcweir elementRemoved(com::sun::star::container::ContainerEvent const & rEvent) 120cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 121cdf0e10cSrcweir 122cdf0e10cSrcweir virtual void SAL_CALL 123cdf0e10cSrcweir elementReplaced(com::sun::star::container::ContainerEvent const & rEvent) 124cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 125cdf0e10cSrcweir 126cdf0e10cSrcweir private: 127cdf0e10cSrcweir JavaVirtualMachine(JavaVirtualMachine &); // not implemented 128cdf0e10cSrcweir void operator =(JavaVirtualMachine); // not implemented 129cdf0e10cSrcweir 130cdf0e10cSrcweir virtual ~JavaVirtualMachine(); 131cdf0e10cSrcweir 132cdf0e10cSrcweir virtual void SAL_CALL disposing(); 133cdf0e10cSrcweir 134cdf0e10cSrcweir JavaVM * createJavaVM(JVM const & jvm, JNIEnv ** pMainThreadEnv); 135cdf0e10cSrcweir // throws com::sun::star::uno::RuntimeException 136cdf0e10cSrcweir 137cdf0e10cSrcweir void registerConfigChangesListener(); 138cdf0e10cSrcweir 139cdf0e10cSrcweir void setINetSettingsInVM(bool set_reset); 140cdf0e10cSrcweir 141cdf0e10cSrcweir void setUpUnoVirtualMachine(JNIEnv * environment); 142cdf0e10cSrcweir 143cdf0e10cSrcweir void handleJniException(JNIEnv * environment); 144cdf0e10cSrcweir 145cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > 146cdf0e10cSrcweir m_xContext; 147cdf0e10cSrcweir 148cdf0e10cSrcweir // the following are controlled by the 'this' mutex: 149cdf0e10cSrcweir bool m_bDisposed; 150cdf0e10cSrcweir rtl::Reference< jvmaccess::VirtualMachine > m_xVirtualMachine; 151cdf0e10cSrcweir rtl::Reference< jvmaccess::UnoVirtualMachine > m_xUnoVirtualMachine; 152cdf0e10cSrcweir JavaVM * m_pJavaVm; 153cdf0e10cSrcweir // stored as an instance member for backwards compatibility in getJavaVM 154cdf0e10cSrcweir bool m_bDontCreateJvm; 155cdf0e10cSrcweir // If the first creation of Java failed and this flag is set then the 156cdf0e10cSrcweir // next call to getJavaVM throws a RuntimException. This is useful when 157cdf0e10cSrcweir // the second attempt to create Java might cause a crash. 158cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::container::XContainer > 159cdf0e10cSrcweir m_xInetConfiguration; 160cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::container::XContainer > 161cdf0e10cSrcweir m_xJavaConfiguration; // for Java settings 162cdf0e10cSrcweir 163cdf0e10cSrcweir osl::ThreadData m_aAttachGuards; 164cdf0e10cSrcweir }; 165cdf0e10cSrcweir 166cdf0e10cSrcweir } 167cdf0e10cSrcweir 168cdf0e10cSrcweir #endif // INCLUDED_STOC_JAVAVM_JAVAVM_HXX 169