| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | /* |
| 3 | * This file is part of the LibreOffice project. |
| 4 | * |
| 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/. |
| 8 | * |
| 9 | * This file incorporates work covered by the following license notice: |
| 10 | * |
| 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 . |
| 18 | */ |
| 19 | |
| 20 | #ifndef INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_VENDORBASE_HXX |
| 21 | #define INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_VENDORBASE_HXX |
| 22 | |
| 23 | #include <rtl/ustring.hxx> |
| 24 | #include <rtl/ref.hxx> |
| 25 | #include <osl/endian.h> |
| 26 | #include <salhelper/simplereferenceobject.hxx> |
| 27 | #include <vector> |
| 28 | |
| 29 | namespace jfw_plugin |
| 30 | { |
| 31 | //Used by subclasses of VendorBase to build paths to Java runtime |
| 32 | #if defined(JAVA_ARCH) |
| 33 | #define JFW_PLUGIN_ARCH JAVA_ARCH |
| 34 | #elif defined SPARC64 |
| 35 | #define JFW_PLUGIN_ARCH "sparcv9" |
| 36 | #elif defined SPARC |
| 37 | #define JFW_PLUGIN_ARCH "sparc" |
| 38 | #elif defined X86_64 |
| 39 | #define JFW_PLUGIN_ARCH "amd64" |
| 40 | #elif defined ARM64 |
| 41 | #define JFW_PLUGIN_ARCH "arm64" |
| 42 | #elif defined INTEL |
| 43 | #define JFW_PLUGIN_ARCH "i386" |
| 44 | #elif defined POWERPC64 |
| 45 | #define JFW_PLUGIN_ARCH "ppc64" |
| 46 | #elif defined POWERPC |
| 47 | #define JFW_PLUGIN_ARCH "ppc" |
| 48 | #elif defined MIPS |
| 49 | #ifdef OSL_BIGENDIAN |
| 50 | #define JFW_PLUGIN_ARCH "mips" |
| 51 | #else |
| 52 | /* FIXME: do JDKs have some JDK-specific define? This is for |
| 53 | OpenJDK at least, but probably not true for Lemotes JDK */ |
| 54 | #define JFW_PLUGIN_ARCH "mipsel" |
| 55 | #endif |
| 56 | #elif defined MIPS64 |
| 57 | #ifdef OSL_BIGENDIAN |
| 58 | #define JFW_PLUGIN_ARCH "mips64" |
| 59 | #else |
| 60 | #define JFW_PLUGIN_ARCH "mips64el" |
| 61 | #endif |
| 62 | #elif defined RISCV64 |
| 63 | #define JFW_PLUGIN_ARCH "riscv64" |
| 64 | #elif defined S390X |
| 65 | #define JFW_PLUGIN_ARCH "s390x" |
| 66 | #elif defined ARM |
| 67 | #define JFW_PLUGIN_ARCH "arm" |
| 68 | #elif defined IA64 |
| 69 | #define JFW_PLUGIN_ARCH "ia64" |
| 70 | #elif defined M68K |
| 71 | #define JFW_PLUGIN_ARCH "m68k" |
| 72 | #elif defined HPPA |
| 73 | #define JFW_PLUGIN_ARCH "parisc" |
| 74 | #elif defined AXP |
| 75 | #define JFW_PLUGIN_ARCH "alpha" |
| 76 | #elif defined AARCH64 |
| 77 | #define JFW_PLUGIN_ARCH "aarch64" |
| 78 | #elif defined LOONGARCH64 |
| 79 | #define JFW_PLUGIN_ARCH "loongarch64" |
| 80 | #else // SPARC, INTEL, POWERPC, MIPS, MIPS64, ARM, IA64, M68K, HPPA, ALPHA, LOONGARCH64 |
| 81 | #error unknown platform |
| 82 | #endif // SPARC, INTEL, POWERPC, MIPS, MIPS64, ARM, IA64, M68K, HPPA, ALPHA, LOONGARCH64 |
| 83 | |
| 84 | class MalformedVersionException final : public std::exception |
| 85 | { |
| 86 | public: |
| 87 | virtual ~MalformedVersionException() override; |
| 88 | }; |
| 89 | |
| 90 | class VendorBase : public salhelper::SimpleReferenceObject |
| 91 | { |
| 92 | public: |
| 93 | VendorBase(); |
| 94 | /* static char const* const * getJavaExePaths(int* size); |
| 95 | |
| 96 | returns relative paths to the java executable as |
| 97 | file URLs. |
| 98 | |
| 99 | For example "bin/java.exe". You need |
| 100 | to implement this function in a derived class, if |
| 101 | the paths differ. this implementation provides for |
| 102 | Windows "bin/java.exe" and for Unix "bin/java". |
| 103 | The paths are relative file URLs. That is, they always |
| 104 | contain '/' even on windows. The paths are relative |
| 105 | to the installation directory of a JRE. |
| 106 | |
| 107 | |
| 108 | The signature of this function must correspond to |
| 109 | getJavaExePaths_func. |
| 110 | */ |
| 111 | |
| 112 | /* static rtl::Reference<VendorBase> createInstance(); |
| 113 | |
| 114 | creates an instance of this class. MUST be overridden |
| 115 | in a derived class. |
| 116 | #################################################### |
| 117 | OVERRIDE in derived class |
| 118 | ################################################### |
| 119 | @param |
| 120 | Key - value pairs of the system properties of the JRE. |
| 121 | */ |
| 122 | |
| 123 | const OUString& getVendor() const; |
| 124 | const OUString& getVersion() const; |
| 125 | const OUString& getHome() const; |
| 126 | const OUString& getRuntimeLibrary() const; |
| 127 | const OUString& getLibraryPath() const; |
| 128 | bool isValidArch() const; |
| 129 | /* determines if prior to running java something has to be done, |
| 130 | like setting the LD_LIBRARY_PATH. This implementation checks |
| 131 | if an LD_LIBRARY_PATH (getLD_LIBRARY_PATH) needs to be set and |
| 132 | if so, needsRestart returns true. |
| 133 | */ |
| 134 | bool needsRestart() const; |
| 135 | |
| 136 | /* compares versions of this vendor. MUST be overridden |
| 137 | in a derived class. |
| 138 | #################################################### |
| 139 | OVERRIDE in derived class |
| 140 | ################################################### |
| 141 | @return |
| 142 | 0 this.version == sSecond |
| 143 | 1 this.version > sSecond |
| 144 | -1 this.version < sSEcond |
| 145 | |
| 146 | @throw |
| 147 | MalformedVersionException if the version string was not recognized. |
| 148 | */ |
| 149 | virtual int compareVersions(const OUString& sSecond) const = 0; |
| 150 | |
| 151 | protected: |
| 152 | /* called automatically on the instance created by createInstance. |
| 153 | |
| 154 | @return |
| 155 | true - the object could completely initialize. |
| 156 | false - the object could not completely initialize. In this case |
| 157 | it will be discarded by the caller. |
| 158 | */ |
| 159 | bool initialize(const std::vector<std::pair<OUString, OUString>>& props); |
| 160 | |
| 161 | /* returns relative file URLs to the runtime library. |
| 162 | For example "/bin/client/jvm.dll" |
| 163 | */ |
| 164 | virtual char const* const* getRuntimePaths(int* size) = 0; |
| 165 | |
| 166 | virtual char const* const* getLibraryPaths(int* size) = 0; |
| 167 | |
| 168 | typedef rtl::Reference<VendorBase> (*createInstance_func)(); |
| 169 | friend rtl::Reference<VendorBase> |
| 170 | createInstance(createInstance_func pFunc, |
| 171 | const std::vector<std::pair<OUString, OUString>>& properties); |
| 172 | |
| 173 | private: |
| 174 | OUString m_sVendor; |
| 175 | OUString m_sVersion; |
| 176 | OUString m_sHome; |
| 177 | OUString m_sRuntimeLibrary; |
| 178 | OUString m_sLD_LIBRARY_PATH; |
| 179 | OUString m_sArch; |
| 180 | }; |
| 181 | } |
| 182 | |
| 183 | #endif |
| 184 | |
| 185 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |