Exemplo n.º 1
0
void GameView::onPositionChange( IJoystick::Position position )
{
    switch ( position )
    {
    case IJoystick::Up:
        if ( _cursor.y > 0 ) _cursor.y--;
        update( Model::GameFieldSection );
        break;

    case IJoystick::Down:
        if ( _cursor.y < 2 ) _cursor.y++;
        update( Model::GameFieldSection );
        break;

    case IJoystick::Left:
        if ( _cursor.x > 0 ) _cursor.x--;
        update( Model::GameFieldSection );
        break;

    case IJoystick::Right:
        if ( _cursor.x < 2 ) _cursor.x++;
        update( Model::GameFieldSection );
        break;

    case IJoystick::Pressed:
        if ( observer() && _model.gamefield().symbol( _cursor ) == GameField::None )
            observer()->onGameFieldSelection( _cursor );
        break;
    default:
        // Do nothing...
        break;
    }
}
Exemplo n.º 2
0
//Damage this actor from a particular faction
void PhysicsActor::Damage(FactionId damagingFaction, float damage) {
	//Can't take damage if you're invulnerable
	if (!vulnerable)
		return;
	//Check that you're alive
	if (life > 0) {
		lastDamageRecieved = Game()->Now();
		//Fire the damaged event
		Game()->Actors.ActorDamaged.Fire([this,damagingFaction,damage](function<void(Actor*,Actor*,FactionId,float)> observer) {
			observer(this,NULL,damagingFaction,damage);
		});
		//Apply damage
		life -= damage;
		if (life < 0)
			life = 0;
		if (life <= 0) {
			//Can't die anymore
			vulnerable = false;
			//Fire on death event
			Game()->Actors.ActorKilled.Fire([this,damagingFaction](function<void(Actor*,Actor*,FactionId)> observer) {
				observer(this,NULL,damagingFaction);
			});
			//This actor just died
			onDeath();
		}
	}
}
Exemplo n.º 3
0
bool DBBaseWidget::dataEditable()
{
	if ( observer() == NULL ) {
		return m_dataEditable;
	}
	if ( observer()->readOnly() ) {
		return false;
	}
	return m_dataEditable;
}
Exemplo n.º 4
0
void
tree_addendum_rep::notify_insert_node (tree& ref, int pos) {
  //cout << "Notify insert node " << ref << ", " << pos << "\n";
  // NOTE: should we remove the 'false'? see also tree_pointer.cpp
  if (keep && false) {
    remove_observer (ref[pos]->obs, observer (this));
    ptr= ref.rep;
    insert_observer (ref->obs, observer (this));
  }
  //cout << "position -> " << obtain_position (observer (this)) << "\n";
}
Exemplo n.º 5
0
bool
tree_addendum_rep::set_tree (tree t) {
  if (ptr != t.rep) {
    tree ref (ptr);
    remove_observer (ref->obs, observer (this));
    if (keep) {
      ptr= t.rep;
      insert_observer (t->obs, observer (this));
    }
    // FIXME: if !keep, then is it safe to not reinsert the observer?
  }
  return true;
}
Exemplo n.º 6
0
/* void resetAnimation (); */
NS_IMETHODIMP imgContainer::ResetAnimation()
{
  if (mAnimationMode == kDontAnimMode || 
      !mAnim || mAnim->currentAnimationFrameIndex == 0)
    return NS_OK;

  PRBool oldAnimating = mAnim->animating;

  if (mAnim->animating) {
    nsresult rv = StopAnimation();
    NS_ENSURE_SUCCESS(rv, rv);
  }

  mAnim->lastCompositedFrameIndex = -1;
  mAnim->currentAnimationFrameIndex = 0;
  // Update display
  nsCOMPtr<imgIContainerObserver> observer(do_QueryReferent(mObserver));
  if (observer) {
    nsresult rv = RestoreDiscardedData();
    NS_ENSURE_SUCCESS(rv, rv);
    observer->FrameChanged(this, mFrames[0], &(mAnim->firstFrameRefreshArea));
  }

  if (oldAnimating)
    return StartAnimation();
  return NS_OK;
}
Exemplo n.º 7
0
TEST_F(TModbusDeviceTest, OnValue)
{
    FilterConfig("OnValueTest");
    PModbusSlave slave = ModbusServer->SetSlave(
        Config->PortConfigs[0]->DeviceConfigs[0]->SlaveId,
        TModbusRange(
            TServerRegisterRange(),
            TServerRegisterRange(),
            TServerRegisterRange(0, 1),
            TServerRegisterRange()));
    ModbusServer->Start();

    PMQTTSerialObserver observer(new TMQTTSerialObserver(MQTTClient, Config));
    observer->SetUp();

    slave->Holding[0] = 0;
    Note() << "LoopOnce()";
    observer->LoopOnce();

    MQTTClient->DoPublish(true, 0, "/devices/OnValueTest/controls/Relay 1/on", "1");

    Note() << "LoopOnce()";
    observer->LoopOnce();
    ASSERT_EQ(500, slave->Holding[0]);

    slave->Holding[0] = 0;
    Note() << "LoopOnce() after slave update";
    observer->LoopOnce();

    slave->Holding[0] = 500;
    Note() << "LoopOnce() after second slave update";
    observer->LoopOnce();
}
Exemplo n.º 8
0
void TModbusDeviceTest::VerifyDDL24()
{
    PModbusSlave slave = ModbusServer->SetSlave(
        Config->PortConfigs[0]->DeviceConfigs[0]->SlaveId,
        TModbusRange(
            TServerRegisterRange(),
            TServerRegisterRange(),
            TServerRegisterRange(4, 19),
            TServerRegisterRange()));
    ModbusServer->Start();

    PMQTTSerialObserver observer(new TMQTTSerialObserver(MQTTClient, Config));
    observer->SetUp();

    Note() << "LoopOnce()";
    observer->LoopOnce();

    MQTTClient->DoPublish(true, 0, "/devices/ddl24/controls/RGB/on", "10;20;30");

    FakeSerial->Flush();
    Note() << "LoopOnce()";
    observer->LoopOnce();
    ASSERT_EQ(10, slave->Holding[4]);
    ASSERT_EQ(20, slave->Holding[5]);
    ASSERT_EQ(30, slave->Holding[6]);

    FakeSerial->Flush();
    slave->Holding[4] = 32;
    slave->Holding[5] = 64;
    slave->Holding[6] = 128;
    Note() << "LoopOnce() after slave update";

    observer->LoopOnce();
}
Exemplo n.º 9
0
void UIServer::killJob(QCString observerAppId, int progressId)
{
    // Contact the object "KIO::Observer" in the application <appId>
    Observer_stub observer(observerAppId, "KIO::Observer");
    // Tell it to kill the job
    observer.killJob(progressId);
}
Exemplo n.º 10
0
/*!
  Pide un nuevo observador si es necesario
  */
