Exemplo n.º 1
0
Qtilities::Core::QtilitiesCategory Qtilities::CoreGui::Command::category() const {
    Observer* obs = OBJECT_MANAGER->observerReference(d_category_context);
    if (obs) {
        QVariant category_variant = obs->getMultiContextPropertyValue(this,qti_prop_CATEGORY_MAP);
        if (category_variant.isValid()) {
            return category_variant.value<QtilitiesCategory>();
        }
    }
    return QtilitiesCategory();
}
bool GlobalAgentSubjectInterf::kill(int id)
{
    Observer * obs = getObserverById(id);
    detach(obs);

    if (!obs)
        return false;

    //if ((obs->getObserverType() != TObsMap) && (obs->getObserverType() != TObsImage))
    //    detachObserver(obs);

    switch (obs->getType())
    {
        case TObsLogFile:
           ((ObserverLogFile *)obs)->close();
            delete(ObserverLogFile *)obs;
            break;

        case TObsTable:
           ((ObserverTable *)obs)->close();
            delete(ObserverTable *)obs;
            break;

        case TObsGraphic:
        case TObsDynamicGraphic:
           ((ObserverGraphic *)obs)->close();
            delete(ObserverGraphic *)obs;
            break;

        case TObsUDPSender:
           ((ObserverUDPSender *)obs)->close();
            delete(ObserverUDPSender *)obs;
            break;

        case TObsTextScreen:
           ((ObserverTextScreen *)obs)->close();
            delete(ObserverTextScreen *)obs;
            break;

        case TObsStateMachine:
           ((ObserverStateMachine *)obs)->close();
            delete(ObserverStateMachine *)obs;
            break;

        //case TObsMap:
        //   ((AgentObserverMap *)obs)->unregistry(this);
        //    break;

        default:
            delete obs;
            break;
    }
    obs = 0;
    return true;
}
void RadiantSelectionSystem::notifyObservers(const scene::INodePtr& node, bool isComponent) {

    // Cycle through the list of observers and call the moved method
    for (ObserverList::iterator i = _observers.begin(); i != _observers.end(); ++i) {
        Observer* observer = *i;

        if (observer != NULL) {
            observer->selectionChanged(node, isComponent);
        }
    }
}
void Qtilities::CoreGui::ObjectHierarchyNavigator::setNavigationStack(QStack<int> navigation_stack) {
    // First disconnect all connections to the current stack
    Observer* observer = 0;
    for (int i = 0; i < d_navigation_stack.count(); i++) {
        observer = OBJECT_MANAGER->observerReference(d_navigation_stack.at(i));
        observer->disconnect(this);
    }

    d_navigation_stack = navigation_stack;
    refreshHierarchy();
}
Exemplo n.º 5
0
void JsonItem::notifyMemberUnset(JsonObject *object, const String *name) const
{
	const JsonItem *item = this;
	do {
		for (Observer *o = item->mObservers.first(); o; o = item->mObservers.next(o)) {
			o->memberUnset(object, name);
		}
		item = item->mParent;
	} while (item);

}
Exemplo n.º 6
0
void RadiantSelectionSystem::notifyObservers() {

	// Cycle through the list of observers and call the moved method
	for (ObserverList::iterator i = _observers.begin(); i != _observers.end(); i++) {
		Observer* observer = *i;

		if (observer != NULL) {
			observer->selectionChanged();
		}
	}
}
Exemplo n.º 7
0
void Calendar::notifyIncidenceDeleted(Incidence *i)
{
    if(!mObserversEnabled)
        return;

    Observer *observer;
    for(observer = mObservers.first(); observer;
            observer = mObservers.next())
    {
        observer->calendarIncidenceDeleted(i);
    }
}
Exemplo n.º 8
0
bool CellSpaceSubjectInterf::kill(int id)
{
    Observer * obs = getObserverById(id);
    detach(obs);

    if (! obs)
        return false;

    switch (obs->getType())
    {
        case TObsTextScreen:
            ((ObserverTextScreen *)obs)->close();
            delete (ObserverTextScreen *)obs;
            break;

        case TObsLogFile:
            ((ObserverLogFile *)obs)->close();
            delete (ObserverLogFile *)obs;
            break;

        case TObsTable:
            ((ObserverTable *)obs)->close();
            delete (ObserverTable *)obs;
            break;

        case TObsDynamicGraphic:
        case TObsGraphic:
            ((ObserverGraphic *)obs)->close();
            delete (ObserverGraphic *)obs;
            break;

        case TObsUDPSender:
            ((ObserverUDPSender *)obs)->close();
            delete (ObserverUDPSender *)obs;
            break;

        case TObsMap:
            ((AgentObserverMap *)obs)->close();
            delete (AgentObserverMap *)obs;
            break;

        case TObsImage:
            ((AgentObserverImage *)obs)->close();
            delete (AgentObserverImage *)obs;
            break;

        default:
            delete obs;
            break;
    }
    obs = 0;
    return true;
}
Exemplo n.º 9
0
	void Timer::notifyObservers(sf::Time oldPosition, sf::Time newPosition, bool alreadySeeked)
	{
		CHECK(getStatus() != Playing, "inconsistency in timer");
		
		std::set<Observer*>::iterator it;
		for (it = m_observers.begin(); it != m_observers.end(); it++) {
			Observer* obs = *it;
			
			if (alreadySeeked)
				obs->didSeek(*this, oldPosition);
			else
				obs->willSeek(*this, newPosition);
		}
	}
