OpenASIP  2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Informer Class Reference

#include <Informer.hh>

Inheritance diagram for Informer:
Inheritance graph
Collaboration diagram for Informer:
Collaboration graph

Public Member Functions

 Informer ()
 
virtual ~Informer ()
 
void handleEvent (int event)
 
virtual bool registerListener (int event, Listener *listener)
 
virtual bool unregisterListener (int event, Listener *listener)
 

Private Types

typedef std::vector< std::pair< int, Listener * > > ListenerList
 

Private Member Functions

std::size_t findListenerSlot (int event, Listener *listener)
 

Private Attributes

ListenerList eventListeners_
 

Detailed Description

The Informer class delivers notifications of events (represented by integers) to Listeners.

A Listener can register to be notified of certain event(s) and will thereafter receive a notification every time the event takes place. Naturally, a Listener can also be unregistered to not receive any more notifications of the event.

Definition at line 52 of file Informer.hh.

Member Typedef Documentation

◆ ListenerList

typedef std::vector<std::pair<int, Listener*> > Informer::ListenerList
private

Definition at line 64 of file Informer.hh.

Constructor & Destructor Documentation

◆ Informer()

Informer::Informer ( )

Constructor.

Definition at line 44 of file Informer.cc.

44  {
45 }

◆ ~Informer()

Informer::~Informer ( )
virtual

Destructor.

Definition at line 51 of file Informer.cc.

51  {
52 }

Member Function Documentation

◆ findListenerSlot()

std::size_t Informer::findListenerSlot ( int  event,
Listener listener 
)
inlineprivate

Finds the event slot for the given listener listening to the given event.

In case the listener is not found, it's added to the list and index of it is returned.

Parameters
eventEvent the listener is listening to.
listenerThe listener.
Returns
The index of the event slot.

Definition at line 65 of file Informer.cc.

65  {
66  for (std::size_t i = 0; i < eventListeners_.size(); ++i) {
67  if (eventListeners_.at(i).first == event &&
68  eventListeners_.at(i).second == listener) {
69  return i;
70  }
71  }
72  eventListeners_.push_back(std::make_pair(event, listener));
73  return eventListeners_.size() - 1;
74 }

References eventListeners_.

Referenced by registerListener(), and unregisterListener().

◆ handleEvent()

void Informer::handleEvent ( int  event)

◆ registerListener()

bool Informer::registerListener ( int  event,
Listener listener 
)
virtual

Adds the given Listener to the list of listeners of the given event.

After this function has been called, the listener will be notified every time the event occurs.

Parameters
eventThe code identifying the event.
listenerThe Listener that should be added.
Returns
'True' if adding of the listener succeeds, 'false' otherwise.

Definition at line 87 of file Informer.cc.

87  {
88  findListenerSlot(event, listener);
89  return true;
90 }

References findListenerSlot().

Referenced by StopPointManager::add(), BusTracker::BusTracker(), ExecutionTracker::ExecutionTracker(), ProximSimulationThread::initialize(), ProcedureTransferTracker::ProcedureTransferTracker(), ProximRuntimeErrorHandler::ProximRuntimeErrorHandler(), SimpleSimulatorFrontend::registerEventListener(), RFAccessTracker::RFAccessTracker(), RuntimeErrorReporter::RuntimeErrorReporter(), and RFAccessTracker::~RFAccessTracker().

Here is the call graph for this function:

◆ unregisterListener()

bool Informer::unregisterListener ( int  event,
Listener listener 
)
virtual

Removes the given Listener from the list of listeners of the given event.

After this function has been called, the listener will not be notified that the event has occurred.

Parameters
eventThe code identifying the event.
listenerThe Listener that should be removed.
Returns
'True' if removing the listener succeeds, 'false' otherwise.

Definition at line 104 of file Informer.cc.

104  {
105  std::size_t index = findListenerSlot(event, listener);
106  ListenerList::iterator i = eventListeners_.begin() + index;
107  eventListeners_.erase(i);
108  return true;
109 }

References eventListeners_, and findListenerSlot().

Referenced by StopPointManager::deleteStopPoint(), SimpleSimulatorFrontend::unregisterEventListener(), BusTracker::~BusTracker(), ExecutionTracker::~ExecutionTracker(), ProcedureTransferTracker::~ProcedureTransferTracker(), ProximRuntimeErrorHandler::~ProximRuntimeErrorHandler(), RFAccessTracker::~RFAccessTracker(), and RuntimeErrorReporter::~RuntimeErrorReporter().

Here is the call graph for this function:

Member Data Documentation

◆ eventListeners_

ListenerList Informer::eventListeners_
private

Definition at line 65 of file Informer.hh.

Referenced by findListenerSlot(), and unregisterListener().


The documentation for this class was generated from the following files:
Informer::eventListeners_
ListenerList eventListeners_
Definition: Informer.hh:65
Informer::findListenerSlot
std::size_t findListenerSlot(int event, Listener *listener)
Definition: Informer.cc:65