void DBNumberEdit::refresh()
{
	observer();
	if ( m_observer != NULL ) {
		m_observer->sync();
	}
}
// ----------------------------------------------------------------------------
// 
// ----------------------------------------------------------------------------
//
void CWrtHarvester::RequestForNotificationL( CWrtInfo& wrtInfo )
    {
    // Preventing duplicate entries.
    for( TInt i = 0; i < iObservers.Count(); i++ )
        {
        if( iObservers[i]->BundleId() == wrtInfo.iBundleId )
            {
            return;
            }
        }
    
    CWrtHarvesterPublisherObserver* observer( NULL );
    CLiwDefaultMap* filter = CLiwDefaultMap::NewLC();
    
    filter->InsertL( KPublisherId, TLiwVariant( KWRTPublisher ) );
    filter->InsertL( KContentType, TLiwVariant( KTemplatedWidget ) );
    filter->InsertL( KContentId, TLiwVariant( wrtInfo.iBundleId ) );
    filter->InsertL( KOperation, TLiwVariant( KExecute ));
    
    observer = CWrtHarvesterPublisherObserver::NewLC( *wrtInfo.iBundleId, this );
    observer->RegisterL(filter);
    
    iObservers.AppendL( observer );
    
    CleanupStack::Pop( observer );
    
    CleanupStack::PopAndDestroy(filter);
    }
   // ----------------------------------------------------------------------
   void
   LocalizationMinMaxModule::
   work( void )
      throw()
   {
      if ( owner().is_anchor() )
         state_ = minmax_finished;

      if ( state_ == minmax_finished )
         return;

      if ( state_ == minmax_wait )
         state_ = minmax_work;

      shawn::Vec est_pos;
      NeighborInfoList neighbors;
      collect_neighbors( neighborhood(), lat_anchors, neighbors );

      if ( est_pos_min_max( neighbors, est_pos ) )
      {
         if ( !observer().check_residue() || check_residue( neighbors, est_pos, lat_anchors, observer().comm_range() ) )
            node_w().set_est_position( est_pos );
      }

      state_ = minmax_finished;
   }