Exemplo n.º 10
0
//---------------------------------------------------------------------------------------
void EventsDispatcher::dispatch_next_event()
{
    pair<SpEventInfo, Observer*> event;

    {
        QueueLock lock(m_mutex);
        event = m_events.front();
        m_events.pop();
    }

    SpEventInfo pEvent = event.first;
    Observer* pObserver = event.second;
    pObserver->notify(pEvent);
}
Exemplo n.º 11
0
void Calendar::setModified(bool modified)
{
    if(modified != mModified || mNewObserver)
    {
        mNewObserver = false;
        Observer *observer;
        for(observer = mObservers.first(); observer;
                observer = mObservers.next())
        {
            observer->calendarModified(modified, this);
        }
        mModified = modified;
    }
}
Exemplo n.º 12
0
	void Timer::notifyObservers(Status futureStatus)
	{
		std::set<Observer*>::iterator it;
		for (it = m_observers.begin(); it != m_observers.end(); it++) {
			Observer* obs = *it;
			
			switch(futureStatus) {
				case Playing:
					obs->willPlay(*this);
					break;
					
				default:
					CHECK(false, "Timer::notifyObservers() - unhandled case in switch");
			}
		}
	}
Exemplo n.º 13
0
    TEST_FIXTURE(DocumentEventsTestFixture, AddHandler_CPP)
    {
        SpDocument spDoc( new MyDocument(m_libraryScope) );
        spDoc->create_empty();
        ImoParagraph* pPara = spDoc->add_paragraph();
        ImoLink* pLink = pPara->add_link("Click me");

        MyEventHandlerCPP handler;
        pLink->add_event_handler(k_on_click_event, &handler);

        MyDocument* pDoc = static_cast<MyDocument*>( spDoc.get() );
        std::list<Observer*> observers = pDoc->my_get_observers();
        CHECK( observers.size() == 1 );
        Observer* pObserver = observers.front();
        CHECK( pObserver->target() == pLink );
    }
