Beispiel #1
0
// ============================================================================
// Inherited IIncidentSvc overrides:
// ============================================================================
void IncidentSvc::addListener
( IIncidentListener* lis ,
  const std::string& type ,
  long prio, bool rethrow, bool singleShot)
{

  boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);

  std::string ltype;
  if( type == "" ) ltype = "ALL";
  else             ltype = type;
  // find if the type already exists
  ListenerMap::iterator itMap = m_listenerMap.find( ltype );
  if( itMap == m_listenerMap.end() ) {
    // if not found, create and insert now a list of listeners
    ListenerList* newlist = new ListenerList();
    std::pair<ListenerMap::iterator, bool> p;
    p = m_listenerMap.insert(ListenerMap::value_type(ltype, newlist));
    if( p.second ) itMap = p.first;
  }
  ListenerList* llist = (*itMap).second;
  // add Listener in the ListenerList according to the priority
  ListenerList::iterator itlist;
  for( itlist = llist->begin(); itlist != llist->end(); itlist++ ) {
    if( (*itlist).priority < prio ) {
      // We insert before the current position
      break;
    }
  }

  DEBMSG << "Adding [" << type << "] listener '" << getListenerName(lis)
         << "' with priority " << prio << endmsg;

  llist->insert(itlist, Listener(lis, prio, rethrow, singleShot));
}
Beispiel #2
0
	//
	// Manager::getListenerList		- Chapter 10, page 300
	//
	// Get the list of listeners associated with a specific event
	// type
	//
	ListenerList Manager::GetListenerList( TypeId const & eventType ) const
	{
		// invalid event type, so sad
		if ( ! VValidateType( eventType ) )
			return ListenerList();

		EventListenerMap::const_iterator itListeners = m_registry.find( eventType.Value() );

		// no listerners currently for this event type, so sad
		if ( itListeners == m_registry.end() )
			return ListenerList();

		EventListenerTable const & table = itListeners->second;

		// there was, but is not now, any listerners currently for
		// this event type, so sad
		if ( table.size() == 0 )
			return ListenerList();

		ListenerList result;

		result.reserve( table.size() );
	
		for ( EventListenerTable::const_iterator it = table.begin(), end = table.end();
				it != end;
					it++ )
		{
			result.push_back( *it );
		}

		return result;
	}
Beispiel #3
0
void EventManager::broadcastEvent(const Event &event)
{
    do
    {
        if (mListenerMap.empty())
            break;
        
        EventID eid = event.getEventID();
        ListenerList *listenerList = NULL;
        ListenerMap::iterator mapIter = mListenerMap.find(eid);
        
        if (mapIter == mListenerMap.end())
            break;
        
        listenerList = mapIter->second;
        if (listenerList->empty())
            break;
        
        ListenerList::iterator listIter;
        for (listIter = listenerList->begin(); listIter != listenerList->end(); ++listIter)
        {
            (*listIter)->handleEvent(event);
        }
        
    } while (0);
}
Beispiel #4
0
    //-----------------------------------------------------------------------
    void Camera::_renderScene(Viewport *vp, bool includeOverlays)
    {
        OgreProfileBeginGPUEvent("Camera: " + getName());

		//update the pixel display ratio
		if (mProjType == Ogre::PT_PERSPECTIVE)
		{
			mPixelDisplayRatio = (2 * Ogre::Math::Tan(mFOVy * 0.5f)) / vp->getActualHeight();
		}
		else
		{
			mPixelDisplayRatio = (mTop - mBottom) / vp->getActualHeight();
		}

		//notify prerender scene
		ListenerList listenersCopy = mListeners;
		for (ListenerList::iterator i = listenersCopy.begin(); i != listenersCopy.end(); ++i)
		{
			(*i)->cameraPreRenderScene(this);
		}

		//render scene
		mSceneMgr->_renderScene(this, vp, includeOverlays);

		// Listener list may have change
		listenersCopy = mListeners;

		//notify postrender scene
		for (ListenerList::iterator i = listenersCopy.begin(); i != listenersCopy.end(); ++i)
		{
			(*i)->cameraPostRenderScene(this);
		}
        OgreProfileEndGPUEvent("Camera: " + getName());
	}