Exemplo n.º 13
0
void InternalBuildJob::build(const TopLevelProjectPtr &project,
        const QList<ResolvedProductPtr> &products, const BuildOptions &buildOptions)
{
    setup(project, products, buildOptions.dryRun());
    setTimed(buildOptions.logElapsedTime());

    m_executor = new Executor(logger());
    m_executor->setProject(project);
    m_executor->setProducts(products);
    m_executor->setBuildOptions(buildOptions);
    m_executor->setProgressObserver(observer());

    QThread * const executorThread = new QThread(this);
    m_executor->moveToThread(executorThread);
    connect(m_executor, SIGNAL(reportCommandDescription(QString,QString)),
            this, SIGNAL(reportCommandDescription(QString,QString)));
    connect(m_executor, SIGNAL(reportProcessResult(qbs::ProcessResult)),
            this, SIGNAL(reportProcessResult(qbs::ProcessResult)));

    connect(executorThread, SIGNAL(started()), m_executor, SLOT(build()));
    connect(m_executor, SIGNAL(finished()), SLOT(handleFinished()));
    connect(m_executor, SIGNAL(destroyed()), executorThread, SLOT(quit()));
    connect(executorThread, SIGNAL(finished()), this, SLOT(emitFinished()));
    executorThread->start();
}
Exemplo n.º 14
0
void InternalSetupProjectJob::execute()
{
    RulesEvaluationContextPtr evalContext(new RulesEvaluationContext(logger()));
    evalContext->setObserver(observer());

    switch (m_parameters.restoreBehavior()) {
    case SetupProjectParameters::ResolveOnly:
        resolveProjectFromScratch(evalContext->engine());
        resolveBuildDataFromScratch(evalContext);
        break;
    case SetupProjectParameters::RestoreOnly:
        m_newProject = restoreProject(evalContext).loadedProject;
        break;
    case SetupProjectParameters::RestoreAndTrackChanges: {
        const BuildGraphLoadResult loadResult = restoreProject(evalContext);
        m_newProject = loadResult.newlyResolvedProject;
        if (!m_newProject)
            m_newProject = loadResult.loadedProject;
        if (!m_newProject) {
            resolveProjectFromScratch(evalContext->engine());
            resolveBuildDataFromScratch(evalContext);
        } else {
            QBS_CHECK(m_newProject->buildData);
        }
        break;
    }
    }

    if (!m_parameters.dryRun())
        storeBuildGraph(m_newProject);

    // The evalutation context cannot be re-used for building, which runs in a different thread.
    m_newProject->buildData->evaluationContext.clear();
}
Exemplo n.º 15
0
void CVulEngine::_RepairVul(HWND hWnd)
{
	ATLASSERT(m_pVulScan);
	CWindowVulfixObserver observer(hWnd);
	if(!m_pRepairVul)
		m_pRepairVul = CreateRepairVul();
	HRESULT hr = E_POINTER;
	if(m_pRepairVul)
	{
		m_pRepairVul->SetObserver( &observer );
		m_pRepairVul->Reset();
		m_pRepairVul->AddSoftVul(m_pVulScan, m_arrRepairVulSoftIds);
		m_pRepairVul->AddVul(m_pVulScan, m_arrRepairVulIds);

		CString strPath, strImportPath;
		GetDownloadPath( strPath );
		BKSafeConfig::Get_Vulfix_Download_LocalPath( strImportPath );
		BOOL bImportLocal = BKSafeConfig::Get_Vulfix_Download_UseLocal();
		BOOL bDownloadIfImportError = BKSafeConfig::Get_Vulfix_Download_DownloadIfNotExists();
		DWORD dwFlags = 0;
		if(bImportLocal && !strImportPath.IsEmpty())
		{
			dwFlags |= VULFLAG_REPAIR_IMPORT_LOCAL;
			if(bDownloadIfImportError)
				dwFlags |= VULFLAG_REPAIR_DOWNLOAD_IF_FAIL_IMPORT;
		}
		
		hr = m_pRepairVul->Repair(strPath, strImportPath, dwFlags);
		m_pRepairVul->WaitForRepairDone();	
		m_pVulScan->SetObserver(NULL);
	}
	m_isRepairing = FALSE;
	_RelayMessage( hWnd, WMH_REPAIR_DONE, m_bRepairCanceled, hr);
}
Exemplo n.º 16
0
    void doStart(const JavaScriptCommand *cmd, Transformer *transformer)
    {
        m_result.success = true;
        m_result.errorMessage.clear();
        ScriptEngine * const scriptEngine = provideScriptEngine();
        QScriptValue scope = scriptEngine->newObject();
        PrepareScriptObserver observer(scriptEngine);
        setupScriptEngineForFile(scriptEngine, transformer->rule->prepareScript->fileContext, scope);
        setupScriptEngineForProduct(scriptEngine, transformer->product(), transformer->rule->module, scope,
                                    &observer);
        transformer->setupInputs(scope);
        transformer->setupOutputs(scriptEngine, scope);

        for (QVariantMap::const_iterator it = cmd->properties().constBegin();
                it != cmd->properties().constEnd(); ++it) {
            scope.setProperty(it.key(), scriptEngine->toScriptValue(it.value()));
        }

        QScriptContext *ctx = scriptEngine->currentContext();
        ctx->pushScope(scope);
        scriptEngine->evaluate(cmd->sourceCode());
        ctx->popScope();
        transformer->propertiesRequestedInCommands
                += scriptEngine->propertiesRequestedInScript();
        scriptEngine->clearRequestedProperties();
        if (scriptEngine->hasUncaughtException()) {
            // ### We don't know the line number of the command's sourceCode property assignment.
            setError(scriptEngine->uncaughtException().toString(), cmd->codeLocation());
        }
    }
