如何从ofono获得财产

时间:2015-05-18 12:24:48

标签: c++ linux dbus

我用C ++创建了一个程序来获取ofono API的属性:

string Protocol [readwrite]

            Holds the protocol for this context.  Valid values
            are: "ip", "ipv6" and "dual".

        string Name [readwrite]

            The name is a free form string that describes this
            context.  The name should not be empty and limited
            to a short string for display purposes.

        dict Settings [readonly, optional]

            Holds all the IP network settings

            string Interface [readonly, optional]

                Holds the interface of the network interface
                used by this context (e.g. "ppp0" "usb0")

            string Method [readonly, optional]

                Holds the IP network config method
                    "static"- Set IP network statically
                    "dhcp"  - Set IP network through DHCP

            string Address [readonly, optional]

我解析属性时使用

...
for (auto p:prop){
p.first //to get name of property
p.second.reader().get_string() //to get string value of property
p.second.reader().get_bool() //to get boolean value of property
...
}

我的问题是如何获取dict类型的名称和值?例如dict Settings [readonly, optional]如何获取string Interface [readonly, optional]string Method [readonly, optional]

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,只是我做了这个:

p是我的问题中定义的道具元素

...
    DBus::MessageIter iterator = p.second.reader();
    std::map< std::string, ::DBus::Variant > mapping;
    iterator >> mapping;
    for (auto map:mapping) {
            map.first// contain the name 
            map.second.reader().get_string() // contain the string value
    }
...