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 
  47 #if defined(_WIN32) && !defined(_WIN64)
  48 #define LAUNCH_FUNC "_JLI_Launch@56"
  49 #else
  50 #define LAUNCH_FUNC "JLI_Launch"
  51 #endif
  52 
  53 
  54 typedef int (JNICALL *JAVA_CREATE)(int argc, char ** argv,
  55         int jargc, const char** jargv,
  56         int appclassc, const char** appclassv,
  57         const char* fullversion,
  58         const char* dotversion,
  59         const char* pname,
  60         const char* lname,
  61         jboolean javaargs,
  62         jboolean cpwildcard,
  63         jboolean javaw,
  64         jint ergo);
  65 
  66 class Library {
  67 private:
  68     std::vector<TString> *FDependentLibraryNames;
  69     std::vector<Library*> *FDependenciesLibraries;
  70     Module FModule;
  71     std::string fname;
  72 
  73     void Initialize();
  74     void InitializeDependencies();
  75     void LoadDependencies();
  76     void UnloadDependencies();
  77 
  78 public:
  79     void* GetProcAddress(const std::string& MethodName) const;
  80 
  81 public:
  82     Library();
  83     Library(const TString &FileName);
  84     ~Library();
  85 
  86     bool Load(const TString &FileName);
  87     bool Unload();
  88 
  89     const std::string& GetName() const {
  90         return fname;
  91     }
  92 
  93     void AddDependency(const TString &FileName);
  94     void AddDependencies(const std::vector<TString> &Dependencies);
  95 };
  96 
  97 class JavaLibrary : public Library {
  98     JAVA_CREATE FCreateProc;
  99     JavaLibrary(const TString &FileName);
 100 public:
 101     JavaLibrary();
 102     bool JavaVMCreate(size_t argc, char *argv[]);
 103 };
 104 
 105 #endif // LIBRARY_H
 106