Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 1 | // Copyright (c) Ed Tanous |
| 2 | // |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #ifndef DBUS_UTILITY_HPP |
| 7 | #define DBUS_UTILITY_HPP |
| 8 | |
| 9 | #include <boost/iostreams/stream.hpp> |
| 10 | #include <boost/property_tree/ptree.hpp> |
| 11 | #include <boost/property_tree/xml_parser.hpp> |
| 12 | |
| 13 | namespace dbus { |
| 14 | |
| 15 | inline void read_dbus_xml_names(std::string& xml_data_in, |
| 16 | std::vector<std::string>& values_out) { |
| 17 | // populate tree structure pt |
| 18 | using boost::property_tree::ptree; |
| 19 | ptree pt; |
| 20 | std::cout << xml_data_in; |
| 21 | std::stringstream ss; |
| 22 | ss << xml_data_in; |
| 23 | read_xml(ss, pt); |
| 24 | |
| 25 | // traverse node to find other nodes |
| 26 | for (const auto& interface : pt.get_child("node")) { |
| 27 | if (interface.first == "node") { |
| 28 | auto t = interface.second.get<std::string>("<xmlattr>", "default"); |
| 29 | for (const auto& subnode : interface.second.get_child("<xmlattr>")) { |
| 30 | if (subnode.first == "name") { |
| 31 | std::string t = subnode.second.get("", "unknown"); |
| 32 | values_out.push_back(t); |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | #endif // DBUS_UTILITY_HPP |