commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: jakarta-commons-sandbox/daemon/src/native/nt/procrun procgui.c
Date Wed, 07 May 2003 15:15:04 GMT
mturk       2003/05/07 08:15:03

  Modified:    daemon/src/native/nt/procrun procgui.c
  Log:
  Added mutex for Single Instance mode. Perhaps one day
  I'll make that customizable, so that same instance can be
  started multiple times.
  
  Revision  Changes    Path
  1.20      +26 -4     jakarta-commons-sandbox/daemon/src/native/nt/procrun/procgui.c
  
  Index: procgui.c
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/nt/procrun/procgui.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- procgui.c	5 May 2003 17:14:21 -0000	1.19
  +++ procgui.c	7 May 2003 15:15:03 -0000	1.20
  @@ -671,7 +671,7 @@
   
           break;
           case WM_INITDIALOG:
  -            SetDlgItemText(hdlg, RC_TXT_JVM, g_env->m->java.display);
  +            SetDlgItemText(hdlg, RC_TXT_JVM, g_env->m->java.display);
               sprintf(txt, "%s;%s;%s", g_env->m->java.start_class,
                                        g_env->m->java.start_method,
                                        g_env->m->java.start_param);
  @@ -679,7 +679,7 @@
               sprintf(txt, "%s;%s;%s", g_env->m->java.stop_class,
                                        g_env->m->java.stop_method,
                                        g_env->m->java.stop_param);
  -            SetDlgItemText(hdlg, RC_TXT_EC, txt);
  +            SetDlgItemText(hdlg, RC_TXT_EC, txt);
               if (g_env->m->java.display &&
                   !strcmp(g_env->m->java.display, "auto"))
                   CheckDlgButton(hdlg, RC_CHK_JVM, BST_CHECKED);
  @@ -734,9 +734,9 @@
                           if (*c == '\n')
                               b[i++] = '#';
                           else if (*c != '\r')
  -                            b[i++] = *c;
  +                            b[i++] = *c;
                           ++c;
  -                    }
  +                    }
                       b[i] = '\0';
                       argv[argc++] = "--" PROCRUN_PARAMS_JVM_OPTS;
                       argv[argc++] = &b[0];
  @@ -1030,13 +1030,19 @@
   {
       DWORD rv = 0;
       MSG   msg;
  +    /* single instance mutex */
  +    HANDLE mutex;
  +
       procrun_t *env = ac_env = (procrun_t *)param;
       char cname[MAX_LOADSTRING];
  +    char cmutex[MAX_PATH];
   
       if (!param || !env->m->service.name)
           return -1;
       strcpy(cname, env->m->service.name);
       strcat(cname, "_CLASS");
  +    strcpy(cmutex, env->m->service.name);
  +    strcat(cmutex, "_MUTEX");
       if (env->m->service.description)
           ac_cmdline = env->m->service.description;
       else
  @@ -1045,6 +1051,20 @@
           ac_cmdname = env->m->service.display;
       else
           ac_cmdname = env->m->service.name;
  +    
  +    mutex = CreateMutex(NULL, FALSE, cmutex);
  +    if ((mutex == NULL) || (GetLastError() == ERROR_ALREADY_EXISTS)) {
  +        char msg[2048];
  +        sprintf(msg, "Starting: %s\nApplication is already running",
  +                env->m->service.name);
  +        MessageBox(NULL, msg, "Second instance", 
  +                   MB_OK | MB_ICONEXCLAMATION | MB_SYSTEMMODAL);
  +        if (mutex)
  +            CloseHandle(mutex);
  +        SetEvent(env->m->events[0]);
  +        return 0;
  +    }
  +
       /* TODO: make that customizable */
       if (ac_use_try)
           ac_use_splash = 1;
  @@ -1060,6 +1080,8 @@
               DispatchMessage(&msg);
           }    
       }
  +    if (mutex)
  +        CloseHandle(mutex);
       ac_main_hwnd = NULL;
       SetEvent(env->m->events[0]);
       return rv;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message