Exemplo n.º 14
0
void Subject::removeObserver(Observer& observer, EventID eventID) {
    _private->registerEventsIfNeeded(*this);

    size_t removalCount = 0;
    if (eventID == EventID::All) {
        for (auto& observers : _private->observers) {
            removalCount += observers.second.erase(&observer);
        }
    }
    else {
        auto observers = _private->observers.find(eventID);
        OXFEDEAssert(observers != _private->observers.end(),
                     "\nReason:\tattempted to remove an observer for an unregistered event." <<
                     "\nSubject:\t" << *this <<
                     "\nObserver:\t" << observer <<
                     "\nEvent:\t" << eventID);

        removalCount = observers->second.erase(&observer);
    }

    OXFEDEAssert(removalCount,
                 "\nReason:\tattempted to remove an observer not observing an event." <<
                 "\nSubject:\t" << *this <<
                 "\nObserver:\t" << observer <<
                 "\nEvent:\t" << eventID);

    Registration e;
    e.state = Registration::State::Unregistered;
    e.subject = this;

    for (int i = 0; i < removalCount; i++) {
        observer.onEvent(e);
    }
}
Exemplo n.º 15
0
void Qtilities::CoreGui::ObjectScopeWidget::handle_actionDetachToSelection_triggered() {
    // Get the ids of all unselected items
    QList<int> other_ids;
    int selected_id = ui->observerTable->currentItem()->type();
    for (int i = 0; i < ui->observerTable->rowCount(); i++) {
        if (selected_id != ui->observerTable->item(i,0)->type())
            other_ids << ui->observerTable->item(i,0)->type();
    }

    QStringList unsupported_items;
    for (int i = 0; i < other_ids.count(); i++) {
        Observer* observer = OBJECT_MANAGER->observerReference(other_ids.at(i));
        if (!observer)
            break;

        if (observer->displayHints()) {
            if (!(observer->displayHints()->actionHints() & ObserverHints::ActionRemoveItem)) {
                unsupported_items << observer->observerName();
            }
        } else {
            unsupported_items << observer->observerName();
        }
    }

    if (unsupported_items.count() > 0)  {
        QMessageBox msgBox;
        msgBox.setText(tr("All other contexts does not support removing of child items."));
        msgBox.setInformativeText(tr("Do you want to continue and remove the contexts which does support this?"));
        msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        msgBox.setDefaultButton(QMessageBox::Yes);
        int ret = msgBox.exec();

        switch (ret) {
           case QMessageBox::No:
               return;
           default:
               break;
        }
    }

    for (int i = 0; i < other_ids.count(); i++) {
        Observer* observer = OBJECT_MANAGER->observerReference(other_ids.at(i));
        if (!observer)
            break;

        if (observer->displayHints()) {
            if (observer->displayHints()->actionHints() & ObserverHints::ActionRemoveItem) {
                observer->detachSubject(d->obj);
            }
        }
    }
}
Exemplo n.º 16
0
void Qtilities::CoreGui::ObjectScopeWidget::handle_actionRemoveContext_triggered() {
    // Get the current selected observer
    int id = ui->observerTable->currentItem()->type();
    Observer* observer = OBJECT_MANAGER->observerReference(id);
    if (!observer)
        return;

    if (observer->displayHints()) {
        // Check if a detach operation is supported by this observer.
        if (observer->displayHints()->actionHints() & ObserverHints::ActionRemoveItem)
            observer->detachSubject(d->obj);
        else {
            QMessageBox msgBox;
            msgBox.setText(tr("The selected context does not support removing of child items. The operation cannot continue."));
            msgBox.exec();
        }
    }
}
Exemplo n.º 17
0
 static float_sylph_t get_corrected_ITOW(const Observer &observer){
   float_sylph_t raw_itow(observer.fetch_ITOW());
   if(options.reduce_1pps_sync_error){
     static float_sylph_t previous_itow(0);
     float_sylph_t delta_t(raw_itow - previous_itow);
     if((delta_t >= 1) && (delta_t < 2)){
       raw_itow -= 1;
     }
     previous_itow = raw_itow;
   }
   return raw_itow;
 }