Exemplo n.º 17
0
void HumanBrain::takeTurn(World &world, Turn &turn, Character &me) {
	Observer observer(*this, turn, me);
	world.visitContents(observer);
	if (!observer.mSawSomeoneElseAlive) {
		mConsole->print("All alone, goodbye.");
		me.setHP(0);
	}
}
Exemplo n.º 18
0
void InternalSetupProjectJob::resolveProjectFromScratch(ScriptEngine *engine)
{
    Loader loader(engine, logger());
    loader.setSearchPaths(m_parameters.searchPaths());
    loader.setProgressObserver(observer());
    m_newProject = loader.loadProject(m_parameters);
    QBS_CHECK(m_newProject);
}
Exemplo n.º 19
0
/*!
  Ajusta los parámetros de visualización de este Widget en función de lo definido en DBField d->m_field
  */
void DBNumberEdit::applyFieldProperties()
{
	DBFieldObserver *obs= qobject_cast<DBFieldObserver *>(observer());
	if ( obs != NULL ) {
		setReadOnly(!dataEditable());
		setDecimalNumbers(obs->partD());
	}
}
      /*!
        @todo
          Ne pas passer par le chargement de TestDemonstration mais 
          faire un copier coller de son contenu dans le setup + une destruction 
          dans le tearDown puis executer les commandes d'accès diverses
      */
      void TestDemonstration::testBuild()
      {
        Model::init() ;
        Model::load("TestDemonstration") ;

        Object* observer(Model::getObject("Observer")) ;
        CPPUNIT_ASSERT_MESSAGE("no Observer object",observer) ;
        
        Kernel::Log::InformationMessage(std::string("sizeof(Object)=") 
                                        + toString(sizeof(Object))) ; 
        
        CPPUNIT_ASSERT_MESSAGE("Observer has no Observer trait",
                               observer->getTrait<Observer>()) ;

        Kernel::Log::InternalMessage("Testing Observer has Positionned trait") ;
        
        CPPUNIT_ASSERT_MESSAGE("Observer has no Positionned trait",
                               observer->getTrait<Positionned>()) ;

        CPPUNIT_ASSERT_MESSAGE("Observer has Universe trait",
                               observer->getTrait<Universe>()==NULL) ;


        Kernel::Log::InternalMessage("Testing Observer has Universe ancestor") ;
        
        Universe* universe(observer->getParent<Universe>()) ;
        CPPUNIT_ASSERT_MESSAGE("Observer has no Universe ancestor",
                               universe) ;


        Kernel::Log::InternalMessage("Testing Universe has object") ;
        Object* universe_object = universe->getObject() ;
        
        CPPUNIT_ASSERT_MESSAGE("universe has no object",
                               universe_object) ;


        Kernel::Log::InternalMessage("Testing Universe has Universe trait") ;
                               
        CPPUNIT_ASSERT_MESSAGE("universe has no Universe trait",
                               universe->getObject()->getTrait<Universe>()) ;

        Kernel::Log::InternalMessage("Testing Observer has StellarSystem ancestor") ;

        StellarSystem* system(observer->getParent<StellarSystem>()) ;
        CPPUNIT_ASSERT_MESSAGE("Observer has no StellarSystem ancestor",
                               system) ;
        Kernel::Log::InformationMessage(std::string("sizeof(StellarSystem)=") 
                                        + toString(sizeof(StellarSystem))) ; 
        Kernel::Log::InformationMessage(std::string("sizeof(Positionned)=") 
                                        + toString(sizeof(Positionned))) ; 

        CPPUNIT_ASSERT_MESSAGE("Observer has no Positionned root",
                               observer->getRoot<Positionned>()) ;

        Model::close() ;
        
      }
