OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/introspectable_client.h" | 5 #include "chromeos/dbus/introspectable_client.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "dbus/bus.h" | 12 #include "dbus/bus.h" |
13 #include "dbus/message.h" | 13 #include "dbus/message.h" |
14 #include "dbus/object_path.h" | 14 #include "dbus/object_path.h" |
15 #include "dbus/object_proxy.h" | 15 #include "dbus/object_proxy.h" |
| 16 #include "third_party/libxml/chromium/libxml_utils.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // D-Bus specification constants. | 20 // D-Bus specification constants. |
20 const char kIntrospectableInterface[] = "org.freedesktop.DBus.Introspectable"; | 21 const char kIntrospectableInterface[] = "org.freedesktop.DBus.Introspectable"; |
21 const char kIntrospect[] = "Introspect"; | 22 const char kIntrospect[] = "Introspect"; |
22 | 23 |
| 24 // String constants used for parsing D-Bus Introspection XML data. |
| 25 const char kInterfaceNode[] = "interface"; |
| 26 const char kInterfaceNameAttribute[] = "name"; |
| 27 |
23 } // namespace | 28 } // namespace |
24 | 29 |
25 namespace chromeos { | 30 namespace chromeos { |
26 | 31 |
27 // The IntrospectableClient implementation used in production. | 32 // The IntrospectableClient implementation used in production. |
28 class IntrospectableClientImpl : public IntrospectableClient { | 33 class IntrospectableClientImpl : public IntrospectableClient { |
29 public: | 34 public: |
30 explicit IntrospectableClientImpl(dbus::Bus* bus) | 35 explicit IntrospectableClientImpl(dbus::Bus* bus) |
31 : weak_ptr_factory_(this), | 36 : weak_ptr_factory_(this), |
32 bus_(bus) { | 37 bus_(bus) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 103 } |
99 }; | 104 }; |
100 | 105 |
101 IntrospectableClient::IntrospectableClient() { | 106 IntrospectableClient::IntrospectableClient() { |
102 } | 107 } |
103 | 108 |
104 IntrospectableClient::~IntrospectableClient() { | 109 IntrospectableClient::~IntrospectableClient() { |
105 } | 110 } |
106 | 111 |
107 // static | 112 // static |
| 113 std::vector<std::string> |
| 114 IntrospectableClient::GetInterfacesFromIntrospectResult( |
| 115 const std::string& xml_data) { |
| 116 std::vector<std::string> interfaces; |
| 117 |
| 118 XmlReader reader; |
| 119 if (!reader.Load(xml_data)) |
| 120 return interfaces; |
| 121 |
| 122 do { |
| 123 // Skip to the next open tag, exit when done. |
| 124 while (!reader.SkipToElement()) { |
| 125 if (!reader.Read()) { |
| 126 return interfaces; |
| 127 } |
| 128 } |
| 129 |
| 130 // Only look at interface nodes. |
| 131 if (reader.NodeName() != kInterfaceNode) |
| 132 continue; |
| 133 |
| 134 // Skip if missing the interface name. |
| 135 std::string interface_name; |
| 136 if (!reader.NodeAttribute(kInterfaceNameAttribute, &interface_name)) |
| 137 continue; |
| 138 |
| 139 interfaces.push_back(interface_name); |
| 140 } while (reader.Read()); |
| 141 |
| 142 return interfaces; |
| 143 } |
| 144 |
| 145 // static |
108 IntrospectableClient* IntrospectableClient::Create( | 146 IntrospectableClient* IntrospectableClient::Create( |
109 DBusClientImplementationType type, | 147 DBusClientImplementationType type, |
110 dbus::Bus* bus) { | 148 dbus::Bus* bus) { |
111 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 149 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
112 return new IntrospectableClientImpl(bus); | 150 return new IntrospectableClientImpl(bus); |
113 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 151 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
114 return new IntrospectableClientStubImpl(); | 152 return new IntrospectableClientStubImpl(); |
115 } | 153 } |
116 | 154 |
117 } // namespace chromeos | 155 } // namespace chromeos |
OLD | NEW |