summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-30 10:44:34 +0000
committerhashimoto@chromium.org <hashimoto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-30 10:44:34 +0000
commitb6ebf078d2ada6bb2e226d58686cc9e7469b55fa (patch)
tree8598e241fc4cce76ad9158102df5df7f79327cb8 /chromeos
parent41e8daba7c80736e434a23164cf62e8999efe0b2 (diff)
downloadchromium_src-b6ebf078d2ada6bb2e226d58686cc9e7469b55fa.zip
chromium_src-b6ebf078d2ada6bb2e226d58686cc9e7469b55fa.tar.gz
chromium_src-b6ebf078d2ada6bb2e226d58686cc9e7469b55fa.tar.bz2
Move chromeos::GetInterfacesFromIntrospectResult into IntrospectableClient
Since XmlReader was moved from chrome/ to third_party/libxml/, now chromeos/ can depend on it. BUG=119583 TEST=chromeos_unittests Review URL: https://chromiumcodereview.appspot.com/10440013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/DEPS1
-rw-r--r--chromeos/chromeos.gyp2
-rw-r--r--chromeos/dbus/introspectable_client.cc38
-rw-r--r--chromeos/dbus/introspectable_client.h6
-rw-r--r--chromeos/dbus/introspectable_client_unittest.cc68
5 files changed, 115 insertions, 0 deletions
diff --git a/chromeos/DEPS b/chromeos/DEPS
index ffae1fe..3958c13 100644
--- a/chromeos/DEPS
+++ b/chromeos/DEPS
@@ -2,4 +2,5 @@ include_rules = [
"+net",
"+third_party/cros",
"+third_party/cros_system_api",
+ "+third_party/libxml",
]
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index 172af0c..97c6604 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -15,6 +15,7 @@
'../build/linux/system.gyp:dbus',
'../dbus/dbus.gyp:dbus',
'../net/net.gyp:net',
+ '../third_party/libxml/libxml.gyp:libxml',
'power_state_control_proto',
'power_supply_properties_proto',
],
@@ -193,6 +194,7 @@
'dbus/ibus/ibus_object_unittest.cc',
'dbus/ibus/ibus_text_unittest.cc',
'dbus/ibus/ibus_input_context_client_unittest.cc',
+ 'dbus/introspectable_client_unittest.cc',
'network/network_sms_handler_unittest.cc',
],
'include_dirs': [
diff --git a/chromeos/dbus/introspectable_client.cc b/chromeos/dbus/introspectable_client.cc
index d29563f..5f66684 100644
--- a/chromeos/dbus/introspectable_client.cc
+++ b/chromeos/dbus/introspectable_client.cc
@@ -13,6 +13,7 @@
#include "dbus/message.h"
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
+#include "third_party/libxml/chromium/libxml_utils.h"
namespace {
@@ -20,6 +21,10 @@ namespace {
const char kIntrospectableInterface[] = "org.freedesktop.DBus.Introspectable";
const char kIntrospect[] = "Introspect";
+// String constants used for parsing D-Bus Introspection XML data.
+const char kInterfaceNode[] = "interface";
+const char kInterfaceNameAttribute[] = "name";
+
} // namespace
namespace chromeos {
@@ -105,6 +110,39 @@ IntrospectableClient::~IntrospectableClient() {
}
// static
+std::vector<std::string>
+IntrospectableClient::GetInterfacesFromIntrospectResult(
+ const std::string& xml_data) {
+ std::vector<std::string> interfaces;
+
+ XmlReader reader;
+ if (!reader.Load(xml_data))
+ return interfaces;
+
+ do {
+ // Skip to the next open tag, exit when done.
+ while (!reader.SkipToElement()) {
+ if (!reader.Read()) {
+ return interfaces;
+ }
+ }
+
+ // Only look at interface nodes.
+ if (reader.NodeName() != kInterfaceNode)
+ continue;
+
+ // Skip if missing the interface name.
+ std::string interface_name;
+ if (!reader.NodeAttribute(kInterfaceNameAttribute, &interface_name))
+ continue;
+
+ interfaces.push_back(interface_name);
+ } while (reader.Read());
+
+ return interfaces;
+}
+
+// static
IntrospectableClient* IntrospectableClient::Create(
DBusClientImplementationType type,
dbus::Bus* bus) {
diff --git a/chromeos/dbus/introspectable_client.h b/chromeos/dbus/introspectable_client.h
index c21eb94..c70bb6e 100644
--- a/chromeos/dbus/introspectable_client.h
+++ b/chromeos/dbus/introspectable_client.h
@@ -42,6 +42,12 @@ class CHROMEOS_EXPORT IntrospectableClient {
const dbus::ObjectPath& object_path,
const IntrospectCallback& callback) = 0;
+ // Parses XML-formatted introspection data returned by
+ // org.freedesktop.DBus.Introspectable.Introspect and returns the list of
+ // interface names declared within.
+ static std::vector<std::string> GetInterfacesFromIntrospectResult(
+ const std::string& xml_data);
+
// Creates the instance
static IntrospectableClient* Create(DBusClientImplementationType type,
dbus::Bus* bus);
diff --git a/chromeos/dbus/introspectable_client_unittest.cc b/chromeos/dbus/introspectable_client_unittest.cc
new file mode 100644
index 0000000..5e98b1c
--- /dev/null
+++ b/chromeos/dbus/introspectable_client_unittest.cc
@@ -0,0 +1,68 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/dbus/introspectable_client.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const char kXmlData[] =
+"<!DOCTYPE node PUBLIC "
+"\"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" "
+"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
+"<node>\n"
+" <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
+" <method name=\"Introspect\">\n"
+" <arg type=\"s\" direction=\"out\"/>\n"
+" </method>\n"
+" </interface>\n"
+" <interface name=\"org.bluez.Device\">\n"
+" <method name=\"GetProperties\">\n"
+" <arg type=\"a{sv}\" direction=\"out\"/>\n"
+" </method>\n"
+" <method name=\"SetProperty\">\n"
+" <arg type=\"s\" direction=\"in\"/>\n"
+" <arg type=\"v\" direction=\"in\"/>\n"
+" </method>\n"
+" <method name=\"DiscoverServices\">\n"
+" <arg type=\"s\" direction=\"in\"/>\n"
+" <arg type=\"a{us}\" direction=\"out\"/>\n"
+" </method>\n"
+" <method name=\"CancelDiscovery\"/>\n"
+" <method name=\"Disconnect\"/>\n"
+" <signal name=\"PropertyChanged\">\n"
+" <arg type=\"s\"/>\n"
+" <arg type=\"v\"/>\n"
+" </signal>\n"
+" <signal name=\"DisconnectRequested\"/>\n"
+" </interface>\n"
+" <interface name=\"org.bluez.Input\">\n"
+" <method name=\"Connect\"/>\n"
+" <method name=\"Disconnect\"/>\n"
+" <method name=\"GetProperties\">\n"
+" <arg type=\"a{sv}\" direction=\"out\"/>\n"
+" </method>\n"
+" <signal name=\"PropertyChanged\">\n"
+" <arg type=\"s\"/>\n"
+" <arg type=\"v\"/>\n"
+" </signal>\n"
+" </interface>\n"
+"</node>";
+
+} // namespace
+
+namespace chromeos {
+
+TEST(IntrospectableClientTest, GetInterfacesFromIntrospectResult) {
+ std::vector<std::string> interfaces =
+ IntrospectableClient::GetInterfacesFromIntrospectResult(kXmlData);
+
+ ASSERT_EQ(3U, interfaces.size());
+ EXPECT_EQ("org.freedesktop.DBus.Introspectable", interfaces[0]);
+ EXPECT_EQ("org.bluez.Device", interfaces[1]);
+ EXPECT_EQ("org.bluez.Input", interfaces[2]);
+}
+
+} // namespace chromeos