modules/jdk.packager/src/main/native/library/common/Platform.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


 127 #define CONFIG_SECTION_APPLICATION                   _T("CONFIG_SECTION_APPLICATION")
 128 #define CONFIG_SECTION_JVMOPTIONS                    _T("CONFIG_SECTION_JVMOPTIONS")
 129 #define CONFIG_SECTION_JVMUSEROPTIONS                _T("CONFIG_SECTION_JVMUSEROPTIONS")
 130 #define CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS       _T("CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS")
 131 #define CONFIG_SECTION_APPCDSJVMOPTIONS              _T("CONFIG_SECTION_APPCDSJVMOPTIONS")
 132 #define CONFIG_SECTION_APPCDSGENERATECACHEJVMOPTIONS _T("CONFIG_SECTION_APPCDSGENERATECACHEJVMOPTIONS")
 133 #define CONFIG_SECTION_ARGOPTIONS                    _T("CONFIG_SECTION_ARGOPTIONS")
 134 
 135 // Config file keys.
 136 #define CONFIG_VERSION            _T("CONFIG_VERSION")
 137 #define CONFIG_MAINJAR_KEY        _T("CONFIG_MAINJAR_KEY")
 138 #define CONFIG_MAINMODULE_KEY     _T("CONFIG_MAINMODULE_KEY")
 139 #define CONFIG_MAINCLASSNAME_KEY  _T("CONFIG_MAINCLASSNAME_KEY")
 140 #define CONFIG_CLASSPATH_KEY      _T("CONFIG_CLASSPATH_KEY")
 141 #define CONFIG_MODULEPATH_KEY     _T("CONFIG_MODULEPATH_KEY")
 142 #define APP_NAME_KEY              _T("APP_NAME_KEY")
 143 #define CONFIG_SPLASH_KEY         _T("CONFIG_SPLASH_KEY")
 144 #define CONFIG_APP_ID_KEY         _T("CONFIG_APP_ID_KEY")
 145 #define CONFIG_APP_MEMORY         _T("CONFIG_APP_MEMORY")
 146 #define CONFIG_APP_DEBUG          _T("CONFIG_APP_DEBUG")

 147 
 148 #define JVM_RUNTIME_KEY           _T("JVM_RUNTIME_KEY")
 149 #define PACKAGER_APP_DATA_DIR     _T("CONFIG_APP_IDENTIFIER")
 150 
 151 
 152 
 153 typedef void* Module;
 154 typedef void* Procedure;
 155 
 156 
 157 template <typename ObjectType, typename ValueType, ValueType (ObjectType::*getter)(void), void (ObjectType::*setter)(ValueType)>
 158 class Property {
 159 private:
 160     ObjectType* FObject;
 161 
 162 public:
 163     Property() {
 164         FObject = NULL;
 165     }
 166 


 369         return _T("\r\n");
 370 #endif //WINDOWS
 371 #ifdef POSIX
 372         return _T("\n");
 373 #endif //POSIX
 374     }
 375 
 376     static StaticReadProperty<TString, &Environment::GetNewLine> NewLine;
 377 };
 378 
 379 
 380 enum DebugState {dsNone, dsNative, dsJava};
 381 enum MessageResponse {mrOK, mrCancel};
 382 enum AppCDSState {cdsUninitialized, cdsDisabled, cdsEnabled, cdsAuto, cdsGenCache};
 383 
 384 class Platform {
 385 private:
 386     AppCDSState FAppCDSState;
 387 
 388 protected:
 389     Platform(void) {
 390         FAppCDSState = cdsUninitialized;

 391     }
 392 
 393 public:
 394     AppCDSState GetAppCDSState() { return FAppCDSState; }
 395     void SetAppCDSState(AppCDSState Value) { FAppCDSState = Value; }

 396 
 397     static Platform& GetInstance();
 398 
 399     virtual ~Platform(void) {}
 400 
 401 public:
 402     virtual void ShowMessage(TString title, TString description) = 0;
 403     virtual void ShowMessage(TString description) = 0;
 404     virtual MessageResponse ShowResponseMessage(TString title, TString description) = 0;
 405 //    virtual MessageResponse ShowResponseMessage(TString description) = 0;
 406 
 407     virtual void SetCurrentDirectory(TString Value) = 0;
 408 
 409     // Caller must free result using delete[].
 410     virtual TCHAR* ConvertStringToFileSystemString(TCHAR* Source, bool &release) = 0;
 411 
 412     // Caller must free result using delete[].
 413     virtual TCHAR* ConvertFileSystemStringToString(TCHAR* Source, bool &release) = 0;
 414 
 415     // Returns:


 427     virtual TString GetBundledJVMLibraryFileName(TString RuntimePath) = 0;
 428     virtual TString GetSystemJVMLibraryFileName() = 0;
 429     virtual TString GetSystemJRE() = 0;
 430 
 431     // Caller must free result.
 432     virtual ISectionalPropertyContainer* GetConfigFile(TString FileName) = 0;
 433 
 434     virtual TString GetModuleFileName() = 0;
 435     virtual TString GetPackageRootDirectory() = 0;
 436 
 437     virtual Module LoadLibrary(TString FileName) = 0;
 438     virtual void FreeLibrary(Module Module) = 0;
 439     virtual Procedure GetProcAddress(Module Module, std::string MethodName) = 0;
 440     virtual std::vector<TString> GetLibraryImports(const TString FileName) = 0;
 441     virtual std::vector<TString> FilterOutRuntimeDependenciesForPlatform(std::vector<TString> Imports) = 0;
 442 
 443     // Caller must free result.
 444     virtual Process* CreateProcess() = 0;
 445 
 446     virtual bool IsMainThread() = 0;


 447 
 448     // Returns megabytes.
 449     virtual TPlatformNumber GetMemorySize() = 0;
 450 
 451     virtual std::map<TString, TString> GetKeys() = 0;
 452 
 453     virtual std::list<TString> LoadFromFile(TString FileName) = 0;
 454     virtual void SaveToFile(TString FileName, std::list<TString> Contents, bool ownerOnly) = 0;
 455 
 456 #ifdef DEBUG
 457     virtual DebugState GetDebugState() = 0;
 458     virtual int GetProcessID() = 0;
 459     virtual bool IsNativeDebuggerPresent() = 0;
 460 #endif //DEBUG
 461 };
 462 
 463 
 464 class Library {
 465 private:
 466     std::vector<TString> *FDependentLibraryNames;


   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


 127 #define CONFIG_SECTION_APPLICATION                   _T("CONFIG_SECTION_APPLICATION")
 128 #define CONFIG_SECTION_JVMOPTIONS                    _T("CONFIG_SECTION_JVMOPTIONS")
 129 #define CONFIG_SECTION_JVMUSEROPTIONS                _T("CONFIG_SECTION_JVMUSEROPTIONS")
 130 #define CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS       _T("CONFIG_SECTION_JVMUSEROVERRIDESOPTIONS")
 131 #define CONFIG_SECTION_APPCDSJVMOPTIONS              _T("CONFIG_SECTION_APPCDSJVMOPTIONS")
 132 #define CONFIG_SECTION_APPCDSGENERATECACHEJVMOPTIONS _T("CONFIG_SECTION_APPCDSGENERATECACHEJVMOPTIONS")
 133 #define CONFIG_SECTION_ARGOPTIONS                    _T("CONFIG_SECTION_ARGOPTIONS")
 134 
 135 // Config file keys.
 136 #define CONFIG_VERSION            _T("CONFIG_VERSION")
 137 #define CONFIG_MAINJAR_KEY        _T("CONFIG_MAINJAR_KEY")
 138 #define CONFIG_MAINMODULE_KEY     _T("CONFIG_MAINMODULE_KEY")
 139 #define CONFIG_MAINCLASSNAME_KEY  _T("CONFIG_MAINCLASSNAME_KEY")
 140 #define CONFIG_CLASSPATH_KEY      _T("CONFIG_CLASSPATH_KEY")
 141 #define CONFIG_MODULEPATH_KEY     _T("CONFIG_MODULEPATH_KEY")
 142 #define APP_NAME_KEY              _T("APP_NAME_KEY")
 143 #define CONFIG_SPLASH_KEY         _T("CONFIG_SPLASH_KEY")
 144 #define CONFIG_APP_ID_KEY         _T("CONFIG_APP_ID_KEY")
 145 #define CONFIG_APP_MEMORY         _T("CONFIG_APP_MEMORY")
 146 #define CONFIG_APP_DEBUG          _T("CONFIG_APP_DEBUG")
 147 #define CONFIG_APPLICATION_INSTANCE _T("CONFIG_APPLICATION_INSTANCE")
 148 
 149 #define JVM_RUNTIME_KEY           _T("JVM_RUNTIME_KEY")
 150 #define PACKAGER_APP_DATA_DIR     _T("CONFIG_APP_IDENTIFIER")
 151 
 152 
 153 
 154 typedef void* Module;
 155 typedef void* Procedure;
 156 
 157 
 158 template <typename ObjectType, typename ValueType, ValueType (ObjectType::*getter)(void), void (ObjectType::*setter)(ValueType)>
 159 class Property {
 160 private:
 161     ObjectType* FObject;
 162 
 163 public:
 164     Property() {
 165         FObject = NULL;
 166     }
 167 


 370         return _T("\r\n");
 371 #endif //WINDOWS
 372 #ifdef POSIX
 373         return _T("\n");
 374 #endif //POSIX
 375     }
 376 
 377     static StaticReadProperty<TString, &Environment::GetNewLine> NewLine;
 378 };
 379 
 380 
 381 enum DebugState {dsNone, dsNative, dsJava};
 382 enum MessageResponse {mrOK, mrCancel};
 383 enum AppCDSState {cdsUninitialized, cdsDisabled, cdsEnabled, cdsAuto, cdsGenCache};
 384 
 385 class Platform {
 386 private:
 387     AppCDSState FAppCDSState;
 388 
 389 protected:
 390     TProcessID singleInstanceProcessId;
 391 
 392     Platform(void): FAppCDSState(cdsUninitialized), singleInstanceProcessId(0) {
 393     }
 394 
 395 public:
 396     AppCDSState GetAppCDSState() { return FAppCDSState; }
 397     void SetAppCDSState(AppCDSState Value) { FAppCDSState = Value; }
 398     TProcessID GetSingleInstanceProcessId() { return singleInstanceProcessId; }
 399 
 400     static Platform& GetInstance();
 401 
 402     virtual ~Platform(void) {}
 403 
 404 public:
 405     virtual void ShowMessage(TString title, TString description) = 0;
 406     virtual void ShowMessage(TString description) = 0;
 407     virtual MessageResponse ShowResponseMessage(TString title, TString description) = 0;
 408 //    virtual MessageResponse ShowResponseMessage(TString description) = 0;
 409 
 410     virtual void SetCurrentDirectory(TString Value) = 0;
 411 
 412     // Caller must free result using delete[].
 413     virtual TCHAR* ConvertStringToFileSystemString(TCHAR* Source, bool &release) = 0;
 414 
 415     // Caller must free result using delete[].
 416     virtual TCHAR* ConvertFileSystemStringToString(TCHAR* Source, bool &release) = 0;
 417 
 418     // Returns:


 430     virtual TString GetBundledJVMLibraryFileName(TString RuntimePath) = 0;
 431     virtual TString GetSystemJVMLibraryFileName() = 0;
 432     virtual TString GetSystemJRE() = 0;
 433 
 434     // Caller must free result.
 435     virtual ISectionalPropertyContainer* GetConfigFile(TString FileName) = 0;
 436 
 437     virtual TString GetModuleFileName() = 0;
 438     virtual TString GetPackageRootDirectory() = 0;
 439 
 440     virtual Module LoadLibrary(TString FileName) = 0;
 441     virtual void FreeLibrary(Module Module) = 0;
 442     virtual Procedure GetProcAddress(Module Module, std::string MethodName) = 0;
 443     virtual std::vector<TString> GetLibraryImports(const TString FileName) = 0;
 444     virtual std::vector<TString> FilterOutRuntimeDependenciesForPlatform(std::vector<TString> Imports) = 0;
 445 
 446     // Caller must free result.
 447     virtual Process* CreateProcess() = 0;
 448 
 449     virtual bool IsMainThread() = 0;
 450     virtual bool CheckForSingleInstance(TString Name) = 0;
 451     virtual void reactivateAnotherInstance() = 0;
 452 
 453     // Returns megabytes.
 454     virtual TPlatformNumber GetMemorySize() = 0;
 455 
 456     virtual std::map<TString, TString> GetKeys() = 0;
 457 
 458     virtual std::list<TString> LoadFromFile(TString FileName) = 0;
 459     virtual void SaveToFile(TString FileName, std::list<TString> Contents, bool ownerOnly) = 0;
 460 
 461 #ifdef DEBUG
 462     virtual DebugState GetDebugState() = 0;
 463     virtual int GetProcessID() = 0;
 464     virtual bool IsNativeDebuggerPresent() = 0;
 465 #endif //DEBUG
 466 };
 467 
 468 
 469 class Library {
 470 private:
 471     std::vector<TString> *FDependentLibraryNames;