Beispiel #5
0
void EventManager::removeListener(GameObject *listener)
{
    do
    {
        if (mListenerMap.empty())
            break;
        
        ListenerMap::iterator mapIter = mListenerMap.begin();
        for (; mapIter != mListenerMap.end(); ++mapIter)
        {
            ListenerList *list = mapIter->second;
            if (list == NULL)
                continue;
            
            ListenerList::iterator listIter = list->begin();
            for (; listIter != list->end(); ++listIter)
            {
                if (*listIter == listener)
                {
                    list->erase(listIter);
                    break;
                }
            }
        }
        
    } while (0);
}
Beispiel #6
0
void WeakRef::_notifyDestroy()
{
	incRefCount();

	ListenerList* listeners = _listeners;

	_listeners = NULL; // prevent removeListener mutate this

	if (listeners)
	{
		for (ListenerList::iterator itr = listeners->begin(), end = listeners->end(); itr != end; ++itr)
		{
			(*itr)->onDestroy(_object);
		}

		delete listeners;
	}

	_object = NULL;

	if (_listeners)
	{
		decRefCount();
		NIT_THROW_FMT(EX_INVALID_STATE, "Can't add listener while destroying one");
		return;
	}

	decRefCount();
}
Beispiel #7
0
    //-----------------------------------------------------------------------
    Camera::~Camera()
    {
		ListenerList listenersCopy = mListeners;
		for (ListenerList::iterator i = listenersCopy.begin(); i != listenersCopy.end(); ++i)
		{
			(*i)->cameraDestroyed(this);
		}
    }
void Environment::cleanupUnusedListeners(ListenerList& list)
{
  for(ListenerList::iterator giter = list.begin(); giter != list.end();){
    if((*giter)->isActive() == false){
      giter = list.erase(giter);
    } else ++giter;
  }
}
Beispiel #9
0
// ============================================================================
void IncidentSvc::removeListener
( IIncidentListener* lis  ,
  const std::string& type )
{

  boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);

  if( type == "") {
    // remove Listener from all the lists
    ListenerMap::iterator itmap;
    for ( itmap = m_listenerMap.begin(); itmap != m_listenerMap.end();)
    {
      // since the current entry may be eventually deleted
      // we need to keep a memory of the next index before
      // calling recursively this method
      ListenerMap::iterator itmap_old = itmap;
      itmap++;
      removeListener( lis, (*itmap_old).first );
    }
  }
  else {
    ListenerMap::iterator itmap = m_listenerMap.find( type );

    if( itmap == m_listenerMap.end() ) {
      // if not found the incident type then return
      return;
    }
    else {
      ListenerList* llist = (*itmap).second;
      ListenerList::iterator itlist;
      bool justScheduleForRemoval = ( 0!= m_currentIncidentType )
                                    && (type == *m_currentIncidentType);
      // loop over all the entries in the Listener list
      // to remove all of them than matches
      // the listener address. Remember the next index
      // before erasing the current one
      for( itlist = llist->begin(); itlist != llist->end(); ) {
        if( (*itlist).iListener == lis || lis == 0) {
          if (justScheduleForRemoval) {
            (itlist++)->singleShot = true; // remove it as soon as it is safe
          }
          else {
            DEBMSG << "Removing [" << type << "] listener '"
                   << getListenerName(lis) << "'" << endmsg;
            itlist = llist->erase(itlist); // remove from the list now
          }
        }
        else {
          itlist++;
        }
      }
      if( llist->size() == 0) {
        delete llist;
        m_listenerMap.erase(itmap);
      }
    }
  }
}
bool Environment::stopListener(ListenerList& list, uint32_t id)
{
  for(ListenerList::iterator giter = list.begin(),
    gend = list.end(); giter != gend;
    ++giter)
  {
    if((*giter)->getID() == id && (*giter)->isActive()){
      (*giter)->deactivate();
      return true;
    }
  }
  return false;
}
Beispiel #11
0
void EventManager::removeListenerByEventID(EventID eventID)
{
    if (mListenerMap.empty())
        return;
    
    ListenerMap::iterator mapIter = mListenerMap.find(eventID);
    if (mapIter == mListenerMap.end())
        return;
    
    ListenerList *list = mapIter->second;
    if (list == NULL)
        return;
    
    list->clear();
}
    //---------------------------------------------------------------------
    Viewport::~Viewport()
    {
        ListenerList listenersCopy;
        std::swap(mListeners, listenersCopy);
        for (ListenerList::iterator i = listenersCopy.begin(); i != listenersCopy.end(); ++i)
        {
            (*i)->viewportDestroyed(this);
        }

        RenderSystem* rs = Root::getSingleton().getRenderSystem();
        if ((rs) && (rs->_getViewport() == this))
        {
            rs->_setViewport(NULL);
        }
    }
