probe.cc revision 10365
110023Smatt.horsnell@ARM.com/*
210023Smatt.horsnell@ARM.com * Copyright (c) 2013 ARM Limited
310023Smatt.horsnell@ARM.com * All rights reserved
410023Smatt.horsnell@ARM.com *
510023Smatt.horsnell@ARM.com * The license below extends only to copyright in the software and shall
610023Smatt.horsnell@ARM.com * not be construed as granting a license to any other intellectual
710023Smatt.horsnell@ARM.com * property including but not limited to intellectual property relating
810023Smatt.horsnell@ARM.com * to a hardware implementation of the functionality of the software
910023Smatt.horsnell@ARM.com * licensed hereunder.  You may use the software subject to the license
1010023Smatt.horsnell@ARM.com * terms below provided that you ensure that this notice is replicated
1110023Smatt.horsnell@ARM.com * unmodified and in its entirety in all distributions of the software,
1210023Smatt.horsnell@ARM.com * modified or unmodified, in source code or in binary form.
1310023Smatt.horsnell@ARM.com *
1410023Smatt.horsnell@ARM.com * Redistribution and use in source and binary forms, with or without
1510023Smatt.horsnell@ARM.com * modification, are permitted provided that the following conditions are
1610023Smatt.horsnell@ARM.com * met: redistributions of source code must retain the above copyright
1710023Smatt.horsnell@ARM.com * notice, this list of conditions and the following disclaimer;
1810023Smatt.horsnell@ARM.com * redistributions in binary form must reproduce the above copyright
1910023Smatt.horsnell@ARM.com * notice, this list of conditions and the following disclaimer in the
2010023Smatt.horsnell@ARM.com * documentation and/or other materials provided with the distribution;
2110023Smatt.horsnell@ARM.com * neither the name of the copyright holders nor the names of its
2210023Smatt.horsnell@ARM.com * contributors may be used to endorse or promote products derived from
2310023Smatt.horsnell@ARM.com * this software without specific prior written permission.
2410023Smatt.horsnell@ARM.com *
2510023Smatt.horsnell@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2610023Smatt.horsnell@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2710023Smatt.horsnell@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2810023Smatt.horsnell@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2910023Smatt.horsnell@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3010023Smatt.horsnell@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3110023Smatt.horsnell@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3210023Smatt.horsnell@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3310023Smatt.horsnell@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3410023Smatt.horsnell@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3510023Smatt.horsnell@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3610023Smatt.horsnell@ARM.com *
3710023Smatt.horsnell@ARM.com * Authors: Matt Horsnell
3810023Smatt.horsnell@ARM.com */
3910023Smatt.horsnell@ARM.com
4010023Smatt.horsnell@ARM.com#include "debug/ProbeVerbose.hh"
4110023Smatt.horsnell@ARM.com#include "sim/probe/probe.hh"
4210023Smatt.horsnell@ARM.com
4310023Smatt.horsnell@ARM.comProbePoint::ProbePoint(ProbeManager *manager, const std::string& _name)
4410023Smatt.horsnell@ARM.com    : name(_name)
4510023Smatt.horsnell@ARM.com{
4610023Smatt.horsnell@ARM.com    if (manager) {
4710023Smatt.horsnell@ARM.com        manager->addPoint(*this);
4810023Smatt.horsnell@ARM.com    }
4910023Smatt.horsnell@ARM.com}
5010023Smatt.horsnell@ARM.com
5110023Smatt.horsnell@ARM.comProbeListenerObject::ProbeListenerObject(const ProbeListenerObjectParams *params)
5210023Smatt.horsnell@ARM.com    : SimObject(params),
5310023Smatt.horsnell@ARM.com      manager(params->manager->getProbeManager())
5410023Smatt.horsnell@ARM.com{
5510023Smatt.horsnell@ARM.com}
5610023Smatt.horsnell@ARM.com
5710023Smatt.horsnell@ARM.comProbeListenerObject::~ProbeListenerObject()
5810023Smatt.horsnell@ARM.com{
5910023Smatt.horsnell@ARM.com    for (auto l = listeners.begin(); l != listeners.end(); ++l) {
6010023Smatt.horsnell@ARM.com        delete (*l);
6110023Smatt.horsnell@ARM.com    }
6210023Smatt.horsnell@ARM.com    listeners.clear();
6310023Smatt.horsnell@ARM.com}
6410023Smatt.horsnell@ARM.com
6510365SAndreas.Sandberg@ARM.comProbeListener::ProbeListener(ProbeManager *_manager, const std::string &_name)
6610365SAndreas.Sandberg@ARM.com    : manager(_manager), name(_name)
6710023Smatt.horsnell@ARM.com{
6810023Smatt.horsnell@ARM.com    manager->addListener(name, *this);
6910023Smatt.horsnell@ARM.com}
7010023Smatt.horsnell@ARM.com
7110365SAndreas.Sandberg@ARM.comProbeListener::~ProbeListener()
7210365SAndreas.Sandberg@ARM.com{
7310365SAndreas.Sandberg@ARM.com    manager->removeListener(name, *this);
7410365SAndreas.Sandberg@ARM.com}
7510365SAndreas.Sandberg@ARM.com
7610023Smatt.horsnell@ARM.comProbeListenerObject*
7710023Smatt.horsnell@ARM.comProbeListenerObjectParams::create()
7810023Smatt.horsnell@ARM.com{
7910023Smatt.horsnell@ARM.com    return new ProbeListenerObject(this);
8010023Smatt.horsnell@ARM.com}
8110023Smatt.horsnell@ARM.com
8210023Smatt.horsnell@ARM.combool
8310023Smatt.horsnell@ARM.comProbeManager::addListener(std::string pointName, ProbeListener &listener)
8410023Smatt.horsnell@ARM.com{
8510023Smatt.horsnell@ARM.com    DPRINTFR(ProbeVerbose, "Probes: Call to addListener to \"%s\" on %s.\n", pointName, object->name());
8610023Smatt.horsnell@ARM.com    bool added = false;
8710023Smatt.horsnell@ARM.com    for (auto p = points.begin(); p != points.end(); ++p) {
8810023Smatt.horsnell@ARM.com        if ((*p)->getName() == pointName) {
8910023Smatt.horsnell@ARM.com            (*p)->addListener(&listener);
9010023Smatt.horsnell@ARM.com            added = true;
9110023Smatt.horsnell@ARM.com        }
9210023Smatt.horsnell@ARM.com    }
9310023Smatt.horsnell@ARM.com    if (!added) {
9410023Smatt.horsnell@ARM.com        DPRINTFR(ProbeVerbose, "Probes: Call to addListener to \"%s\" on %s failed, no such point.\n", pointName, object->name());
9510023Smatt.horsnell@ARM.com    }
9610023Smatt.horsnell@ARM.com    return added;
9710023Smatt.horsnell@ARM.com}
9810023Smatt.horsnell@ARM.com
9910023Smatt.horsnell@ARM.combool
10010023Smatt.horsnell@ARM.comProbeManager::removeListener(std::string pointName, ProbeListener &listener)
10110023Smatt.horsnell@ARM.com{
10210023Smatt.horsnell@ARM.com    DPRINTFR(ProbeVerbose, "Probes: Call to removeListener from \"%s\" on %s.\n", pointName, object->name());
10310023Smatt.horsnell@ARM.com    bool removed = false;
10410023Smatt.horsnell@ARM.com    for (auto p = points.begin(); p != points.end(); ++p) {
10510023Smatt.horsnell@ARM.com        if ((*p)->getName() == pointName) {
10610023Smatt.horsnell@ARM.com            (*p)->removeListener(&listener);
10710023Smatt.horsnell@ARM.com            removed = true;
10810023Smatt.horsnell@ARM.com        }
10910023Smatt.horsnell@ARM.com    }
11010023Smatt.horsnell@ARM.com    if (!removed) {
11110023Smatt.horsnell@ARM.com        DPRINTFR(ProbeVerbose, "Probes: Call to removeListener from \"%s\" on %s failed, no such point.\n", pointName, object->name());
11210023Smatt.horsnell@ARM.com    }
11310023Smatt.horsnell@ARM.com    return removed;
11410023Smatt.horsnell@ARM.com}
11510023Smatt.horsnell@ARM.com
11610023Smatt.horsnell@ARM.comvoid
11710023Smatt.horsnell@ARM.comProbeManager::addPoint(ProbePoint &point)
11810023Smatt.horsnell@ARM.com{
11910023Smatt.horsnell@ARM.com    DPRINTFR(ProbeVerbose, "Probes: Call to addPoint \"%s\" to %s.\n", point.getName(), object->name());
12010023Smatt.horsnell@ARM.com
12110023Smatt.horsnell@ARM.com    for (auto p = points.begin(); p != points.end(); ++p) {
12210023Smatt.horsnell@ARM.com        if ((*p)->getName() == point.getName()) {
12310023Smatt.horsnell@ARM.com            DPRINTFR(ProbeVerbose, "Probes: Call to addPoint \"%s\" to %s failed, already added.\n", point.getName(), object->name());
12410023Smatt.horsnell@ARM.com            return;
12510023Smatt.horsnell@ARM.com        }
12610023Smatt.horsnell@ARM.com    }
12710023Smatt.horsnell@ARM.com    points.push_back(&point);
12810023Smatt.horsnell@ARM.com}
129