示例#1
0
文件: WServer.C 项目: bvanhauwaert/wt
int WServer::waitForShutdown(const char *restartWatchFile)
{
#if !defined(WIN32)
  if (!CatchSignals) {
    for(;;)
      sleep(0x1<<16);
  }
#endif // WIN32

#ifdef WT_THREADED

#if !defined(_WIN32)
  sigset_t wait_mask;
  sigemptyset(&wait_mask);

  sigaddset(&wait_mask, SIGHUP);
  sigaddset(&wait_mask, SIGINT);
  sigaddset(&wait_mask, SIGQUIT);
  sigaddset(&wait_mask, SIGTERM);
  pthread_sigmask(SIG_BLOCK, &wait_mask, 0);

  for (;;) {
    int sig;
    sigwait(&wait_mask, &sig);

    if (sig != -1) {
      if (sig == SIGHUP) {
	if (instance())
	  instance()->configuration().rereadConfiguration();
      } else
	return sig;
    }
  }

#else  // WIN32

  boost::mutex::scoped_lock terminationLock(terminationMutex);
  SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
  while (!terminationRequested)
    terminationCondition.wait(terminationLock);
  SetConsoleCtrlHandler(console_ctrl_handler, FALSE);
  return 0;

#endif // WIN32
#else
  return 0;
#endif // WT_THREADED
}
      void ExportScanner::start() {
        
        db::HiveDb db=org::esb::hive::DatabaseService::getDatabase();
        while (_run) {
          {
            try {
              std::vector<db::Job> completed_jobs = litesql::select<db::Job > (db, db::Job::Status == "completed").all();
              std::vector<db::Job>::iterator job_it = completed_jobs.begin();
              for (; job_it != completed_jobs.end(); job_it++) {
                db::MediaFile mfile = (*job_it).outputfile().get().one();
                try {
                  db::JobLog log((*job_it).getDatabase());
                  std::string message = "exporting file";
                  message += mfile.path + "/" + mfile.filename;
                  log.message = message;
                  log.update();

                  (*job_it).joblog().link(log);

                  (*job_it).status = "exporting";
                  (*job_it).update();
                  FileExporter::exportFile(mfile);
                } catch (boost::filesystem::filesystem_error & e) {
                  db::JobLog log((*job_it).getDatabase());
                  std::string message = "failed to write the outputfile to ";
                  message += mfile.path + "/" + mfile.filename;
                  message += ": ";
                  message += e.what();
                  log.message = message;
                  log.update();

                  (*job_it).joblog().link(log);

                  (*job_it).status = "failed";
                  (*job_it).update();
                }
              }
            } catch (litesql::NotFound ex) {
              LOGDEBUG("no new File to export Found");
              org::esb::lang::Thread::sleep2(1000);
            }
          }
          org::esb::lang::Thread::sleep2(5000);
        }
        boost::mutex::scoped_lock terminationLock(terminationMutex);
        termination_wait.notify_all();
      }
示例#3
0
文件: WServer.C 项目: bvanhauwaert/wt
BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
{
  switch (ctrl_type)
  {
  case CTRL_C_EVENT:
  case CTRL_BREAK_EVENT:
  case CTRL_CLOSE_EVENT:
  case CTRL_SHUTDOWN_EVENT:
    {
      boost::mutex::scoped_lock terminationLock(terminationMutex);
      terminationRequested = true;
      terminationCondition.notify_all(); // should be just 1
      return TRUE;
    }
  default:
    return FALSE;
  }
}
 void ExportScanner::onMessage(org::esb::signal::Message & msg) {
   if (msg.getProperty("exportscanner") == "start") {
     LOGDEBUG("Start Request for the ExportScanner");
     _run = true;
     boost::thread t(boost::bind(&ExportScanner::start, this));
     boost::thread(boost::bind(&ExportScanner::restart_failed_exports, this));
     LOGDEBUG("ExportScanner started");
   } else
     if (msg.getProperty("exportscanner") == "stop") {
     LOGDEBUG("Export Scanner stop request received");
     if (_run) {
       _run = false;
       boost::mutex::scoped_lock terminationLock(terminationMutex);
       termination_wait.wait(terminationLock);
     }
     LOGDEBUG("Export Scanner stopped");
   }
 }