Beispiel #13
0
void EventManager::addListener(GameObject *listener, EventID eventID)
{
    ListenerMap::iterator mapIter = mListenerMap.find(eventID);
 
    // listener list for eventID is empty, need create first
    if (mapIter == mListenerMap.end())
    {
        ListenerList *newList = new ListenerList;
        mListenerMap.insert(ListenerMap::value_type(eventID, newList));
        newList->push_back(listener);
    }
    else
    {
        (mapIter->second)->push_back(listener);
    }
}
    void MamdaMultiSecurityManager::MamdaMultiSecurityManagerImpl::forwardMsg (
        ListenerList&         listeners,
        MamdaSubscription*    subscription,
        const MamaMsg&        msg,
        short                 msgType)
    {
        ListenerList::iterator end = listeners.end();
        ListenerList::iterator i   = listeners.begin();

        for (; i != end; ++i)
        {
            MamdaMsgListener* listener = *i;

            listener->onMsg (subscription, 
                             msg, 
                             msgType);
        }
    }
Beispiel #15
0
void EventManager::removeAllListeners()
{
    do
    {
        if (mListenerMap.empty())
            break;
        
        ListenerMap::iterator mapIter = mListenerMap.begin();
        for (; mapIter != mListenerMap.end(); ++mapIter)
        {
            ListenerList *list = mapIter->second;
            if (list == NULL)
                continue;
            
            list->clear();
        }
        
    } while (0);
}
Beispiel #16
0
	void Camera::_renderScene(Viewport *vp, BOOL includeOverlays)
	{
		if (mProjType == PT_PERSPECTIVE)
		{
			mPixelDisplayRatio = (2 * Math::Tan((Radian)(mFOVy * 0.5f))) / vp->getActualHeight();
		}
		else
		{
			mPixelDisplayRatio = (mTop - mBottom) / vp->getActualHeight();
		}

		ListenerList listenersCopy = mListeners;
		for (ListenerList::iterator i = listenersCopy.begin(); i != listenersCopy.end(); ++i)
		{
			(*i)->cameraPreRenderScene(this);
		}
		mSceneMgr->renderScene(this, vp, includeOverlays);
		listenersCopy = mListeners;

		for (ListenerList::iterator i = listenersCopy.begin(); i != listenersCopy.end(); ++i)
		{
			(*i)->cameraPostRenderScene(this);
		}
	}