Exemplo n.º 21
0
void
VectorImage::InvalidateObserver()
{
  RefPtr<imgDecoderObserver> observer(mObserver);
  if (observer) {
    observer->FrameChanged(&nsIntRect::GetMaxSizedIntRect());
    observer->OnStopFrame();
  }
}
Exemplo n.º 22
0
void InternalInstallJob::start()
{
    try {
        ProductInstaller(m_project, m_products, m_options, observer(), logger()).install();
    } catch (const ErrorInfo &error) {
        setError(error);
    }
    emit finished(this);
}
   // ----------------------------------------------------------------------
   void
   LocalizationGPSfreeLCSModule::
   work( void )
      throw()
   {
      // send initial messages
      if ( state_ == gflcs_init )
      {
         send( new LocalizationGPSfreeLCSInitMessage() );
         state_ = gflcs_wait_bc;
      }

      // after idle-time passed, initial messages of neighbors had already been
      // received and state is set to 'broadcast'.
      if ( state_ == gflcs_wait_bc && simulation_round() - last_useful_msg_ > observer().idle_time() )
      {
         state_ = gflcs_broadcast;
         last_useful_msg_ = simulation_round();
      }

      // broadcast collected information
      if ( state_ == gflcs_broadcast )
      {
         broadcast_neighborhood();
         state_ = gflcs_wait_w;
      }

      // after idle-time passed, neighborhood messages of neighbors had already been
      // received and state is set to 'work'.
      if ( state_ == gflcs_wait_w && simulation_round() - last_useful_msg_ > observer().idle_time() )
         state_ = gflcs_work;

      if ( state_ == gflcs_work )
      {
         build_lcs();
         state_ = gflcs_finished;
      }

      // maybe shutdown processor
      if ( simulation_round() - last_useful_msg_ > observer().idle_shutdown_time() )
      {
         state_ = gflcs_finished;
      }
   }