示例#5
0
文件: WServer.C 项目: mickythump/wt
int WServer::waitForShutdown(const char *restartWatchFile)
{
#if !defined(WT_WIN32)
    if (!CatchSignals) {
        for(;;)
            sleep(0x1<<16);
    }
#endif // WIN32

#ifdef WT_THREADED

#if !defined(WT_WIN32)
    sigset_t wait_mask;
    sigemptyset(&wait_mask);

    // Block the signals which interest us
    sigaddset(&wait_mask, SIGHUP);
    sigaddset(&wait_mask, SIGINT);
    sigaddset(&wait_mask, SIGQUIT);
    sigaddset(&wait_mask, SIGTERM);
    pthread_sigmask(SIG_BLOCK, &wait_mask, 0);

    for (;;) {
        int rc, sig= -1;

        // Wait for a signal to be raised
        rc= sigwait(&wait_mask, &sig);

        // branch based on return value of sigwait().
        switch (rc) {
        case 0: // rc indicates one of the blocked signals was raised.

            // branch based on the signal which was raised.
            switch(sig) {
            case SIGHUP: // SIGHUP means re-read the configuration.
                if (instance())
                    instance()->configuration().rereadConfiguration();
                break;

            default: // Any other blocked signal means time to quit.
                return sig;
            }

            break;
        case EINTR:
            // rc indicates an unblocked signal was raised, so we'll go
            // around again.

            break;
        default:
            // report the error and return an obviously illegitimate signal value.
            throw WServer::Exception(std::string("sigwait() error: ")
                                     + strerror(rc));
            return -1;
        }
    }

#else  // WIN32

    boost::mutex::scoped_lock terminationLock(terminationMutex);
    SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
    while (!terminationRequested)
        terminationCondition.wait(terminationLock);
    SetConsoleCtrlHandler(console_ctrl_handler, FALSE);
    return 0;

#endif // WIN32
#else
    return 0;
#endif // WT_THREADED
}
示例#6
0
文件: WServer.C 项目: mickythump/wt
void WServer::terminate()
{
    boost::mutex::scoped_lock terminationLock(terminationMutex);
    terminationRequested = true;
    terminationCondition.notify_all(); // should be just 1
}
      void HiveClientAudio::process() {
        //int pCount = 0;
        while (!_toHalt) {
          if (!_sock->isConnected()) {
            connect();
          } else {
            while (!_toHalt) {
              char * text = const_cast<char*> ("get audio_process_unit");
              org::esb::hive::job::ProcessUnit * unit = new org::esb::hive::job::ProcessUnit();
              try {
                _sock->getOutputStream()->write(text, strlen(text));
                //LOGDEBUG("sended command");
                _ois->readObject(*unit);
                //LOGDEBUG("pu received");
              } catch (exception & ex) {
                LOGERROR("Connection to Server lost, while waiting for audio process unit!!!" << ex.what());
                _sock->close();
              }
              if (unit->_input_packets.size() == 0) {
                //                delete _dec;
                //                delete _enc;
                delete unit;
                break;
              }
              if (_swap_codec_list.find(unit->_source_stream) == _swap_codec_list.end()) {
                _swap_codec_list[unit->_source_stream] = false;
              }

              if (_swap_codec_list[unit->_source_stream]) {
                unit->_decoder = _decoder_list[unit->_source_stream];
                unit->_encoder = _encoder_list[unit->_target_stream];
                unit->_converter = _converter_list[unit->_target_stream];
              }
              _swap_codec_list[unit->_source_stream] = true;

              unit->process();

              if (_swap_codec_list[unit->_source_stream]) {
                _decoder_list[unit->_source_stream] = unit->_decoder;
                _encoder_list[unit->_target_stream] = unit->_encoder;
                _converter_list[unit->_target_stream] = unit->_converter;
              }

              /**
               * clear the input packets, there are no more nedded
               * they only consumes Network bandwidth and cpu on the server
               */
              //unit->_input_packets.clear();

              char * text_out = const_cast<char*> ("put audio_process_unit");
              try {
                _sock->getOutputStream()->write(text_out, strlen(text_out));
                _oos->writeObject(*unit);
              } catch (exception & ex) {
                LOGERROR("Connection to Server lost, while sending audio process unit!!!" << ex.what());
                _sock->close();
              }
              if (unit->_last_process_unit) {
                LOGDEBUG("Last ProcessUnit for Audio received, clear out");
                _swap_codec_list.clear();
                _decoder_list.clear();
                _encoder_list.clear();
                std::map<int, org::esb::av::FrameConverter * >::iterator it = _converter_list.begin();
                for (; it != _converter_list.end(); it++) {
                  delete (*it).second;
                }
                _converter_list.clear();
              }
              delete unit;
            }
          }
          org::esb::lang::Thread::sleep2(5000);
        }
        boost::mutex::scoped_lock terminationLock(terminationMutex);
        ctrlCHit.notify_all();
      }