OpenASIP  2.0
OSEdInformer.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file OSEdInformer.cc
26  *
27  * Definition of OSEdInformer class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note rating: red
31  */
32 
33 #include "OSEdInformer.hh"
34 #include "OSEdListener.hh"
35 
36 using std::vector;
37 
38 /**
39  * Constructor.
40  */
42 }
43 
44 /**
45  * Destructor.
46  */
48 }
49 
50 /**
51  * Handles event of given id.
52  *
53  * If no such id exists, nothing is done.
54  *
55  * @param event Event to be handled.
56  */
57 void
59  ListenerContainer::iterator iter = listeners_.find(event);
60  if (iter != listeners_.end()) {
61  for (size_t i = 0; i < (*iter).second.size(); i++) {
62  (*iter).second[i]->handleEvent(event);
63  }
64  }
65 }
66 
67 /**
68  * Registers listener to informers data base.
69  *
70  * @param event Event of which given listener is interested in.
71  * @param listener Listener to be registered.
72  */
73 void
75  ListenerContainer::iterator iter = listeners_.find(event);
76  if (iter != listeners_.end()) {
77  (*iter).second.push_back(listener);
78  } else {
79  vector<OSEdListener*> newListenerContainer;
80  newListenerContainer.push_back(listener);
81  listeners_[event] = newListenerContainer;
82  }
83 }
84 
85 /**
86  * Unregisters listener from the informer.
87  *
88  * @param event Event for which given listener is registered to listen.
89  * @param listener Listener to be unregistered.
90  */
91 void
93  ListenerContainer::iterator iter = listeners_.find(event);
94  if (iter != listeners_.end()) {
95  vector<OSEdListener*>::iterator vecIter = (*iter).second.begin();
96  while (vecIter != (*iter).second.end()) {
97  if (*vecIter == listener) {
98  (*iter).second.erase(vecIter);
99  return;
100  }
101  vecIter++;
102  }
103  }
104 }
OSEdInformer::EventId
EventId
Definition: OSEdInformer.hh:52
OSEdInformer::handleEvent
void handleEvent(EventId event)
Definition: OSEdInformer.cc:58
OSEdListener.hh
OSEdInformer::listeners_
ListenerContainer listeners_
All listeners.
Definition: OSEdInformer.hh:75
OSEdInformer.hh
OSEdInformer::registerListener
void registerListener(EventId event, OSEdListener *listener)
Definition: OSEdInformer.cc:74
OSEdListener
Definition: OSEdListener.hh:42
OSEdInformer::OSEdInformer
OSEdInformer()
Definition: OSEdInformer.cc:41
OSEdInformer::unregisterListener
void unregisterListener(EventId event, OSEdListener *listener)
Definition: OSEdInformer.cc:92
OSEdInformer::~OSEdInformer
virtual ~OSEdInformer()
Definition: OSEdInformer.cc:47