2
* Copyright © 2013 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Alan Griffiths <alan@octopull.co.uk>
19
#include "mir/scene/scene_report.h"
20
#include "scene_report.h"
21
#include "mir/logging/logger.h"
22
#include "basic_surface.h"
26
namespace ms = mir::scene;
27
namespace ml = mir::logging;
28
namespace ms = mir::scene;
30
void ms::NullSceneReport::surface_created(BasicSurface* const /*surface*/) {}
31
void ms::NullSceneReport::surface_added(BasicSurface* const /*surface*/) {}
32
void ms::NullSceneReport::surface_removed(BasicSurface* const /*surface*/) {}
33
void ms::NullSceneReport::surface_deleted(BasicSurface* const /*surface*/) {}
37
char const* const component = "scene";
40
ml::SceneReport::SceneReport(std::shared_ptr<Logger> const& logger) :
45
void ml::SceneReport::surface_created(ms::BasicSurface* const surface)
47
std::lock_guard<std::mutex> lock(mutex);
48
surfaces[surface] = surface->name();
51
ss << "surface_created(" << surface << " [\"" << surface->name() << "\"])";
53
logger->log(Logger::informational, ss.str(), component);
56
void ml::SceneReport::surface_added(ms::BasicSurface* const surface)
58
std::lock_guard<std::mutex> lock(mutex);
60
auto const i = surfaces.find(surface);
63
ss << "surface_added(" << surface << " [\"" << surface->name() << "\"])";
65
if (i == surfaces.end())
67
ss << " - ERROR not reported to surface_created()";
69
else if (surface->name() != i->second)
71
ss << " - WARNING name changed from " << i->second;
74
ss << " - INFO surface count=" << surfaces.size();
76
logger->log(Logger::informational, ss.str(), component);
79
void ml::SceneReport::surface_removed(ms::BasicSurface* const surface)
81
std::lock_guard<std::mutex> lock(mutex);
83
auto const i = surfaces.find(surface);
86
ss << "surface_removed(" << surface << " [\"" << surface->name() << "\"])";
88
if (i == surfaces.end())
90
ss << " - ERROR not reported to surface_created()";
92
else if (surface->name() != i->second)
94
ss << " - WARNING name changed from " << i->second;
97
ss << " - INFO surface count=" << surfaces.size();
99
logger->log(Logger::informational, ss.str(), component);
102
void ml::SceneReport::surface_deleted(ms::BasicSurface* const surface)
104
std::lock_guard<std::mutex> lock(mutex);
106
auto const i = surfaces.find(surface);
108
std::stringstream ss;
109
ss << "surface_deleted(" << surface << " [\"" << surface->name() << "\"])";
111
if (i == surfaces.end())
113
ss << " - ERROR not reported to surface_created()";
115
else if (surface->name() != i->second)
117
ss << " - WARNING name changed from " << i->second;
120
if (i != surfaces.end())
123
ss << " - INFO surface count=" << surfaces.size() << std::endl;
125
logger->log(Logger::informational, ss.str(), component);