Beispiel #17
0
// ============================================================================
void IncidentSvc::i_fireIncident
( const Incident&    incident     ,
  const std::string& listenerType )
{

  boost::recursive_mutex::scoped_lock lock(m_listenerMapMutex);

  // Special case: FailInputFile incident must set the application return code
  if (incident.type() == IncidentType::FailInputFile
      || incident.type() == IncidentType::CorruptedInputFile) {
    SmartIF<IProperty> appmgr(serviceLocator());
    if (incident.type() == IncidentType::FailInputFile)
      // Set the return code to Gaudi::ReturnCode::FailInput (2)
      Gaudi::setAppReturnCode(appmgr, Gaudi::ReturnCode::FailInput).ignore();
    else
      Gaudi::setAppReturnCode(appmgr, Gaudi::ReturnCode::CorruptedInput).ignore();
  }

  ListenerMap::iterator itmap = m_listenerMap.find( listenerType );
  if ( m_listenerMap.end() == itmap ) return;

  // setting this pointer will avoid that a call to removeListener() during
  // the loop triggers a segfault
  m_currentIncidentType = &(incident.type());

  ListenerList* llist = (*itmap).second;
  ListenerList::iterator itlist;
  bool weHaveToCleanUp = false;
  // loop over all registered Listeners

    for( itlist = llist->begin(); itlist != llist->end(); itlist++ )
  {

    VERMSG << "Calling '" << getListenerName((*itlist).iListener)
           << "' for incident [" << incident.type() << "]" << endmsg;

    // handle exceptions if they occur
    try {
      (*itlist).iListener->handle(incident);
    }
    catch( const GaudiException& exc ) {
      error() << "Exception with tag=" << exc.tag() << " is caught"
                 " handling incident" << m_currentIncidentType << endmsg;
      error() <<  exc  << endmsg;
      if ( (*itlist).rethrow ) { throw (exc); }
    }
    catch( const std::exception& exc ) {
     error() << "Standard std::exception is caught"
          " handling incident" << m_currentIncidentType << endmsg;
      error() << exc.what()  << endmsg;
      if ( (*itlist).rethrow ) { throw (exc); }
    }
    catch(...) {
      error() << "UNKNOWN Exception is caught"
          " handling incident" << m_currentIncidentType << endmsg;
      if ( (*itlist).rethrow ) { throw; }
    }
    // check if at least one of the listeners is a one-shot
    weHaveToCleanUp |= itlist->singleShot;
  }
  if (weHaveToCleanUp) {
    // remove all the listeners that need to be removed from the list
    llist->remove_if( listenerToBeRemoved() );
    // if the list is empty, we can remove it
    if( llist->size() == 0) {
      delete llist;
      m_listenerMap.erase(itmap);
    }
  }

  m_currentIncidentType = 0;
}
Beispiel #18
0
void EventManager<T>::temporary_processEventQueue(AbsTime forceCompletionBy) {
	AbsTime startTime = AbsTime::now();
	SILOG(task,insane," >>> Processing events.");

	// swaps to allow people to keep adding new events
	typename EventList::NodeIterator processingList(mUnprocessed);

	// The events are swapped first to guarantee that listeners are at least as up-to-date as events.
	// Events can be delayed, but we cannot allow any lost subscriptions/unsubscriptions.

	{
		typename ListenerRequestList::NodeIterator procListeners(mListenerRequests);

		const ListenerRequest *req;
		while ((req = procListeners.next()) != NULL) {
			if (req->subscription) {
				SILOG(task,debug," >>>\tDoing subscription listener "<< req->listenerId << " for event " << req->eventId << " (" << req->onlyPrimary <<  ").");
				doSubscribeId(*req);
			} else {
				SILOGNOCR(task,debug," >>>\t");
				if (req->notifyListener) {
					SILOGNOCR(task,debug,"Notifying");
				}
				SILOG(task,debug,"UNSUBSCRIBED listener " << req->listenerId << ".");
				doUnsubscribe(req->listenerId, req->notifyListener);
			}
		}
	}

	if (SILOGP(task,insane)){
		SILOG(task,insane,"==== All Event Subscribers for " << (intptr_t)this << " ====");
		typename PrimaryListenerMap::const_iterator priIter =
			mListeners.begin();
		while (priIter != mListeners.end()) {
			SILOG(task,insane,"  ID " << (*priIter).first << ":");
			PartiallyOrderedListenerList *primaryLists =
				&((*priIter).second->first);
			SecondaryListenerMap *secondaryMap =
				&((*priIter).second->second);

			for (int i = 0; i < NUM_EVENTORDER; i++) {
				ListenerList *currentList = &(primaryLists->get(i));
				for (typename ListenerList::const_iterator iter = currentList->begin();
						iter != currentList->end(); ++iter) {
					SILOG(task,insane," \t"
						"[" << (i==MIDDLE?'=':i<MIDDLE?'*':'/') << "] " <<
						(*iter).second);
				}
			}

			typename SecondaryListenerMap::const_iterator secIter;
			secIter = secondaryMap->begin();
			while (secIter != secondaryMap->end()) {
				SILOG(task,insane,"\tSec ID " << (*secIter).first << ":");
				for (int i = 0; i < NUM_EVENTORDER; i++) {
					ListenerList *currentList = &((*secIter).second->get(i));
					for (typename ListenerList::const_iterator iter = currentList->begin();
							iter != currentList->end(); ++iter) {
						SILOG(task,insane," \t\t"
							"[" << (i==MIDDLE?'=':i<MIDDLE?'*':'/') << "] " <<
							(*iter).second);
					}
				}
				++secIter;
			}
			++priIter;
		}
		SILOG(task,insane,"==== ---------------------------------- ====");
	}

	EventPtr *evTemp;
	int numProcessed = 0;

	while ((evTemp = processingList.next())!=NULL) {
		EventPtr ev (*evTemp);
		++numProcessed;

		typename PrimaryListenerMap::iterator priIter =
			mListeners.find(ev->getId().mPriId);
		if (priIter == mListeners.end()) {
			// FIXME: Should this ever happen?
			SILOG(task,warning," >>>\tWARNING: No listeners for type " <<
                  "event type " << ev->getId().mPriId);
			continue;
		}

		PartiallyOrderedListenerList *primaryLists =
			&((*priIter).second->first);
		SecondaryListenerMap *secondaryMap =
			&((*priIter).second->second);

		typename SecondaryListenerMap::iterator secIter;
		secIter = secondaryMap->find(ev->getId().mSecId);

        bool cancel = false;
        EventHistory eventHistory=EVENT_UNHANDLED;
		// Call once per event order.
		for (int i = 0; i < NUM_EVENTORDER && cancel == false; i++) {
			SILOG(task,debug," >>>\tFiring " << ev << ": " << ev->getId() <<
                  " [order " << i << "]");
			ListenerList *currentList = &(primaryLists->get(i));
			if (!currentList->empty())
				eventHistory=EVENT_HANDLED;
			if (callAllListeners(ev, currentList, forceCompletionBy)) {
				cancel = cancel || true;
			}

			if (secIter != secondaryMap->end() &&
					!(*secIter).second->get(i).empty()) {
				currentList = &((*secIter).second->get(i));
				if (!currentList->empty())
					eventHistory=EVENT_HANDLED;

				if (callAllListeners(ev, currentList, forceCompletionBy)) {
					cancel = cancel || true;
				}
				// all listeners may have returned false.
				// cleanUp(secondaryMap, secIter);
				// secIter = secondaryMap->find(ev->getId().mSecId);
			}

			if (cancel) {
				SILOG(task,debug," >>>\tCancelling " << ev->getId());
			}
		}
		if (secIter != secondaryMap->end()) {
			cleanUp(secondaryMap, secIter);
		}

        if (cancel) eventHistory=EVENT_CANCELED;
        (*ev)(eventHistory);
		SILOG(task,debug," >>>\tFinished " << ev->getId());
	}

	if (mEventCV) {
		mPendingEvents -= numProcessed;
	}

	AbsTime finishTime = AbsTime::now();
	SILOG(task,insane, "**** Done processing events this round. " <<
          "Took " << (finishTime-startTime).toSeconds() <<
		" seconds.");
}