Garmin Fleet Management Controller  2.19.0
Event.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * Event.cpp
5 *
6 * Copyright 2008-2009 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "stdafx.h"
12 #include <algorithm>
13 
14 #include "Event.h"
15 #include "EventListener.h"
16 
17 std::list<EventListener*> Event::mListeners;
18 
19 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
24  (
25  EventListener * aTarget
26  )
27 {
28  // Precondition: aTarget must not be in the list
29  ASSERT( aTarget != NULL );
30  ASSERT( find( mListeners.begin(), mListeners.end(), aTarget ) == mListeners.end() );
31 
32  mListeners.push_back( aTarget );
33 }
34 
35 //----------------------------------------------------------------------
38 //----------------------------------------------------------------------
40  (
41  EventListener * aTarget
42  )
43 {
44  ASSERT( aTarget != NULL );
45 
46  std::list<EventListener*>::iterator iter;
47 
48  // Precondition: aTarget must be in the event target list
49  iter = find( mListeners.begin(), mListeners.end(), aTarget );
50  ASSERT( iter != mListeners.end() );
51 
52  mListeners.erase( iter );
53 }
54 
55 //----------------------------------------------------------------------
65 //----------------------------------------------------------------------
66 void Event::post
67  (
68  EventId aEventId,
69  uint32 aEventData,
70  void * aEventDataPtr,
71  BOOL handleNow
72  )
73 {
74  std::list<EventListener*>::iterator iter;
75  for( iter = mListeners.begin(); iter != mListeners.end(); ++iter )
76  {
77  (*iter)->onEvent( aEventId, aEventData, aEventDataPtr, handleNow );
78  }
79 }
static void addListener(EventListener *aListener)
Adds a window that is interested in receiving events.
Definition: Event.cpp:24
EventId
Events generated by the FMI PC Application.
Definition: EventId.h:19
static std::list< EventListener * > mListeners
List of listeners that should receive event notifications.
Definition: Event.h:58
static void removeListener(EventListener *aListener)
Remove a target window from the interested object list.
Definition: Event.cpp:40
unsigned long int uint32
32-bit unsigned integer
Definition: garmin_types.h:66
Base class for objects that take action in response to an Event being posted.
Definition: EventListener.h:24
static void post(EventId aEventId, uint32 aEventData=0, void *aEventDataPtr=NULL, BOOL handleNow=FALSE)
Posts a message to all windows that have registered to get events.
Definition: Event.cpp:67