~ubuntu-branches/ubuntu/utopic/mir/utopic-proposed

« back to all changes in this revision

Viewing changes to src/server/scene/scene_report.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-03-10 19:28:46 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: package-import@ubuntu.com-20140310192846-rq9qm3ec26yrelo2
Tags: upstream-0.1.6+14.04.20140310
Import upstream version 0.1.6+14.04.20140310

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2013 Canonical Ltd.
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17
 
 */
18
 
 
19
 
#include "mir/scene/scene_report.h"
20
 
#include "scene_report.h"
21
 
#include "mir/logging/logger.h"
22
 
#include "basic_surface.h"
23
 
 
24
 
#include <sstream>
25
 
 
26
 
namespace ms = mir::scene;
27
 
namespace ml = mir::logging;
28
 
namespace ms = mir::scene;
29
 
 
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*/) {}
34
 
 
35
 
namespace
36
 
{
37
 
char const* const component = "scene";
38
 
}
39
 
 
40
 
ml::SceneReport::SceneReport(std::shared_ptr<Logger> const& logger) :
41
 
    logger(logger)
42
 
{
43
 
}
44
 
 
45
 
void ml::SceneReport::surface_created(ms::BasicSurface* const surface)
46
 
{
47
 
    std::lock_guard<std::mutex> lock(mutex);
48
 
    surfaces[surface] = surface->name();
49
 
 
50
 
    std::stringstream ss;
51
 
    ss << "surface_created(" << surface << " [\"" << surface->name() << "\"])";
52
 
 
53
 
    logger->log(Logger::informational, ss.str(), component);
54
 
}
55
 
 
56
 
void ml::SceneReport::surface_added(ms::BasicSurface* const surface)
57
 
{
58
 
    std::lock_guard<std::mutex> lock(mutex);
59
 
 
60
 
    auto const i = surfaces.find(surface);
61
 
 
62
 
    std::stringstream ss;
63
 
    ss << "surface_added(" << surface << " [\"" << surface->name() << "\"])";
64
 
 
65
 
    if (i == surfaces.end())
66
 
    {
67
 
        ss << " - ERROR not reported to surface_created()";
68
 
    }
69
 
    else if (surface->name() != i->second)
70
 
    {
71
 
        ss << " - WARNING name changed from " << i->second;
72
 
    }
73
 
 
74
 
    ss << " - INFO surface count=" << surfaces.size();
75
 
 
76
 
    logger->log(Logger::informational, ss.str(), component);
77
 
}
78
 
 
79
 
void ml::SceneReport::surface_removed(ms::BasicSurface* const surface)
80
 
{
81
 
    std::lock_guard<std::mutex> lock(mutex);
82
 
 
83
 
    auto const i = surfaces.find(surface);
84
 
 
85
 
    std::stringstream ss;
86
 
    ss << "surface_removed(" << surface << " [\"" << surface->name() << "\"])";
87
 
 
88
 
    if (i == surfaces.end())
89
 
    {
90
 
        ss << " - ERROR not reported to surface_created()";
91
 
    }
92
 
    else if (surface->name() != i->second)
93
 
    {
94
 
        ss << " - WARNING name changed from " << i->second;
95
 
    }
96
 
 
97
 
    ss << " - INFO surface count=" << surfaces.size();
98
 
 
99
 
    logger->log(Logger::informational, ss.str(), component);
100
 
}
101
 
 
102
 
void ml::SceneReport::surface_deleted(ms::BasicSurface* const surface)
103
 
{
104
 
    std::lock_guard<std::mutex> lock(mutex);
105
 
 
106
 
    auto const i = surfaces.find(surface);
107
 
 
108
 
    std::stringstream ss;
109
 
    ss << "surface_deleted(" << surface << " [\"" << surface->name() << "\"])";
110
 
 
111
 
    if (i == surfaces.end())
112
 
    {
113
 
        ss << " - ERROR not reported to surface_created()";
114
 
    }
115
 
    else if (surface->name() != i->second)
116
 
    {
117
 
        ss << " - WARNING name changed from " << i->second;
118
 
    }
119
 
 
120
 
    if (i != surfaces.end())
121
 
        surfaces.erase(i);
122
 
 
123
 
    ss << " - INFO surface count=" << surfaces.size() << std::endl;
124
 
 
125
 
    logger->log(Logger::informational, ss.str(), component);
126
 
}