What the heck is a dbus argument of type a{sa{sv}} in the Network Manager API?

986 Views Asked by At

I'm looking through the dbus api for Network Manager and there are methods with inputs of type a{sa{sv}}. I'm still new to dbus but if I'm interpreting the definition of signature specifiers in https://www.freedesktop.org/software/systemd/man/sd_bus_message_read.html# correctly this is:

  • A variable-length array
    • Of named variable arrays
      • Of named "variants" (which I guess are tagged unions)

What practically is this for? A name-paginated list of named settings? I'm seeing it all over the place in this API.

2

There are 2 best solutions below

0
davolfman On BEST ANSWER

It turns out this is what I guess should be called a "Settings" in Network Manager. For several methods instead of building a connection setting by setting an entire set of settings are added all at once. Here's a tabbed and commented version of the settings of my current connection as queried for example:

5
    "connection" 5
        "id" s "Profile 1"
        "permissions" as o //<empty array of strings>
        "timestamp" t 1661376049
        "type" s "802-3-ethernet"
        "uuid" s <not posting for privacy>
    "802-3-ethernet" 3
        "auto-negotiate" b false
        "mac-address-blacklist" as 0
        "s390-options" a{ss} 0
    "ipv4" 6
        "address-data" aa{sv} 0
        "addresses" aau 0
        "dns-search" as 0
        "method" s "auto"
        "route-data" aa{sv} 0
        "routes" aau 0
    "ipv6" 7
        "addr-gen-mode" i 1
        "address-data" aa{sv} 0
        "addresses" a(ayuay) 0
        "dns-search" as 0
        "method" s "auto"
        "route-data" aa{sv} 0
        "routes" a(ayuayu) 0
    "proxy" 0

I think most of these are defaults so the real settings you might set when creating a connection are probably something like:

4
    "connection" 4
        "id" s "Profile Foo"
        "timestamp" t <whatever, maybe this is autogenerated>
        "type" s "802-3-ethernet"
        "uuid" s <might be auto generated too>
    "802-3-ethernet" 0
    "ipv4" 1
        "method" s "auto"
    "ipv6" 1
        "addr-gen-mode" i 1
        "method" s "auto"
4
Ali-Ibrahim On
  • s is std::string.
  • v is variant.
  • a{} is std::map.
  • a{sv} is std::map<std::string, Variant>
  • Finally: a{sa{sv}} is std::map<std::string, std::map<std::string, Variant>>

Variant can hold value of any D-Bus-supported type, if you are using c++ I recommend you to check it at sdbus-cpp