1 /* 2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef LIBRARY_H 27 #define LIBRARY_H 28 29 #include "PlatformDefs.h" 30 //#include "Platform.h" 31 #include "OrderedMap.h" 32 33 #include "jni.h" 34 #include <stdio.h> 35 #include <stdlib.h> 36 #include <memory.h> 37 #include <string> 38 #include <map> 39 #include <list> 40 #include <vector> 41 #include <fstream> 42 43 using namespace std; 44 45 // Private typedef for function pointer casting 46 #define LAUNCH_FUNC "JLI_Launch" 47 48 typedef int (JNICALL *JAVA_CREATE)(int argc, char ** argv, 49 int jargc, const char** jargv, 50 int appclassc, const char** appclassv, 51 const char* fullversion, 52 const char* dotversion, 53 const char* pname, 54 const char* lname, 55 jboolean javaargs, 56 jboolean cpwildcard, 57 jboolean javaw, 58 jint ergo); 59 60 class Library { 61 private: 62 std::vector<TString> *FDependentLibraryNames; 63 std::vector<Library*> *FDependenciesLibraries; 64 Module FModule; 65 std::string fname; 66 67 void Initialize(); 68 void InitializeDependencies(); 69 void LoadDependencies(); 70 void UnloadDependencies(); 71 72 public: 73 void* GetProcAddress(const std::string& MethodName) const; 74 75 public: 76 Library(); 77 Library(const TString &FileName); 78 ~Library(); 79 80 bool Load(const TString &FileName); 81 bool Unload(); 82 83 const std::string& GetName() const { 84 return fname; 85 } 86 87 void AddDependency(const TString &FileName); 88 void AddDependencies(const std::vector<TString> &Dependencies); 89 }; 90 91 class JavaLibrary : public Library { 92 JAVA_CREATE FCreateProc; 93 JavaLibrary(const TString &FileName); 94 public: 95 JavaLibrary(); 96 bool JavaVMCreate(size_t argc, char *argv[]); 97 }; 98 99 #endif // LIBRARY_H 100