예제 #1
0
  void playWithHomeTheater() {

    // Create all the parts of the home theatre system
    Amplifier amp("Top-O-Line Amplifier");
    CdPlayer cd("Top-O-Line CD Player", &amp);
    DvdPlayer dvd("Top-O-Line DVD Player", &amp);
    Screen screen("My Theater Screen");
    PopcornPopper popper("My Popcorn Popper");
    Tuner tuner("Top-O-Line AM/FM Tuner", &amp);
    TheaterLights lights("Theater Ceiling Lights");
    Projector projector("Top-O-Line Projector");

    popper.on();  // Turn on the popcorn popper...
    popper.pop(); // and start popping...

    lights.dim(10); // Dim the lights to 10%... 
    
    screen.down();  // Put the screen down...

    projector.on();             // Turn on the projector...
    projector.setInput(&dvd);    // set it to DVD...
    projector.wideScreenMode(); // and put it on wide screen mode for the movie...

    amp.on();                // Turn on the amp...
    amp.setInput(&dvd);       // set it to DVD and...
    amp.setSurroundSound();  // put it into surround sound mode...
    amp.setVolume(11);       // and set the volume to 11...

    dvd.on();                            // Turn on the DVD player...
    dvd.play("Raiders of the lost ark"); // and FINALLY, play the movie!

    // What about shutting everything down again?!
    // How would you play a CD? etc...
  }
예제 #2
0
// Doxygen skip:
/// @cond
void QueueManager::addStructureToSubmissionQueue_(Structure* s, int optStep)
{
  Q_ASSERT(trackerContainsStructure(s, &m_newSubmissionTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_newSubmissionTracker);

  // Update structure
  s->lock().lockForWrite();
  if (s->getStatus() != Structure::Optimized) {
    s->setStatus(Structure::WaitingForOptimization);
    if (optStep != -1) {
      s->setCurrentOptStep(optStep);
    }
  }
  s->lock().unlock();

  // Perform writing
  m_opt->queueInterface(s->getCurrentOptStep())->writeInputFiles(s);

  m_jobStartTracker.lockForWrite();
  m_jobStartTracker.append(s);
  m_jobStartTracker.unlock();

  m_runningTracker.lockForWrite();
  m_runningTracker.append(s);
  m_runningTracker.unlock();

  emit structureUpdated(s);
}
예제 #3
0
// Doxygen skip:
/// @cond
void QueueManager::handleSubmittedStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_submittedTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_submittedTracker);

  if (s->getStatus() != Structure::Submitted) {
    return;
  }

  switch (m_opt->queueInterface(s->getCurrentOptStep())->getStatus(s)) {
    case QueueInterface::Running:
    case QueueInterface::Queued:
    case QueueInterface::Success:
    case QueueInterface::Started:
      // Update the structure as "InProcess"
      s->lock().lockForWrite();
      s->setStatus(Structure::InProcess);
      s->lock().unlock();
      emit structureUpdated(s);
      break;
    case QueueInterface::Error:
      s->lock().lockForWrite();
      s->setStatus(Structure::Restart);
      s->lock().unlock();
      emit structureUpdated(s);
      break;
    case QueueInterface::CommunicationError:
    case QueueInterface::Unknown:
    case QueueInterface::Pending:
    default:
      // nothing to do but wait
      break;
  }
}
예제 #4
0
// Doxygen skip:
/// @cond
void QueueManager::handleRestartStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_restartTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_restartTracker);

  if (s->getStatus() != Structure::Restart) {
    return;
  }

  stopJob(s);

  addStructureToSubmissionQueue(s);
}
예제 #5
0
				Ret operator[](const Policies& p)
				{
					typedef typename find_conversion_policy<0, Policies>::type converter_policy;
					typename converter_policy::template generate_converter<Ret, lua_to_cpp>::type converter;

					m_called = true;
					lua_State* L = m_obj->lua_state();
					detail::stack_pop popper(L, 2); // pop the return value and the self reference

					// get the function
					m_obj->pushvalue();
					lua_pushstring(L, m_member_name);
					lua_gettable(L, -2);

					// push the self-object
					m_obj->pushvalue();

					detail::push_args_from_tuple<1>::apply(L, m_args, p);
					if (lua_pcall(L, boost::tuples::length<Tuple>::value + 1, 1, 0))
					{ 
#ifndef LUABIND_NO_EXCEPTIONS
						throw error(L);
#else
						error_callback_fun e = detail::error_callback::get().err;
						if (e) e(L);
	
						assert(0 && "the lua function threw an error and exceptions are disabled."
							"If you want to handle this error use luabind::set_error_callback()");
						std::terminate();
#endif
					}

#ifndef LUABIND_NO_ERROR_CHECKING

					if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
					{
#ifndef LUABIND_NO_EXCEPTIONS
						throw cast_failed(L, LUABIND_TYPEID(Ret));
#else
						cast_failed_callback_fun e = detail::error_callback::get().cast;
						if (e) e(L, LUABIND_TYPEID(Ret));

						assert(0 && "the lua function's return value could not be converted."
							"If you want to handle this error use luabind::set_error_callback()");
						std::terminate();
#endif
					}
#endif
					return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
				}