Exemplo n.º 18
0
/**
*  Main
*  creates executable that takes periodic snapshots of kernel's state for a
*  given interval It takes command-line arguments, period and
*  interval respectivley
*/
int main(int argc, char** argv){
    //Check for correct user input
    if(argc != 3){
        cout << "Usage: " << argv[0] << "<period><interval>\n";
        exit(-2);
    }

    //Converts char's to int values
    int period = atoi(argv[1]);
    int interval = atoi(argv[2]);

    //declare the Obeserver struct
    Observer observer;

    //Reports the snapshot
    for(int i = 0; i != interval/period; ++i){
        observer.report();
        sleep(period);
    }

    return 0;
}
Exemplo n.º 19
0
int luaTrajectory::kill(lua_State *luaL)
{
    int id = luaL_checknumber(luaL, 1);
    bool result = false;

    result = TrajectorySubjectInterf::kill(id);

    if (!result)
    {
        if (cellSpace)
        {
            Observer *obs = cellSpace->getObserverById(id);

            if (obs)
            {
                if (obs->getType() == TObsMap)
                    result =((AgentObserverMap *)obs)->unregistry(this);
            }
        }
    }
    lua_pushboolean(luaL, result);
    return 1;
}
Exemplo n.º 20
0
void Qtilities::Testing::TestObserver::testOwnershipObserverScope() {
    LOG_INFO("TestObserver::testOwnershipObserverScope() start:");

    // Create the observers
    Observer* observerA = new Observer("Observer A");
    Observer* observerB = new Observer("Observer B");

    // Create the objects
    QPointer<QObject> object1 = new QObject();
    object1->setObjectName("Object 1");
    QPointer<QObject> object2 = new QObject();
    object2->setObjectName("Object 2");

    // Attach objects to observers
    observerA->attachSubject(object1,Observer::ObserverScopeOwnership);
    observerA->attachSubject(object2,Observer::ObserverScopeOwnership);
    observerB->attachSubject(object1,Observer::ObserverScopeOwnership);
    observerB->attachSubject(object2,Observer::ObserverScopeOwnership);

    // Now delete observer A
    delete observerA;
    QApplication::processEvents();

    // Check the validity of the objects:
    QVERIFY(object1 != 0);
    QVERIFY(object2 != 0);

    // Now delete observer B
    delete observerB;
    QApplication::processEvents();

    // Check the validity of the objects:
    QVERIFY(object1 == 0);
    QVERIFY(object2 == 0);

    LOG_INFO("TestObserver::testOwnershipObserverScope() end.");
}
Exemplo n.º 21
0
void Subject::addObserver(Observer& observer, EventID eventID) {
    _private->registerEventsIfNeeded(*this);

    auto observers = _private->observers.find(eventID);
    OXFEDEAssert(observers != _private->observers.end(),
                 "\nReason:\tattempted to add an observer for an unregistered event." <<
                 "\nSubject:\t" << *this <<
                 "\nObserver:\t" << observer <<
                 "\nEvent:\t" << eventID);

    bool observerIsNotAlreadyObserving = observers->second.insert(&observer).second;
    OXFEDEAssert(observerIsNotAlreadyObserving,
                 "\nReason:\tattempted to add an observer for an event it is already observing." <<
                 "\nSubject:\t" << *this <<
                 "\nObserver:\t" << observer <<
                 "\nEvent:\t" << eventID);

    Registration e;
    e.state = Registration::State::Registered;
    e.subject = this;

    observer.onEvent(e);
}
Exemplo n.º 22
0
    void PersonPassedThrough(const InterfaceDescription::Member* member, const char* path, Message& message) {
        QCC_UNUSED(member);

        char* name;
        string location;
        QStatus status = message->GetArgs("s", &name);
        if (ER_OK == status) {
            bus->EnableConcurrentCallbacks();
            DoorProxy door(observer->Get(message->GetSender(), path), *bus);
            if (door.IsValid()) {
                status = door.GetLocation(location);
            } else {
                cerr << "Received a signal from a door we don't know." << endl;
                status = ER_FAIL;
            }
        }
        if (ER_OK == status) {
            cout << "[listener] " << name << " passed through a door "
                 << "@location " << location << endl;
            cout << "> ";
            cout.flush();
        }
    }
Exemplo n.º 23
0
 static void apply(Observer& obs, const boost::system::error_code& error)
 {
   obs.connection_failure(error);
 }
Exemplo n.º 24
0
 static void apply(Observer& obs, const std::shared_ptr<Socket>& socket)
 {
   obs.connection_success(socket);
 }
Exemplo n.º 25
0
 static void apply(Observer& obs, std::string ip_address)
 {
   obs.try_connecting_with_ip(std::move(ip_address));
 }
