/[svn]/qsampler/trunk/src/qsamplerMainForm.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerMainForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1558 by capela, Thu Dec 6 09:35:33 2007 UTC revision 1626 by schoenebeck, Sat Jan 5 13:29:11 2008 UTC
# Line 471  bool MainForm::queryClose (void) Line 471  bool MainForm::queryClose (void)
471                          if (m_pDeviceForm)                          if (m_pDeviceForm)
472                                  m_pDeviceForm->close();                                  m_pDeviceForm->close();
473                          // Stop client and/or server, gracefully.                          // Stop client and/or server, gracefully.
474                          stopServer();                          stopServer(true /*interactive*/);
475                  }                  }
476          }          }
477    
# Line 2390  void MainForm::startServer (void) Line 2390  void MainForm::startServer (void)
2390                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
2391                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
2392                          tr("Could not start the LinuxSampler server.\n\n"                          tr("Could not start the LinuxSampler server.\n\n"
2393                          "Maybe it ss already started."),                          "Maybe it is already started."),
2394                          tr("Stop"), tr("Kill"), tr("Cancel"))) {                          tr("Stop"), tr("Kill"), tr("Cancel"))) {
2395                  case 0:                  case 0:
2396                          m_pServer->terminate();                          m_pServer->terminate();
# Line 2410  void MainForm::startServer (void) Line 2410  void MainForm::startServer (void)
2410                  return;                  return;
2411    
2412          // OK. Let's build the startup process...          // OK. Let's build the startup process...
2413          m_pServer = new QProcess(this);          m_pServer = new QProcess();
2414            bForceServerStop = true;
2415    
2416          // Setup stdout/stderr capture...          // Setup stdout/stderr capture...
2417  //      if (m_pOptions->bStdoutCapture) {  //      if (m_pOptions->bStdoutCapture) {
2418                  //m_pServer->setProcessChannelMode(  #if QT_VERSION >= 0x040200
2419                  //      QProcess::StandardOutput);                  m_pServer->setProcessChannelMode(QProcess::ForwardedChannels);
2420    #endif
2421                  QObject::connect(m_pServer,                  QObject::connect(m_pServer,
2422                          SIGNAL(readyReadStandardOutput()),                          SIGNAL(readyReadStandardOutput()),
2423                          SLOT(readServerStdout()));                          SLOT(readServerStdout()));
# Line 2426  void MainForm::startServer (void) Line 2428  void MainForm::startServer (void)
2428    
2429          // The unforgiveable signal communication...          // The unforgiveable signal communication...
2430          QObject::connect(m_pServer,          QObject::connect(m_pServer,
2431                  SIGNAL(finished(int,QProcess::ExitStatus)),                  SIGNAL(finished(int, QProcess::ExitStatus)),
2432                  SLOT(processServerExit()));                  SLOT(processServerExit()));
2433    
2434          // Build process arguments...          // Build process arguments...
# Line 2457  void MainForm::startServer (void) Line 2459  void MainForm::startServer (void)
2459    
2460    
2461  // Stop linuxsampler server...  // Stop linuxsampler server...
2462  void MainForm::stopServer (void)  void MainForm::stopServer (bool bInteractive)
2463  {  {
2464          // Stop client code.          // Stop client code.
2465          stopClient();          stopClient();
2466    
2467            if (m_pServer && bInteractive) {
2468                    if (QMessageBox::question(this,
2469                            QSAMPLER_TITLE ": " + tr("The backend's fate ..."),
2470                            tr("You have the option to keep the sampler backend (LinuxSampler)\n"
2471                            "running in the background. The sampler would continue to work\n"
2472                            "according to your current sampler session and you could alter the\n"
2473                            "sampler session at any time by relaunching QSampler.\n\n"
2474                            "Do you want LinuxSampler to stop or to keep running in\n"
2475                            "the background?"),
2476                            tr("Stop"), tr("Keep Running")) == 1)
2477                    {
2478                            bForceServerStop = false;
2479                    }
2480            }
2481    
2482          // And try to stop server.          // And try to stop server.
2483          if (m_pServer) {          if (m_pServer && bForceServerStop) {
2484                  appendMessages(tr("Server is stopping..."));                  appendMessages(tr("Server is stopping..."));
2485                  if (m_pServer->state() == QProcess::Running)                  if (m_pServer->state() == QProcess::Running) {
2486    #if defined(WIN32)
2487                            // Try harder...
2488                            m_pServer->kill();
2489    #else
2490                            // Try softly...
2491                          m_pServer->terminate();                          m_pServer->terminate();
2492          }  #endif
2493                    }
2494            }       // Do final processing anyway.
2495            else processServerExit();
2496    
2497          // Give it some time to terminate gracefully and stabilize...          // Give it some time to terminate gracefully and stabilize...
2498          QTime t;          QTime t;
2499          t.start();          t.start();
2500          while (t.elapsed() < QSAMPLER_TIMER_MSECS)          while (t.elapsed() < QSAMPLER_TIMER_MSECS)
2501                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
   
         // Do final processing anyway.  
         processServerExit();  
2502  }  }
2503    
2504    
# Line 2498  void MainForm::processServerExit (void) Line 2520  void MainForm::processServerExit (void)
2520          if (m_pMessages)          if (m_pMessages)
2521                  m_pMessages->flushStdoutBuffer();                  m_pMessages->flushStdoutBuffer();
2522    
2523          if (m_pServer) {          if (m_pServer && bForceServerStop) {
2524                    if (m_pServer->state() != QProcess::NotRunning) {
2525                            appendMessages(tr("Server is being forced..."));
2526                            // Force final server shutdown...
2527                            m_pServer->kill();
2528                            // Give it some time to terminate gracefully and stabilize...
2529                            QTime t;
2530                            t.start();
2531                            while (t.elapsed() < QSAMPLER_TIMER_MSECS)
2532                                    QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2533                    }
2534                  // Force final server shutdown...                  // Force final server shutdown...
2535                  appendMessages(                  appendMessages(
2536                          tr("Server was stopped with exit status %1.")                          tr("Server was stopped with exit status %1.")
2537                          .arg(m_pServer->exitStatus()));                          .arg(m_pServer->exitStatus()));
                 m_pServer->terminate();  
                 if (!m_pServer->waitForFinished(2000))  
                         m_pServer->kill();  
                 // Destroy it.  
2538                  delete m_pServer;                  delete m_pServer;
2539                  m_pServer = NULL;                  m_pServer = NULL;
2540          }          }

Legend:
Removed from v.1558  
changed lines
  Added in v.1626

  ViewVC Help
Powered by ViewVC