Exemplo n.º 24
0
EXPORT_C void CSTTorrentManager::AddTorrentObserverL(	MSTTorrentObserver* aObserver,
														CSTTorrent* aTorrent,
														TUint32 iEventFlags)
{
	for (TInt i=0; i<iTorrentObservers.Count(); i++)
		if (iTorrentObservers[i].iObserver == aObserver) return;
		
	TSTTorrentObserver observer(aObserver, iEventFlags, aTorrent);
	User::LeaveIfError(iTorrentObservers.Append(observer));
}
Exemplo n.º 25
0
void InternalCleanJob::start()
{
    try {
        ArtifactCleaner cleaner(logger(), observer());
        cleaner.cleanup(project(), products(), m_options);
    } catch (const ErrorInfo &error) {
        setError(error);
    }
    storeBuildGraph();
    emit finished(this);
}
Exemplo n.º 26
0
void DBBaseWidget::setRelationFilter(const QString &name)
{
	if ( m_relationFilter != name ) {
		m_relationFilter = name;
		if ( m_observer != NULL ) {
			m_observer->uninstallWidget(dynamic_cast<QObject *>(this));
			m_observer = NULL;
		}
		observer();
	}
}
NS_IMETHODIMP
nsHttpActivityDistributor::RemoveObserver(nsIHttpActivityObserver *aObserver)
{
    MutexAutoLock lock(mLock);

    ObserverHandle observer(new ObserverHolder(aObserver));
    if (!mObservers.RemoveElement(observer))
        return NS_ERROR_FAILURE;

    return NS_OK;
}
Exemplo n.º 28
0
int main(int argc, char** argv)
{
    // Create the object representing Mercury
    CEPlanet mars = CEPlanet::Mars() ;
    
    // Create an object that always represents the current instantaneous time
    CERunningDate date ;
    
    // Create a default observer, longitude and latitude in degrees. I'm using Ames, IA, USA.
    // Note that longitude is "east-positive" from Greenwich.
    CEObserver observer(-93.62, 42.0347, 287.0, CEAngleType::DEGREES, &date) ;
    
    // Now get the coordinates of the object as a constantly updating 'CEObservation' object
    CEObservation observed_coords(&observer, &mars) ;
    
    /*****************************************************************
     * At this point we're done. Everything below here is just to
     * view the results of the above inputs.
     *****************************************************************/
    
    // Print this information to the screen
    std::printf("\n") ;
    std::printf("OBSERVER INFORMATION\n") ;
    std::printf("   Longitude: %+f\n", observer.Longitude_Deg()) ;
    std::printf("   Latitude : %+f\n", observer.Latitude_Deg()) ;
    std::printf("\nDATE INFORMATION\n") ;
    std::printf("   Julian Date: %+f\n", date.JD());
    std::printf("   Year : %+d\n", date.Year()) ;
    std::printf("   Month: %+d\n", date.Month()) ;
    std::printf("   Day  : %+d\n", date.Day()) ;
    std::printf("   DayFrac: %+f\n", date.DayFraction()) ;
    
    // Print the object information, updated every ~1 second
    
    std::printf("\nOBJECT INFORMATION\n") ;
    std::printf("    JD    | Time UTC |   RA   |  DEC   | Azimuth| Zenith | Altitude\n") ;
    std::printf("----------+----------+--------+--------+--------+--------+----------\n") ;
    double ra, dec, azimuth, zenith ;
    while (true) {
        usleep(1000000) ;
        observed_coords.GetAzimuthZenith_Deg(&azimuth, &zenith) ;
//        observed_coords.GetApparentXYCoordinate_Deg(&ra, &dec) ;

        ra = mars.XCoordinate_Deg() ;
        dec = mars.YCoordinate_Deg() ;
//        CECoordinates::ICRS2CIRS(ra, dec, &ra, &dec,date, CEAngleType::DEGREES) ;
        std::printf("\r %8d | %8.1f |%8.3f|%+8.3f|%8.3f|%8.3f|%8.3f",
                    int(date), date.GetTime(),
                    ra, dec, azimuth, zenith, 90.0-zenith) ;
        std::cout.flush() ;
    }
    
    return 0 ;
}
NS_IMETHODIMP
nsHttpActivityDistributor::AddObserver(nsIHttpActivityObserver *aObserver)
{
    MutexAutoLock lock(mLock);

    ObserverHandle observer(new ObserverHolder(aObserver));
    if (!mObservers.AppendElement(observer))
        return NS_ERROR_OUT_OF_MEMORY;

    return NS_OK;
}
bool AbstractLiveEditTool::topSelectedItemIsMovable(const QList<QGraphicsItem*> &itemList)
{
    QList<QGraphicsItem*> selectedItems = observer()->selectedItems();

    foreach (QGraphicsItem *item, itemList) {
        QDeclarativeItem *declarativeItem = toQDeclarativeItem(item);
        if (declarativeItem
                && selectedItems.contains(declarativeItem)
                /*&& (declarativeItem->qmlItemNode().hasShowContent() || selectNonContentItems)*/)
            return true;
    }