Exemplo n.º 26
0
//---------------------------------------------------------------------------------------
void EventNotifier::add_handler(Observable* pSource, int eventType,
                                void (*pt2Func)(SpEventInfo event) )
{
    Observer* observer = add_observer_for(pSource);
    observer->add_handler(eventType, pt2Func);
}
Exemplo n.º 27
0
//---------------------------------------------------------------------------------------
void EventNotifier::add_handler(Observable* pSource, int eventType,
                                EventHandler* pHandler)
{
    Observer* observer = add_observer_for(pSource);
    observer->add_handler(eventType, pHandler);
}
void ChatManagerImplementation::broadcastMessage(CreatureObject* player, const UnicodeString& message,  uint64 target, uint32 moodid, uint32 mood2) {
	Zone* zone = player->getZone();
	PlayerObject* myGhost = NULL;
	bool godMode = false;

	if (zone == NULL)
		return;

	int language = 0;
	String firstName;

	if (player->isPlayerCreature() /*|| !((Player *)player)->isChatMuted() */) {
		CreatureObject* playerCreature = cast<CreatureObject*>(player);
		if (playerCreature)
		{
			firstName = playerCreature->getFirstName().toLowerCase();
			myGhost = playerCreature->getPlayerObject();
		}

		if (myGhost)
			language = myGhost->getLanguageID();
	}

	if (myGhost)
	{
		if (myGhost->hasGodMode())
			godMode = true;
	}

	StringIdChatParameter* param = NULL;

	if (message[0] == '@' && message.indexOf(":") != -1) {
		param = new StringIdChatParameter(message.toString());
	}

	CloseObjectsVector* closeObjects = (CloseObjectsVector*) player->getCloseObjects();

	SortedVector<QuadTreeEntry*> closeEntryObjects(200, 50);

	if (closeObjects != NULL) {
		closeObjects->safeCopyTo(closeEntryObjects);
	} else {
		player->info("Null closeobjects vector in ChatManager::broadcastMessage", true);
		zone->getInRangeObjects(player->getWorldPositionX(), player->getWorldPositionY(), 128, &closeEntryObjects, true);
	}

	float range = defaultSpatialChatDistance;

	float specialRange = spatialChatDistances.get(mood2);
	if (specialRange != -1) {
		range = specialRange;
	}

	try {
		for (int i = 0; i < closeEntryObjects.size(); ++i) {
			SceneObject* object = cast<SceneObject*>(closeEntryObjects.get(i));

			if (player->isInRange(object, range)) {

				//Notify observers that are expecting spatial chat.
				if (object->getObserverCount(ObserverEventType::SPATIALCHATRECEIVED)) {
					ManagedReference<ChatMessage*> chatMessage = new ChatMessage();
					chatMessage->setString(message.toString());

					EXECUTE_TASK_3(object, chatMessage, player, {
						if (player_p == NULL || object_p == NULL)
							return;

						Locker locker(object_p);

						SortedVector<ManagedReference<Observer*> > observers = object_p->getObservers(ObserverEventType::SPATIALCHATRECEIVED);
						for (int oc = 0; oc < observers.size(); oc++) {
							Observer* observer = observers.get(oc);
							Locker clocker(observer, object_p);
							if (observer->notifyObserverEvent(ObserverEventType::SPATIALCHATRECEIVED, object_p, chatMessage_p, player_p->getObjectID()) == 1)
								object_p->dropObserver(ObserverEventType::SPATIALCHATRECEIVED, observer);
						}
					});
				}

				if (object->isPlayerCreature()) {
					CreatureObject* creature = cast<CreatureObject*>(object);
					PlayerObject* ghost = creature->getPlayerObject();

					if (ghost == NULL)
						continue;

					if (!ghost->isIgnoring(firstName) || godMode) {
						SpatialChat* cmsg = NULL;

						if (param == NULL) {
							cmsg = new SpatialChat(player->getObjectID(), creature->getObjectID(), message, target, moodid, mood2, language);
						} else {
							cmsg = new SpatialChat(player->getObjectID(), creature->getObjectID(), *param, target, moodid, mood2);
						}

						creature->sendMessage(cmsg);
					}
				}
				else if( object->isPet() ){
					AiAgent* pet = cast<AiAgent*>(object);

					if (pet == NULL )
						continue;

					if( pet->isDead() || pet->isIncapacitated() )
						continue;

					PetManager* petManager = server->getPetManager();
					Locker clocker(pet, player);
					petManager->handleChat( player, pet, message.toString() );

				}
			}
		}
Exemplo n.º 29
0
JsonItem::~JsonItem()
{
	for (Observer *o = mObservers.first(); o; o = mObservers.next(o)) {
		o->itemDeleted(this);
	}
}
Exemplo n.º 30
-1
void JsonItem::notifyElementInserted(JsonArray *array, int index) const
{
	const JsonItem *item = this;
	do {
		for (Observer *o = item->mObservers.first(); o; o = item->mObservers.next(o)) {
			o->elementInserted(array, index);
		}
		item = item->mParent;
	} while (item);
}