702.3.1
by Michael Terry
add modelines and fix up some inconsistent tabbings |
1 |
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
|
572.9.22
by Alex Launi
Fix method names |
2 |
/*
|
3 |
* Copyright (C) 2010 Canonical Ltd
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License version 3 as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*
|
|
17 |
* Authored by: Alex Launi <alex.launi@canonical.com>
|
|
572.9.11
by Alex Launi
Build framework for elements to be introspected |
18 |
*/
|
19 |
||
20 |
#include "Introspectable.h" |
|
21 |
||
1249.1.3
by Jay Taoko
* Added Introspectable to the "unity" namesapce |
22 |
namespace unity |
23 |
{
|
|
1741.2.2
by Alex Launi
Move Introspectable and DebugDBusInterface into debug namespace |
24 |
namespace debug |
25 |
{
|
|
1741.3.1
by Jason Smith
Add switcher introspection in detail |
26 |
|
27 |
Introspectable::Introspectable() |
|
28 |
{
|
|
1882.2.14
by Thomi Richards
Refactor of launcher icon classes. |
29 |
static guint64 unique_id=0; |
30 |
_id = unique_id++; |
|
1741.3.1
by Jason Smith
Add switcher introspection in detail |
31 |
}
|
32 |
||
33 |
Introspectable::~Introspectable() |
|
34 |
{
|
|
1741.3.3
by Jason Smith
make parent tracking internal to introspection |
35 |
for (auto parent : _parents) |
36 |
parent->_children.remove(this); |
|
1852.1.1
by Thomi Richards
Fixed a bug that would cause unity to crash sometimes on exit due to Introspectable keeping stale pointers to parents. |
37 |
for (auto child : _children) |
38 |
child->_parents.remove(this); |
|
1741.3.1
by Jason Smith
Add switcher introspection in detail |
39 |
}
|
40 |
||
1885.6.1
by Jason Smith
let Introspectable's override children getter |
41 |
Introspectable::IntrospectableList const& Introspectable::GetIntrospectableChildren() |
42 |
{
|
|
43 |
return _children; |
|
44 |
}
|
|
45 |
||
572.9.11
by Alex Launi
Build framework for elements to be introspected |
46 |
GVariant* |
1733.6.34
by Thomi Richards
Children now returned in a tuple with their names. |
47 |
Introspectable::Introspect() |
572.9.22
by Alex Launi
Fix method names |
48 |
{
|
1765.1.1
by Jason Smith
initial perf improvement |
49 |
GVariantBuilder builder; |
50 |
GVariantBuilder child_builder; |
|
650.1.5
by Neil Jagdish Patel
Clean up the Introspect function, implement GetChildsName() for some nicer results |
51 |
gint n_children = 0; |
572.9.22
by Alex Launi
Fix method names |
52 |
|
1733.6.34
by Thomi Richards
Children now returned in a tuple with their names. |
53 |
g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); |
1882.2.14
by Thomi Richards
Refactor of launcher icon classes. |
54 |
g_variant_builder_add(&builder, "{sv}", "id", g_variant_new_uint64(_id)); |
1765.1.3
by Jason Smith
get rid of spare tuples |
55 |
|
1765.1.1
by Jason Smith
initial perf improvement |
56 |
AddProperties(&builder); |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
57 |
|
1733.6.34
by Thomi Richards
Children now returned in a tuple with their names. |
58 |
g_variant_builder_init(&child_builder, G_VARIANT_TYPE("a(sv)")); |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
59 |
|
1885.6.1
by Jason Smith
let Introspectable's override children getter |
60 |
auto children = GetIntrospectableChildren(); |
61 |
for (auto it = children.begin(); it != children.end(); it++) |
|
650.1.4
by Neil Jagdish Patel
Revert changes to introspectable |
62 |
{
|
1733.6.8
by Alex Launi
Convert debugging code from gchar* to std::string |
63 |
if ((*it)->GetName() != "") |
650.1.5
by Neil Jagdish Patel
Clean up the Introspect function, implement GetChildsName() for some nicer results |
64 |
{
|
1733.6.34
by Thomi Richards
Children now returned in a tuple with their names. |
65 |
g_variant_builder_add(&child_builder, "(sv)", (*it)->GetName().c_str(), (*it)->Introspect()); |
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
66 |
n_children++; |
650.1.5
by Neil Jagdish Patel
Clean up the Introspect function, implement GetChildsName() for some nicer results |
67 |
}
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
68 |
}
|
69 |
||
1765.1.1
by Jason Smith
initial perf improvement |
70 |
GVariant* child_results = g_variant_builder_end(&child_builder); |
1885.6.1
by Jason Smith
let Introspectable's override children getter |
71 |
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
72 |
if (n_children > 0) |
1776.1.7
by Thomi Richards
Code now uses GetChildsName() method correctly. Updated a few places in the code where classes had overloaded this method incorrectly. |
73 |
g_variant_builder_add(&builder, "{sv}", GetChildsName().c_str(), child_results); |
1765.1.1
by Jason Smith
initial perf improvement |
74 |
return g_variant_builder_end(&builder); |
572.9.22
by Alex Launi
Fix method names |
75 |
}
|
76 |
||
77 |
void
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
78 |
Introspectable::AddChild(Introspectable* child) |
572.9.22
by Alex Launi
Fix method names |
79 |
{
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
80 |
_children.push_back(child); |
1741.3.3
by Jason Smith
make parent tracking internal to introspection |
81 |
child->_parents.push_back(this); |
572.9.22
by Alex Launi
Fix method names |
82 |
}
|
83 |
||
84 |
void
|
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
85 |
Introspectable::RemoveChild(Introspectable* child) |
572.9.22
by Alex Launi
Fix method names |
86 |
{
|
1307
by Neil Jagdish Patel
Update formatting to match style (as close as possible) |
87 |
_children.remove(child); |
1741.3.3
by Jason Smith
make parent tracking internal to introspection |
88 |
child->_parents.remove(this); |
650.1.5
by Neil Jagdish Patel
Clean up the Introspect function, implement GetChildsName() for some nicer results |
89 |
}
|
90 |
||
1733.6.4
by Alex Launi
Change gchar* to std::string in the debugging classes |
91 |
std::string |
92 |
Introspectable::GetChildsName() const |
|
650.1.5
by Neil Jagdish Patel
Clean up the Introspect function, implement GetChildsName() for some nicer results |
93 |
{
|
1776.1.7
by Thomi Richards
Code now uses GetChildsName() method correctly. Updated a few places in the code where classes had overloaded this method incorrectly. |
94 |
return "Children"; |
650.1.5
by Neil Jagdish Patel
Clean up the Introspect function, implement GetChildsName() for some nicer results |
95 |
}
|
1882.2.14
by Thomi Richards
Refactor of launcher icon classes. |
96 |
|
97 |
guint64 Introspectable::GetIntrospectionId() const |
|
98 |
{
|
|
99 |
return _id; |
|
100 |
}
|
|
101 |
||
102 |
}
|
|
103 |
}
|
|
104 |