Search code examples
c++linuxdbus

How to get property from ofono


I have made a program with C++ to get Properties of 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]

While I parse properties I use

...
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
...
}

My problem is how to get names and values for dict type? like for example for dict Settings [readonly, optional] how to get string Interface [readonly, optional] or string Method [readonly, optional]


Solution

  • I found the solution, just I made this:

    p is element of prop defined in my question

    ...
        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
        }
    ...