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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
  * All rights reserved. Use is subject to license terms.
  *
  * This file is available and licensed under the following license:
  *
  * Redistribution and use in source and binary forms, with or without

@@ -42,10 +42,47 @@
 #include "JavaUserPreferences.h"
 
 #include <Windows.h>
 
 
+// the class is used to create and detect single instance of user application
+class SingleInstance {
+private:
+    const int BUF_SIZE;
+
+    DWORD  _lastError;
+    HANDLE _mutex;
+    TString _name;
+    TString _sharedMemoryName;
+    HANDLE _hMapFile;
+    LPCTSTR _pBuf;
+
+    SingleInstance(): BUF_SIZE(0) {}
+
+    SingleInstance(TString& name_);
+
+public:
+    static SingleInstance* getInstance(TString& name) {
+        static SingleInstance* result = NULL;
+        
+        if (result == NULL) {
+            result = new SingleInstance(name);
+        }
+        
+        return result;
+    }
+
+    ~SingleInstance();
+
+    bool IsAnotherInstanceRunning() {
+        return (ERROR_ALREADY_EXISTS == _lastError);
+    }
+
+    bool writePid(DWORD pid);
+    DWORD readPid();
+};
+
 #pragma warning( push )
 #pragma warning( disable : 4250 ) // C4250 - 'class1' : inherits 'class2::member'
 class WindowsPlatform : virtual public Platform, GenericPlatform {
 private:
     DWORD FMainThread;

@@ -78,11 +115,13 @@
     virtual std::vector<TString> GetLibraryImports(const TString FileName);
     virtual std::vector<TString> FilterOutRuntimeDependenciesForPlatform(std::vector<TString> Imports);
 
     virtual Process* CreateProcess();
 
+    virtual void reactivateAnotherInstance();
     virtual bool IsMainThread();
+    virtual bool CheckForSingleInstance(TString Name);
     virtual TPlatformNumber GetMemorySize();
 
 #ifdef DEBUG
     virtual bool IsNativeDebuggerPresent();
     virtual int GetProcessID();