예제 #6
0
  void playWithHomeTheaterFacade() {
    // Create all the parts of the home theatre system
    // Not encapsulated or owned by the facade.
    Amplifier amp("Top-O-Line Amplifier");
    CdPlayer cd("Top-O-Line CD Player", &amp);
    DvdPlayer dvd("Top-O-Line DVD Player", &amp);
    Screen screen("My Theater Screen");
    PopcornPopper popper("My Popcorn Popper");
    Tuner tuner("Top-O-Line AM/FM Tuner", &amp);
    TheaterLights lights("Theater Ceiling Lights");
    Projector projector("Top-O-Line Projector");

    HomeTheaterFacade theater(&amp, &tuner, &dvd, &cd, &projector, &lights, &screen, &popper);
    theater.watchMovie("Raiders of the Lost Ark");
    theater.endMovie();
  }
예제 #7
0
// Doxygen skip:
/// @cond
void QueueManager::handleSupercellStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_newSupercellTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_newSupercellTracker);

  if (s->getStatus() != Structure::Supercell) {
    return;
  }

  // Ensure that the job is not tying up the queue
  stopJob(s);

  // Remove from running tracker
  m_runningTracker.lockForWrite();
  m_runningTracker.remove(s);
  m_runningTracker.unlock();
}
예제 #8
0
// Doxygen skip:
/// @cond
void QueueManager::handleInProcessStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_inProcessTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_inProcessTracker);

  // Revalidate assumptions
  if (s->getStatus() != Structure::InProcess) {
    return;
  }

  QueueInterface* qi = m_opt->queueInterface(s->getCurrentOptStep());
  switch (qi->getStatus(s)) {
    case QueueInterface::Running:
    case QueueInterface::Queued:
    case QueueInterface::CommunicationError:
    case QueueInterface::Unknown:
    case QueueInterface::Pending:
    case QueueInterface::Started:
    {
      // Kill the structure if it has exceeded the allowable time.
      // Only perform this for remote queues.
      if (m_opt->cancelJobAfterTime() &&
          s->getOptElapsedHours() > m_opt->hoursForCancelJobAfterTime() &&
          qi->getIDString().toLower() != "local") {
        killStructure(s);
        emit structureUpdated(s);
        return;
      }
      // Nothing to do but wait
      break;
    }
    case QueueInterface::Success:
      updateStructure(s);
      break;
    case QueueInterface::Error:
      s->lock().lockForWrite();
      s->setStatus(Structure::Error);
      s->lock().unlock();
      emit structureUpdated(s);
      break;
  }

  return;
}
예제 #9
0
    virtual bool readProject( const QString &uri, QIODevice *ioDevice, QgsReadWriteContext &context ) override
    {
      QgsReadWriteContextCategoryPopper popper( context.enterCategory( "memory storage" ) );

      QStringList lst = uri.split( ":" );
      Q_ASSERT( lst.count() == 2 );
      QString projectName = lst[1];

      if ( !mProjects.contains( projectName ) )
      {
        context.pushMessage( "project not found", Qgis::Critical );
        return false;
      }

      QByteArray content = mProjects[projectName];
      ioDevice->write( content );
      ioDevice->seek( 0 );
      return true;
    }
