예제 #1
0
void SFXSound::_updateStatus()
{
   // If we have a voice, use its status.
   
   if( mVoice )
   {
      SFXStatus voiceStatus = mVoice->getStatus();
      
      // Filter out SFXStatusBlocked.
      
      if( voiceStatus == SFXStatusBlocked )
         _setStatus( SFXStatusPlaying );
      else
         _setStatus( voiceStatus );
      
      return;
   }

   // If we're not in a playing state or we're a looping
   // sound then we don't need to calculate the status.
   
   if( isLooping() || mStatus != SFXStatusPlaying )
      return;

   // If we're playing and don't have a voice we
   // need to decide if the sound is done playing
   // to ensure proper virtualization of the sound.

   if( mPlayTimer.getPosition() > mDuration )
   {
      _stop();
      _setStatus( SFXStatusStopped );
   }
}
예제 #2
0
void DatabasesCloner::_onListDatabaseFinish(const CommandCallbackArgs& cbd) {
    const Status respStatus = cbd.response.getStatus();
    if (!respStatus.isOK()) {
        // TODO: retry internally?
        _setStatus(respStatus);
        _doNextActions();
        return;
    }

    const auto respBSON = cbd.response.getValue().data;

    // There should not be any cloners yet
    invariant(_databaseCloners.size() == 0);

    const auto okElem = respBSON["ok"];
    if (okElem.trueValue()) {
        const auto dbsElem = respBSON["databases"].Obj();
        BSONForEach(arrayElement, dbsElem) {
            const BSONObj dbBSON = arrayElement.Obj();
            const std::string name = dbBSON["name"].str();
            ++_clonersActive;
            std::shared_ptr<DatabaseCloner> dbCloner{nullptr};
            try {
                dbCloner.reset(new DatabaseCloner(
                    _exec,
                    _source,
                    name,
                    BSONObj(),                            // do not filter database out.
                    [](const BSONObj&) { return true; },  // clone all dbs.
                    _storage,                             // use storage provided.
                    [](const Status& status, const NamespaceString& srcNss) {
                        if (status.isOK()) {
                            log() << "collection clone finished: " << srcNss;
                        } else {
                            log() << "collection clone for '" << srcNss << "' failed due to "
                                  << status.toString();
                        }
                    },
                    [=](const Status& status) { _onEachDBCloneFinish(status, name); }));
            } catch (...) {
                // error creating, fails below.
            }

            Status s = dbCloner ? dbCloner->start() : Status(ErrorCodes::UnknownError, "Bad!");

            if (!s.isOK()) {
                std::string err = str::stream() << "could not create cloner for database: " << name
                                                << " due to: " << s.toString();
                _setStatus(Status(ErrorCodes::InitialSyncFailure, err));
                error() << err;
                break;  // exit for_each loop
            }

            // add cloner to list.
            _databaseCloners.push_back(dbCloner);
        }
    } else {
예제 #3
0
void SFXFMODEventSource::_updateStatus()
{
   if( mStatus == SFXStatusPlaying )
   {
      if( !getEvent() )
         _setStatus( SFXStatusStopped );
      else
      {
         FMOD_EVENT_STATE state;
         SFXFMODDevice::smFunc->FMOD_Event_GetState( mHandle, &state );
         
         if( !( state & FMOD_EVENT_STATE_PLAYING ) )
            _setStatus( SFXStatusStopped );
      }
   }
}
예제 #4
0
void SFXFMODEventSource::stop( F32 fadeOutTime )
{
   if( getStatus() == SFXStatusStopped )
      return;
      
   AssertFatal( mHandle, "SFXFMODEvent::stop() - event not acquired" );
   
   bool immediate = ( fadeOutTime == 0.f );
   
   FMOD_RESULT result = SFXFMODDevice::smFunc->FMOD_Event_Stop( mHandle, immediate );
   if( result != FMOD_OK )
      Con::errorf( "SFXFMODEventSource::stop() - failed to stop event: %s", FMODResultToString( result ).c_str() );

   mPlayTimer.stop();
   _setStatus( SFXStatusStopped );
   
   // Reset fade-in to default in case it got overwritten
   // in play().

   U32 fade = U32( mFadeInTime * 1000.f );
   SFXFMODDevice::smFunc->FMOD_Event_SetPropertyByIndex(
      mHandle, FMOD_EVENTPROPERTY_FADEIN,
      &fade, true
   );
   
   _stop();
}
예제 #5
0
void SFXFMODEventSource::play( F32 fadeInTime )
{
   if( getStatus() == SFXStatusPlaying )
      return;
      
   if( isPaused() )
      SFXFMODDevice::smFunc->FMOD_Event_SetPaused( mHandle, false );
   else
   {
      AssertFatal( getEvent()->getEventGroup()->isDataLoaded(), "SFXFMODEventSource::play() - event data for group not loaded" );
                     
      if( fadeInTime != -1.f )
      {
         U32 fade = U32( fadeInTime * 1000.f );
         SFXFMODDevice::smFunc->FMOD_Event_SetPropertyByIndex(
            mHandle, FMOD_EVENTPROPERTY_FADEIN,
            &fade, true
         );
      }
      
      FMOD_RESULT result = SFXFMODDevice::smFunc->FMOD_Event_Start( mHandle );
      if( result != FMOD_OK )
      {
         Con::errorf( "SFXFMODEventSoure::play() - failed to start event: %s", FMODResultToString( result ).c_str() );
         return;
      }
   }
   
   mPlayTimer.start();
   _setStatus( SFXStatusPlaying );
   
   _play();
}
예제 #6
0
// Initial Sync
Status DatabasesCloner::start() {
    _active = true;

    if (!_status.isOK() && _status.code() != ErrorCodes::NotYetInitialized) {
        return _status;
    }

    _status = Status::OK();

    log() << "starting cloning of all databases";
    // Schedule listDatabase command which will kick off the database cloner per result db.
    Request listDBsReq(_source,
                       "admin",
                       BSON("listDatabases" << true),
                       rpc::ServerSelectionMetadata(true, boost::none).toBSON());
    CBHStatus s = _exec->scheduleRemoteCommand(
        listDBsReq,
        stdx::bind(&DatabasesCloner::_onListDatabaseFinish, this, stdx::placeholders::_1));
    if (!s.isOK()) {
        _setStatus(s);
        _failed();
    }

    _doNextActions();

    return _status;
}
void NtgTransformDomainNameToIp::_exec(const NtgEntity & input, QHash<QString, QString> params)
{
  if( input.type != "domain-name" || ! input.values.contains("value"))
  {
    _setError(Ntg::InvalidInputError, "Type of input Entity is not\"domain-name\", or missing key \"value\".");
    return;
  }

  QStringList arguments;
  if(params.contains("server port"))
    arguments << QString("-port=%1").arg(params.value("server port"));
  if(params.contains("timeout"))
    arguments << QString("-timeout=%1").arg(params.value("timeout"));

  arguments << input.values["value"];

  if(params.contains("server"))
    arguments << params.value("server");

  _process.setReadChannel(QProcess::StandardOutput);
  connect(&_process, SIGNAL(readyReadStandardOutput()), this, SLOT(_parseOutput()));
  connect(&_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(_finished(int, QProcess::ExitStatus)));
  connect(&_process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(_error(QProcess::ProcessError)));
  _process.start("nslookup", arguments, QIODevice::ReadOnly);
  _setStatus(Ntg::Running);
}
void NtgTransformDomainNameToIp::_finished( int exitCode, QProcess::ExitStatus exitStatus)
{
  if( exitStatus == QProcess::NormalExit && exitCode == 0)
    _setStatus(Ntg::Finished);
  else
  {
    QString str = _process.readAllStandardError();
    _setError(Ntg::CustomError, str);
  }
}
예제 #9
0
void SFXFMODEventSource::pause( F32 fadeOutTime )
{
   if( getStatus() != SFXStatusPlaying )
      return;

   SFXFMODDevice::smFunc->FMOD_Event_SetPaused( mHandle, true );

   mPlayTimer.pause();
   _setStatus( SFXStatusPaused );
   
   _pause();
}
예제 #10
0
void SFXSource::stop( F32 fadeOutTime )
{
   _updateStatus();
   
   if( mStatus != SFXStatusPlaying
       && mStatus != SFXStatusPaused )
      return;
      
   if( fadeOutTime != 0.0f && ( fadeOutTime > 0.0f || mFadeOutTime > 0.0f ) )
   {
      // Do a fade-out and then stop.
      
      _clearEffects< SFXFadeEffect >();
      
      if( fadeOutTime == -1.0f )
         fadeOutTime = mFadeOutTime;
         
      mEffects.pushFront( new SFXFadeEffect( this,
                                             getMin( fadeOutTime,
                                                     F32( getDuration() - getPosition() ) / 1000.f ),
                                             0.0f,
                                             getPosition(),
                                             SFXFadeEffect::ON_END_Stop,
                                             true ) );
   }
   else
   {
      // Stop immediately.
      
      _setStatus( SFXStatusStopped );
   
      if ( mVoice )
         mVoice->stop();
      else
         mVirtualPlayTimer.stop();
         
      #ifdef DEBUG_SPEW
      Platform::outputDebugString( "[SFXSource] stopped playback of source '%i'", getId() );
      #endif
   }      
}
예제 #11
0
void SFXController::_update()
{
   Parent::_update();
   
   SFXPlayList* playList = getPlayList();

   // Check all sources against the current state setup and
   // take appropriate actions.
 
   for( U32 i = 0; i < mSources.size(); ++ i )
   {
      Source& source = mSources[ i ];
      
      // If the source has already stopped playing,
      // remove it.
      
      if( !source.mPtr )
      {
         mSources.erase( i );
         -- i;
         continue;
      }
      
      if( !source.mState )
         continue;
         
      SFXPlayList::EStateMode stateMode = playList->getSlots().mStateMode[ mSources[ i ].mSlotIndex ];
      if( !source.mState->isActive() )
      {
         if( source.mPtr->isPlaying() )
         {
            // The source is playing in an incompatible state.
            
            if( stateMode == SFXPlayList::STATE_PauseInactive )
               source.mPtr->pause();
            else if( stateMode == SFXPlayList::STATE_StopInactive )
            {
               source.mPtr->stop();
               mSources.erase( i );
            
               -- i;
            }
         }
      }
      else
      {
         // Unpause a source that had its state become active again.
         
         if( source.mPtr->isPaused() && stateMode == SFXPlayList::STATE_PauseInactive )
            source.mPtr->play();
      }
   }
      
   // Update interpreter.
      
   bool endUpdate = false;
   while( !endUpdate )
   {
      if( mIp >= mInsns.size() )
      {
         // End of list reached.
         
         if( playList->getDescription()->mIsLooping &&
             playList->getLoopMode() == SFXPlayList::LOOP_All )
         {
            // The play list is set to repeat-all.
            // If it is also random, generate a new instruction list
            // so we get a new playing order.  Otherwise just reset.
            
            if( playList->getRandomMode() != SFXPlayList::RANDOM_NotRandom )
               _compileList( playList );
            else
            {
               mIp = 0;
               if( !mInsns.empty() )
                  _initInsn();
            }
            
            // Reset play timer.
            
            mPlayTimer.reset();
            mPlayTimer.start();
         }
         else
         {
            // Moved to stopped state.
            
            mPlayTimer.stop();
            _setStatus( SFXStatusStopped );
            mIp = 0;
         }
         
         // End this update.  This limits playlist to at most one complete
         // cycle per update.
         
         break;
      }
         
      Insn& insn = mInsns[ mIp ];
      
      if( insn.mState && !insn.mState->isActive() )
      {
         // The state associated with the slot is inactive.  Skip
         // the instructions.
         _advanceIp();
      }
      else
         endUpdate = _execInsn();
   }
}
예제 #12
0
void SFXSource::play( F32 fadeInTime )
{
   // Update our status once.
   _updateStatus();

   if( mStatus == SFXStatusPlaying )
      return;

   if( mStatus != SFXStatusPaused )
      mPlayStartTick = Platform::getVirtualMilliseconds();
         
   // Add fade-out, if requested.
   
   U32 fadeOutStartsAt = getDuration();
   if( mFadeOutTime )
   {
      fadeOutStartsAt = getMax( getPosition(), getDuration() - U32( mFadeOutTime * 1000 ) );
      mEffects.pushBack( new SFXFadeEffect( this,
                                            getMin( mFadeOutTime,
                                                    F32( getDuration() - getPosition() ) / 1000.f ),
                                            0.0f,
                                            fadeOutStartsAt,
                                            SFXFadeEffect::ON_END_Stop,
                                            true ) );
   }
   
   // Add fade-in, if requested.
   
   if( fadeInTime != 0.0f && ( fadeInTime > 0.0f || mFadeInTime > 0.0f ) )
   {
      // Don't fade from full 0.0f to avoid virtualization on this source.
      
      if( fadeInTime == -1.0f )
         fadeInTime = mFadeInTime;
         
      fadeInTime = getMin( fadeInTime, F32( fadeOutStartsAt ) * 1000.f );
      
      mEffects.pushFront( new SFXFadeEffect( this, 
                                             fadeInTime,
                                             mVolume,
                                             getPosition(),
                                             SFXFadeEffect::ON_END_Nop,
                                             true ) );
      setVolume( 0.01f );
   }

   // Start playback.

   _setStatus( SFXStatusPlaying );
   if( mVoice )
   {
      #ifdef DEBUG_SPEW
      Platform::outputDebugString( "[SFXSource] playing source '%i'", getId() );
      #endif
      
      mVoice->play( mIsLooping );
   }
   else
   {
      // To ensure the fastest possible reaction 
      // to this playback let the system reassign
      // voices immediately.
      SFX->_assignVoices();

      // If we did not get assigned a voice, start the
      // playback timer for virtualized playback.

      if( !mVoice )
      {
         #ifdef DEBUG_SPEW
         Platform::outputDebugString( "[SFXSource] virtualizing playback of source '%i'", getId() );
         #endif
         
         mVirtualPlayTimer.start();
      }
   }
}
예제 #13
0
void LocalTransform::_setError(Ntg::TransformError error, QString msg)
{
    _error = error;
    _errorString = msg;
    _setStatus(Ntg::Failed);
}