gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
probe.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * Authors: Matt Horsnell
38  */
39 
61 #ifndef __SIM_PROBE_PROBE_HH__
62 #define __SIM_PROBE_PROBE_HH__
63 
64 #include <string>
65 #include <vector>
66 
67 #include "base/compiler.hh"
68 #include "base/trace.hh"
69 #include "sim/sim_object.hh"
70 
72 class ProbeManager;
73 class ProbeListener;
74 class ProbeListenerObjectParams;
75 
84 namespace ProbePoints {
85 /* Note: This is only here for documentation purposes, new probe
86  * points should normally be declared in their own header files. See
87  * for example pmu.hh.
88  */
89 }
90 
101 {
102  protected:
105 
106  public:
107  ProbeListenerObject(const ProbeListenerObjectParams *params);
108  virtual ~ProbeListenerObject();
110 };
111 
120 {
121  public:
122  ProbeListener(ProbeManager *manager, const std::string &name);
123  virtual ~ProbeListener();
124 
125  protected:
127  const std::string name;
128 };
129 
136 {
137  protected:
138  const std::string name;
139  public:
140  ProbePoint(ProbeManager *manager, const std::string &name);
141  virtual ~ProbePoint() {}
142 
143  virtual void addListener(ProbeListener *listener) = 0;
144  virtual void removeListener(ProbeListener *listener) = 0;
145  std::string getName() const { return name; }
146 };
147 
153 {
154  private:
159 
160  public:
162  : object(obj)
163  {}
164  virtual ~ProbeManager() {}
165 
173  bool addListener(std::string pointName, ProbeListener &listener);
174 
183  bool removeListener(std::string pointName, ProbeListener &listener);
184 
189  void addPoint(ProbePoint &point);
190 };
191 
199 template <class Arg>
201 {
202  public:
203  ProbeListenerArgBase(ProbeManager *pm, const std::string &name)
204  : ProbeListener(pm, name)
205  {}
206  virtual void notify(const Arg &val) = 0;
207 };
208 
216 template <class T, class Arg>
218 {
219  private:
220  T *object;
221  void (T::* function)(const Arg &);
222 
223  public:
229  ProbeListenerArg(T *obj, const std::string &name, void (T::* func)(const Arg &))
230  : ProbeListenerArgBase<Arg>(obj->getProbeManager(), name),
231  object(obj),
232  function(func)
233  {}
234 
240  virtual void notify(const Arg &val) { (object->*function)(val); }
241 };
242 
250 template <typename Arg>
251 class ProbePointArg : public ProbePoint
252 {
255 
256  public:
257  ProbePointArg(ProbeManager *manager, std::string name)
258  : ProbePoint(manager, name)
259  {
260  }
261 
267  {
268  // check listener not already added
269  if (std::find(listeners.begin(), listeners.end(), l) == listeners.end()) {
270  listeners.push_back(static_cast<ProbeListenerArgBase<Arg> *>(l));
271  }
272  }
273 
279  {
280  listeners.erase(std::remove(listeners.begin(), listeners.end(), l),
281  listeners.end());
282  }
283 
288  void notify(const Arg &arg)
289  {
290  for (auto l = listeners.begin(); l != listeners.end(); ++l) {
291  (*l)->notify(arg);
292  }
293  }
294 };
295 #endif//__SIM_PROBE_PROBE_HH__
bool removeListener(std::string pointName, ProbeListener &listener)
Remove a ProbeListener from the ProbePoint named by pointName.
Definition: probe.cc:102
const std::string name
Definition: probe.hh:127
virtual ~ProbeListenerObject()
Definition: probe.cc:59
#define M5_CLASS_VAR_USED
Definition: compiler.hh:61
ProbeListener base class; again used to simplify use of ProbePoints in containers and used as to defi...
Definition: probe.hh:135
virtual void notify(const Arg &val)=0
std::string getName() const
Definition: probe.hh:145
const Params * params() const
Definition: sim_object.hh:111
void notify(const Arg &arg)
called at the ProbePoint call site, passes arg to each listener.
Definition: probe.hh:288
ProbePointArg(ProbeManager *manager, std::string name)
Definition: probe.hh:257
virtual void notify(const Arg &val)
called when the ProbePoint calls notify.
Definition: probe.hh:240
ProbePoint(ProbeManager *manager, const std::string &name)
Definition: probe.cc:45
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:152
bool addListener(std::string pointName, ProbeListener &listener)
Add a ProbeListener to the ProbePoint named by pointName.
Definition: probe.cc:85
Bitfield< 63 > val
Definition: misc.hh:770
ProbeManager * getProbeManager()
Definition: probe.hh:109
ProbeManager * manager
Definition: probe.hh:103
virtual ~ProbePoint()
Definition: probe.hh:141
void addPoint(ProbePoint &point)
Add a ProbePoint to this SimObject ProbeManager.
Definition: probe.cc:119
ProbeListenerObject(const ProbeListenerObjectParams *params)
Definition: probe.cc:53
ProbeListenerArgBase is used to define the base interface to a ProbeListenerArg (i.e the notify method on specific type).
Definition: probe.hh:200
virtual void removeListener(ProbeListener *listener)=0
std::vector< ProbePoint * > points
Vector for name look-up.
Definition: probe.hh:158
This class is a minimal wrapper around SimObject.
Definition: probe.hh:100
virtual void addListener(ProbeListener *listener)=0
ProbeListenerArg(T *obj, const std::string &name, void(T::*func)(const Arg &))
Definition: probe.hh:229
void addListener(ProbeListener *l)
adds a ProbeListener to this ProbePoints notify list.
Definition: probe.hh:266
const M5_CLASS_VAR_USED SimObject * object
Required for sensible debug messages.
Definition: probe.hh:156
std::vector< ProbeListener * > listeners
Definition: probe.hh:104
ProbeListenerArgBase(ProbeManager *pm, const std::string &name)
Definition: probe.hh:203
virtual ~ProbeManager()
Definition: probe.hh:164
ProbePointArg generates a point for the class of Arg.
ProbeManager(SimObject *obj)
Definition: probe.hh:161
void removeListener(ProbeListener *l)
remove a ProbeListener from this ProbePoints notify list.
Definition: probe.hh:278
std::vector< ProbeListenerArgBase< Arg > * > listeners
The attached listeners.
Definition: probe.hh:254
virtual ~ProbeListener()
Definition: probe.cc:73
void(T::* function)(const Arg &)
Definition: probe.hh:221
ProbeListenerArg generates a listener for the class of Arg and the class type T which is the class co...
Definition: probe.hh:217
const std::string name
Definition: probe.hh:138
ProbeListener base class; here to simplify things like containers containing multiple types of ProbeL...
Definition: probe.hh:119
ProbeManager *const manager
Definition: probe.hh:126
ProbeListener(ProbeManager *manager, const std::string &name)
Definition: probe.cc:67
Bitfield< 5 > l
Abstract superclass for simulation objects.
Definition: sim_object.hh:94

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6