Пример #1
0
void GlobalTickTrigle::update(float delta)
{
	const unsigned int currentTime = ServerTime::getTime();

	// 1.更新通知时间,找出需要通知的对象,移除不需要的对象
	// 不在这里通知,因为通知会触发mTrigles的修改,会崩溃
	vector<TrigleItem> needNotify;
	{
		vector<TrigleItem>::iterator it;
		for (it = mTrigles.begin(); it!= mTrigles.end();)
		{
			it->timeFromLastNotify += delta; // 更新时间

			switch (it->trigle.type)
			{
			case Trigle_Delay:
				// 间隔时间到了,通知.如果不loop,就移除
				if (it->timeFromLastNotify >= it->trigle.time)
				{
					needNotify.push_back((*it));

					it->timeFromLastNotify = 0; // 清空时间
					if (!it->trigle.loop)
					{
						it = mTrigles.erase(it); // 移除
						continue;
					}
				}

				break;
			case Trigle_AtTime:
				// 时间到了就通知,并移除
				if (it->trigle.time >= currentTime)
				{
					needNotify.push_back((*it));
					it->timeFromLastNotify = 0; // 清空,这里可以不需要
					it = mTrigles.erase(it); // 移除
					continue;
				}
				break;
			default:
				CCAssert(false,"");
				break;
			}

			 it++;
		}
	}
	

	postNotification(MSG_GLOBAL_TICK,delta);
	// 2.通知,通知期间可能有新的Item加入,有Item移除
	// 当然这里不用管,因为操作的数据都是mTrigles,而不是needNotify
	for (int i=0,count=needNotify.size(); i<count; i++)
	{
		postNotification(needNotify[i].trigle.notifyMsg.c_str(),needNotify[i].timeFromLastNotify);
	}
}
Пример #2
0
void RAM::update()
{
    size_t oldSize = data.size();
    
    init();
    
    if (size != oldSize)
        postNotification(this, RAM_SIZE_DID_CHANGE, &size);
}
Пример #3
0
void Monitor::notify(OEComponent *sender, int notification, void *data)
{
    if (sender == controlBus)
    {
        powerState = *((ControlBusPowerState *)data);
        
        updateBezel();
    }
    else if (sender == canvas)
        postNotification(sender, notification, data);
}
Пример #4
0
void JoystickMapper::mapNotification(OEInt usageId, float value)
{
    for (JoystickMapperMap::iterator i = usageIdMap.begin();
         i != usageIdMap.end();
         i++)
    {
        if (i->second.usageId == usageId)
        {
            JoystickHIDEvent hidEvent;
            
            hidEvent.deviceId = deviceId;
            hidEvent.usageId = i->first;
            hidEvent.value = value;
            
            switch (i->second.type)
            {
                case JOYSTICKMAPPER_AXIS:
                    hidEvent.value -= 0.5F;
                    if (i->second.reverse)
                        hidEvent.value = -hidEvent.value;
                    hidEvent.value *= powf(10, i->second.sensitivity / 20);
                    hidEvent.value += 0.5F;
                    
                    break;
                    
                case JOYSTICKMAPPER_RELATIVEAXIS:
                    if (i->second.reverse)
                        hidEvent.value = -hidEvent.value;
                    hidEvent.value = i->second.value + hidEvent.value * powf(10, (i->second.sensitivity - 50) / 20);
                    
                    break;
                    
                default:
                    break;
            }
            
            if (hidEvent.value < 0)
                hidEvent.value = 0;
            else if (hidEvent.value > 1)
                hidEvent.value = 1;
            
            if (i->second.value == hidEvent.value)
                return;
            
            i->second.value = hidEvent.value;
            
            postNotification(this, JOYSTICK_DID_CHANGE, &hidEvent);
        }
    }
}
Пример #5
0
void Proxy::notify(OEComponent *sender, int notification, void *data)
{
    postNotification(this, notification, data);
}
Пример #6
0
void MakeTask::processLine(const std::string& line)
{
    postNotification(new Poco::TaskCustomNotification<std::string>(this, line));
}
Пример #7
0
void JoystickMapper::update()
{
    if (inputDevice != oldInputDevice)
    {
        // Build axis and button label
        vector<string> axes;
        vector<string> buttons;
        
        for (JoystickMapperItems::iterator i = items.begin();
             i != items.end();
             i++)
        {
            if (i->inputDevice == inputDevice)
            {
                switch (i->type)
                {
                    case JOYSTICKMAPPER_AXIS:
                    case JOYSTICKMAPPER_RELATIVEAXIS:
                        axes.push_back(i->label);
                        
                        break;
                        
                    case JOYSTICKMAPPER_BUTTON:
                        buttons.push_back(i->label);
                        
                        break;
                        
                    case JOYSTICKMAPPER_UNMAPPED:
                        axes.push_back(i->label);
                        buttons.push_back(i->label);
                        
                        break;
                        
                    default:
                        break;
                }
            }
        }
        
        // Update settings
        DeviceSettings settings;
        
        device->postMessage(this, DEVICE_GET_SETTINGS, &settings);
        
        for (DeviceSettings::iterator i = settings.begin();
             i != settings.end();
             i++)
        {
            if ((i->name.substr(0, 4) == "axis") && (i->type == "select"))
                i->options = strjoin(axes, ',');
            if ((i->name.substr(0, 6) == "button") && (i->type == "select"))
                i->options = strjoin(buttons, ',');
        }
        
        device->postMessage(this, DEVICE_SET_SETTINGS, &settings);
        
        inputDeviceMap[oldInputDevice] = serializeMap();
        
        device->postMessage(this, DEVICE_UPDATE, NULL);
        
        // Load map
        unserializeMap(inputDeviceMap[inputDevice]);
        
        // Reset values
        for (JoystickMapperMap::iterator i = usageIdMap.begin();
             i != usageIdMap.end();
             i++)
        {
            if ((i->second.type == JOYSTICKMAPPER_BUTTON) &&
                (i->second.value))
            {
                i->second.value = false;
                
                JoystickHIDEvent hidEvent;
                
                hidEvent.deviceId = deviceId;
                hidEvent.usageId = i->first;
                hidEvent.value = i->second.value;
                
                postNotification(this, JOYSTICK_DID_CHANGE, &hidEvent);
            }
        }
        
        oldInputDevice = inputDevice;
    }
}
Пример #8
0
    /* ns:      namespace, e.g. <database>.<collection>
       pattern: the "where" clause / criteria
       justOne: stop after 1 match
       god:     allow access to system namespaces, and don't yield
    */
    long long deleteObjects(const char *ns, BSONObj pattern, bool justOne, bool logop, bool god, RemoveSaver * rs ) {
        if( !god ) {
            if ( strstr(ns, ".system.") ) {
                /* note a delete from system.indexes would corrupt the db
                if done here, as there are pointers into those objects in
                NamespaceDetails.
                */
                uassert(12050, "cannot delete from system namespace", legalClientSystemNS( ns , true ) );
            }
            if ( strchr( ns , '$' ) ) {
                log() << "cannot delete from collection with reserved $ in name: " << ns << endl;
                uassert( 10100 ,  "cannot delete from collection with reserved $ in name", strchr(ns, '$') == 0 );
            }
        }

        {
            NamespaceDetails *d = nsdetails( ns );
            if ( ! d )
                return 0;
            uassert( 10101 ,  "can't remove from a capped collection" , ! d->isCapped() );
        }

        long long nDeleted = 0;

        shared_ptr< Cursor > creal = NamespaceDetailsTransient::getCursor( ns, pattern );

        if( !creal->ok() )
            return nDeleted;

        shared_ptr< Cursor > cPtr = creal;
        auto_ptr<ClientCursor> cc( new ClientCursor( QueryOption_NoCursorTimeout, cPtr, ns) );
        cc->setDoingDeletes( true );

        CursorId id = cc->cursorid();

        bool canYield = !god && !(creal->matcher() && creal->matcher()->docMatcher().atomic());

        do {
            // TODO: we can generalize this I believe
            //       
            bool willNeedRecord = (creal->matcher() && creal->matcher()->needRecord()) || pattern.isEmpty() || isSimpleIdQuery( pattern );
            if ( ! willNeedRecord ) {
                // TODO: this is a total hack right now
                // check if the index full encompasses query
                
                if ( pattern.nFields() == 1 && 
                     str::equals( pattern.firstElement().fieldName() , creal->indexKeyPattern().firstElement().fieldName() ) )
                    willNeedRecord = true;
            }
            
            if ( canYield && ! cc->yieldSometimes( willNeedRecord ? ClientCursor::WillNeed : ClientCursor::MaybeCovered ) ) {
                cc.release(); // has already been deleted elsewhere
                // TODO should we assert or something?
                break;
            }
            if ( !cc->ok() ) {
                break; // if we yielded, could have hit the end
            }

            // this way we can avoid calling prepareToYield() every time (expensive)
            // as well as some other nuances handled
            cc->setDoingDeletes( true );

            DiskLoc rloc = cc->currLoc();
            BSONObj key = cc->currKey();

            bool match = creal->currentMatches();

            cc->advance();
            
            if ( ! match )
                continue;

            // SERVER-5198 Advance past the document to be modified, but see SERVER-5725.
            while( cc->ok() && rloc == cc->currLoc() ) {
                cc->advance();
            }
            
            bool foundAllResults = ( justOne || !cc->ok() );

            if ( !foundAllResults ) {
                // NOTE: Saving and restoring a btree cursor's position was historically described
                // as slow here.
                cc->c()->prepareToTouchEarlierIterate();
            }

            {
                BSONElement e;
                if( BSONObj::make( rloc.rec() ).getObjectID( e ) ) {
                    BSONObjBuilder b;
                    b.append( e );
                    bool replJustOne = true;
		    if(logop)
			    logOp( "d", ns, b.done(), 0, &replJustOne );
		    postNotification("d",ns,b.done(),0);
                }
                else {
                    problem() << "deleted object without id, not logging" << endl;
                }
            }

            theDataFileMgr.deleteRecord(ns, rloc.rec(), rloc);
            nDeleted++;
            if ( foundAllResults ) {
                break;
            }
            cc->c()->recoverFromTouchingEarlierIterate();
         
            if( !god ) 
                getDur().commitIfNeeded();

            if( debug && god && nDeleted == 100 ) 
                log() << "warning high number of deletes with god=true which could use significant memory" << endl;
        }
        while ( cc->ok() );

        if ( cc.get() && ClientCursor::find( id , false ) == 0 ) {
            // TODO: remove this and the id declaration above if this doesn't trigger
            //       if it does, then i'm very confused (ERH 06/2011)
            error() << "this should be impossible" << endl;
            printStackTrace();
            cc.release();
        }

        return nDeleted;
    }
Пример #9
0
void DefaultClientTask::handleBufferEvent(const ClientResponseBufferEventArgs& bufferEvent)
{
    postNotification(new Poco::TaskCustomNotification<HTTP::ClientResponseBufferEventArgs>(this, bufferEvent));
}