예제 #10
0
// Doxygen skip:
/// @cond
void QueueManager::handleKilledStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_newlyKilledTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_newlyKilledTracker);

  if (s->getStatus() != Structure::Killed &&
      // Remove structures end up here, too, so check this (see
      // handleRemovedStructure below)
      s->getStatus() != Structure::Removed) {
    return;
  }

  // Ensure that the job is not tying up the queue
  stopJob(s);

  // Remove from running tracker
  m_runningTracker.lockForWrite();
  m_runningTracker.remove(s);
  m_runningTracker.unlock();
}
예제 #11
0
// Doxygen skip:
/// @cond
void QueueManager::handleOptimizedStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_newlyOptimizedTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_newlyOptimizedTracker);

  // Revalidate assumptions
  if (s->getStatus() != Structure::Optimized) {
    return;
  }

  // Ensure that the job is not tying up the queue
  stopJob(s);

  // Remove from running tracker
  m_runningTracker.lockForWrite();
  m_runningTracker.remove(s);
  m_runningTracker.unlock();

  emit structureFinished(s);
}
예제 #12
0
파일: functor.hpp 프로젝트: NeoAnomaly/xray
				Ret operator[](const Policies& p)
				{
					typedef typename detail::find_conversion_policy<0, Policies>::type converter_policy;
					typename converter_policy::template generate_converter<Ret, lua_to_cpp>::type converter;

					m_called = true;
					lua_State* L = m_func->lua_state();
#ifndef LUABIND_NO_ERROR_CHECKING
					if (L == 0)
					{
	#ifndef LUABIND_NO_EXCEPTIONS
						throw error(L); 
	#else
						error_callback_fun e = get_error_callback();
						if (e) e(L);
	
						/*assert(0 && "tried to call uninitialized functor object."
							"if you want to handle this error use luabind::set_error_callback()");
						std::terminate();*/
	#endif
					}
#endif

					detail::stack_pop popper(L, 1); // pop the return value

					// get the function
					m_func->pushvalue();

					detail::push_args_from_tuple<1>::apply(L, m_args, p);
					if (pcall(L, boost::tuples::length<Tuple>::value, 1))
					{ 
#ifndef LUABIND_NO_EXCEPTIONS
						throw error(L);
#else
						error_callback_fun e = get_error_callback();
						if (e) e(L);
	
						/*assert(0 && "the lua function threw an error and exceptions are disabled."
							"if you want to handle this error use luabind::set_error_callback()");
						std::terminate();*/
#endif
					}

#ifndef LUABIND_NO_ERROR_CHECKING

					if (converter.match(L, LUABIND_DECORATE_TYPE(Ret), -1) < 0)
					{
#ifndef LUABIND_NO_EXCEPTIONS
						throw cast_failed(L, LUABIND_TYPEID(Ret));
#else
						cast_failed_callback_fun e = get_cast_failed_callback();
						if (e) e(L, LUABIND_TYPEID(Ret));

						/*assert(0 && "the lua function's return value could not be converted."
							"if you want to handle this error use luabind::set_error_callback()");
						std::terminate();*/
#endif
					}
#endif
					return converter.apply(L, LUABIND_DECORATE_TYPE(Ret), -1);
				}
예제 #13
0
 inline template<typename T> T pop() {
   janus_data_stack_popper<stack_t, T> popper;
   return popper(raw_stack());
 }
