modules/jdk.packager/src/main/native/library/common/WindowsPlatform.h

Print this page


   1 /*
   2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates.
   3  * All rights reserved. Use is subject to license terms.
   4  *
   5  * This file is available and licensed under the following license:
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  *  - Redistributions of source code must retain the above copyright
  12  *    notice, this list of conditions and the following disclaimer.
  13  *  - Redistributions in binary form must reproduce the above copyright
  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR


  27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 
  33 
  34 #include "Platform.h"
  35 
  36 #ifdef WINDOWS
  37 
  38 #ifndef WINDOWSPLATFORM_H
  39 #define WINDOWSPLATFORM_H
  40 
  41 #include "GenericPlatform.h"
  42 #include "JavaUserPreferences.h"
  43 
  44 #include <Windows.h>
  45 
  46 





































  47 #pragma warning( push )
  48 #pragma warning( disable : 4250 ) // C4250 - 'class1' : inherits 'class2::member'
  49 class WindowsPlatform : virtual public Platform, GenericPlatform {
  50 private:
  51     DWORD FMainThread;
  52 
  53 public:
  54     WindowsPlatform(void);
  55     virtual ~WindowsPlatform(void);
  56 
  57     virtual TCHAR* ConvertStringToFileSystemString(TCHAR* Source, bool &release);
  58     virtual TCHAR* ConvertFileSystemStringToString(TCHAR* Source, bool &release);
  59 
  60     virtual void ShowMessage(TString title, TString description);
  61     virtual void ShowMessage(TString description);
  62     virtual MessageResponse ShowResponseMessage(TString title, TString description);
  63     //virtual MessageResponse ShowResponseMessage(TString description);
  64 
  65     virtual void SetCurrentDirectory(TString Value);
  66     virtual TString GetPackageRootDirectory();
  67     virtual TString GetAppDataDirectory();
  68     virtual TString GetBundledJVMLibraryFileName(TString RuntimePath);
  69     virtual TString GetSystemJVMLibraryFileName();
  70     virtual TString GetSystemJRE();
  71 
  72     virtual ISectionalPropertyContainer* GetConfigFile(TString FileName);
  73 
  74     virtual TString GetModuleFileName();
  75     virtual Module LoadLibrary(TString FileName);
  76     virtual void FreeLibrary(Module AModule);
  77     virtual Procedure GetProcAddress(Module AModule, std::string MethodName);
  78     virtual std::vector<TString> GetLibraryImports(const TString FileName);
  79     virtual std::vector<TString> FilterOutRuntimeDependenciesForPlatform(std::vector<TString> Imports);
  80 
  81     virtual Process* CreateProcess();
  82 

  83     virtual bool IsMainThread();

  84     virtual TPlatformNumber GetMemorySize();
  85 
  86 #ifdef DEBUG
  87     virtual bool IsNativeDebuggerPresent();
  88     virtual int GetProcessID();
  89 #endif //DEBUG
  90 };
  91 #pragma warning( pop ) // C4250
  92 
  93 
  94 class WindowsJavaUserPreferences : public JavaUserPreferences {
  95 public:
  96     WindowsJavaUserPreferences(void);
  97     ~WindowsJavaUserPreferences(void);
  98 
  99     virtual bool Load(TString Appid);
 100 };
 101 
 102 
 103 class FileHandle {


   1 /*
   2  * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
   3  * All rights reserved. Use is subject to license terms.
   4  *
   5  * This file is available and licensed under the following license:
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  *  - Redistributions of source code must retain the above copyright
  12  *    notice, this list of conditions and the following disclaimer.
  13  *  - Redistributions in binary form must reproduce the above copyright
  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR


  27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31  */
  32 
  33 
  34 #include "Platform.h"
  35 
  36 #ifdef WINDOWS
  37 
  38 #ifndef WINDOWSPLATFORM_H
  39 #define WINDOWSPLATFORM_H
  40 
  41 #include "GenericPlatform.h"
  42 #include "JavaUserPreferences.h"
  43 
  44 #include <Windows.h>
  45 
  46 
  47 // the class is used to create and detect single instance of user application
  48 class SingleInstance {
  49 private:
  50     const int BUF_SIZE;
  51 
  52     DWORD  _lastError;
  53     HANDLE _mutex;
  54     TString _name;
  55     TString _sharedMemoryName;
  56     HANDLE _hMapFile;
  57     LPCTSTR _pBuf;
  58 
  59     SingleInstance(): BUF_SIZE(0) {}
  60 
  61     SingleInstance(TString& name_);
  62 
  63 public:
  64     static SingleInstance* getInstance(TString& name) {
  65         static SingleInstance* result = NULL;
  66         
  67         if (result == NULL) {
  68             result = new SingleInstance(name);
  69         }
  70         
  71         return result;
  72     }
  73 
  74     ~SingleInstance();
  75 
  76     bool IsAnotherInstanceRunning() {
  77         return (ERROR_ALREADY_EXISTS == _lastError);
  78     }
  79 
  80     bool writePid(DWORD pid);
  81     DWORD readPid();
  82 };
  83 
  84 #pragma warning( push )
  85 #pragma warning( disable : 4250 ) // C4250 - 'class1' : inherits 'class2::member'
  86 class WindowsPlatform : virtual public Platform, GenericPlatform {
  87 private:
  88     DWORD FMainThread;
  89 
  90 public:
  91     WindowsPlatform(void);
  92     virtual ~WindowsPlatform(void);
  93 
  94     virtual TCHAR* ConvertStringToFileSystemString(TCHAR* Source, bool &release);
  95     virtual TCHAR* ConvertFileSystemStringToString(TCHAR* Source, bool &release);
  96 
  97     virtual void ShowMessage(TString title, TString description);
  98     virtual void ShowMessage(TString description);
  99     virtual MessageResponse ShowResponseMessage(TString title, TString description);
 100     //virtual MessageResponse ShowResponseMessage(TString description);
 101 
 102     virtual void SetCurrentDirectory(TString Value);
 103     virtual TString GetPackageRootDirectory();
 104     virtual TString GetAppDataDirectory();
 105     virtual TString GetBundledJVMLibraryFileName(TString RuntimePath);
 106     virtual TString GetSystemJVMLibraryFileName();
 107     virtual TString GetSystemJRE();
 108 
 109     virtual ISectionalPropertyContainer* GetConfigFile(TString FileName);
 110 
 111     virtual TString GetModuleFileName();
 112     virtual Module LoadLibrary(TString FileName);
 113     virtual void FreeLibrary(Module AModule);
 114     virtual Procedure GetProcAddress(Module AModule, std::string MethodName);
 115     virtual std::vector<TString> GetLibraryImports(const TString FileName);
 116     virtual std::vector<TString> FilterOutRuntimeDependenciesForPlatform(std::vector<TString> Imports);
 117 
 118     virtual Process* CreateProcess();
 119     
 120     virtual void reactivateAnotherInstance();
 121     virtual bool IsMainThread();
 122     virtual bool CheckForSingleInstance(TString Name);
 123     virtual TPlatformNumber GetMemorySize();
 124 
 125 #ifdef DEBUG
 126     virtual bool IsNativeDebuggerPresent();
 127     virtual int GetProcessID();
 128 #endif //DEBUG
 129 };
 130 #pragma warning( pop ) // C4250
 131 
 132 
 133 class WindowsJavaUserPreferences : public JavaUserPreferences {
 134 public:
 135     WindowsJavaUserPreferences(void);
 136     ~WindowsJavaUserPreferences(void);
 137 
 138     virtual bool Load(TString Appid);
 139 };
 140 
 141 
 142 class FileHandle {