예제 #14
0
// Doxygen skip:
/// @cond
void QueueManager::handleErrorStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_errorTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_errorTracker);

  if (s->getStatus() != Structure::Error) {
    return;
  }

  if (!m_opt->usingGUI()) {
    qDebug() << "Structure"
             << QString::number(s->getGeneration()) + "x" +
                  QString::number(s->getIDNumber())
             << "failed";
  }

  stopJob(s);

  // Lock for writing
  QWriteLocker locker(&s->lock());

  s->addFailure();

  // If the number of failures has exceed the limit, take
  // appropriate action
  if (s->getFailCount() >= m_opt->failLimit) {
    switch (OptBase::FailActions(m_opt->failAction)) {
      case OptBase::FA_DoNothing:
      default:
        // resubmit job
        s->setStatus(Structure::Restart);
        emit structureUpdated(s);
        return;
      case OptBase::FA_KillIt:
        locker.unlock();
        killStructure(s);
        emit structureUpdated(s);
        return;
      case OptBase::FA_Randomize:
        s->setStatus(Structure::Empty);
        locker.unlock();
        m_opt->replaceWithRandom(s, tr("excessive failures"));
        s->setStatus(Structure::Restart);
        emit structureUpdated(s);
        return;
      case OptBase::FA_NewOffspring:
        s->setStatus(Structure::Empty);
        locker.unlock();
        m_opt->replaceWithOffspring(s, tr("excessive failures"));
        s->setStatus(Structure::Restart);
        emit structureUpdated(s);
        return;
    }
  }
  // Resubmit job if failure limit hasn't been reached
  else {
    s->setStatus(Structure::Restart);
    emit structureUpdated(s);
    return;
  }
}
예제 #15
0
// Doxygen skip:
/// @cond
void QueueManager::handleStepOptimizedStructure_(Structure* s)
{
  Q_ASSERT(trackerContainsStructure(s, &m_stepOptimizedTracker));
  removeFromTrackerWhenScopeEnds popper(s, &m_stepOptimizedTracker);

  QWriteLocker locker(&s->lock());

  // Validate assumptions
  if (s->getStatus() != Structure::StepOptimized) {
    return;
  }

  s->stopOptTimer();

  QString err;
  if (!m_opt->checkStepOptimizedStructure(s, &err)) {
    // Structure failed a post optimization step:
    m_opt->warning(QString("Structure %1 failed a post-optimization step: %2")
                     .arg(s->getIDString())
                     .arg(err));
    s->setStatus(Structure::Killed);
    locker.unlock();
    emit structureUpdated(s);
    return;
  }

  // update optstep and relaunch if necessary
  if (s->getCurrentOptStep() + 1 <
      static_cast<unsigned int>(m_opt->getNumOptSteps())) {

    // Print an update to the terminal if we are not using the GUI
    if (!m_opt->usingGUI()) {
      qDebug() << "Structure"
               << QString::number(s->getGeneration()) + "x" +
                    QString::number(s->getIDNumber())
               << "completed step" << s->getCurrentOptStep();
    }

    s->setCurrentOptStep(s->getCurrentOptStep() + 1);

    // Update status
    s->setStatus(Structure::WaitingForOptimization);
    m_runningTracker.lockForWrite();
    m_runningTracker.append(s);
    m_runningTracker.unlock();
    locker.unlock();
    emit structureUpdated(s);
    addStructureToSubmissionQueue(s);
    return;
  }
  // Otherwise, it's done
  else {
    // Print an update to the terminal if we are not using the GUI
    if (!m_opt->usingGUI()) {
      qDebug() << "Structure"
               << QString::number(s->getGeneration()) + "x" +
                    QString::number(s->getIDNumber())
               << "is optimized!";
    }

    s->setStatus(Structure::Optimized);
    locker.unlock();
    handleOptimizedStructure(s);
  }
}