Re: [systemd-devel] sd-bus dynamic property table
On Mo, 13.05.19 08:25, Stephen Hemminger (step...@networkplumber.org) wrote: > I have a simple application that does provides property table for network > devices (maybe it would be useful for a more complete example somewhere). > The app is more to show how to use sdbus, not to replace network manager. > > The next step is to add ethtool statistics. Each type of network device will > have > different set of named properties. How could this be implemented? > So far, the only idea would be to dynamically build a vtable then > register it? > > > # busctl tree org.networkplumber.net1 > └─/org > └─/org/networkplumber > └─/org/networkplumber/net1 > └─/org/networkplumber/net1/interface > ├─/org/networkplumber/net1/interface/eno1 > ├─/org/networkplumber/net1/interface/eno2 > ├─/org/networkplumber/net1/interface/ens11 > └─/org/networkplumber/net1/interface/lo > > # busctl introspect org.networkplumber.net1 > /org/networkplumber/net1/interface/eno1 > NAMETYPE SIGNATURE RESULT/VALUE FLAGS > org.freedesktop.DBus.Introspectable interface - -- > .Introspect method- s- > org.freedesktop.DBus.Peer interface - -- > .GetMachineId method- s- > .Ping method- -- > org.freedesktop.DBus.Properties interface - -- > .Getmethodssv- > .GetAll methods a{sv}- > .Setmethodssv -- > .PropertiesChanged signalsa{sv}as -- > org.networkplumber.net1.Interface interface - -- > .carrierproperty q 1- > .ifindexproperty q 2- > .iflink property q 2- > .mtuproperty q 1500 - Simon already replied to this, but let's add some further points: dbus' object model is modelled after the object model of common object-oriented programming languages, i.e. Java, C# and suchlike. They generally have immutable interface definitions, i.e. the vtables consisting of methods and properties never change, but the implementation of them might, and objects might expose different interfaces at the same time, in different combinations. It's not unlike C in many ways: a C struct definition doesn't change either, regardless what you apply it to. Hence: you have multiple options to model what you are trying to do: try to split things up into multiple interfaces so that you object can implement them in varying combinations. Or simply define all properties at all times, but define a special value (i.e. UINT64_MAX for a uint64_t property or so) that indicates they don't actually apply to the current object. Lennart -- Lennart Poettering, Berlin ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] sd-bus dynamic property table
On Mon, 13 May 2019 at 08:25:03 -0700, Stephen Hemminger wrote: > The next step is to add ethtool statistics. Each type of network device will > have > different set of named properties. This is really a D-Bus API design query, not a systemd query. The standard D-Bus Properties interface is not designed for use with arbitrary/dynamic named attributes. It's intended to be a D-Bus equivalent of GObject properties or Qt properties, which are set up in the object's source code: their values might vary at runtime, but the list of properties that exists in a class or interface is part of the API of that class or interface and does not change[1]. Similarly, D-Bus properties exist in an interface alongside methods and signals, and an interface either has a Foo property or it doesn't: if it does, then every object that implements the interface also has a Foo property. If you need named attributes that vary between objects, I'd suggest representing them as either a single large property with an a{sv} as its value, or a D-Bus interface that structurally resembles Properties but is not Properties (for instance you could call it com.example.NetworkStatistics, replacing com.example with your reversed domain name, and have a GetStatistics() -> a{sv} method and optionally a StatisticsChanged signal). The org.freedesktop.DBus.Debug.Stats interface in dbus-daemon (it's compile-time conditional, so your dbus-daemon might not have it) provides an example of an interface that puts arbitrary attributes in the result of a method call. smcv [1] except for maybe backward-compatible feature enhancements where newer versions introduce more properties ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] sd-bus dynamic property table
I have a simple application that does provides property table for network devices (maybe it would be useful for a more complete example somewhere). The app is more to show how to use sdbus, not to replace network manager. The next step is to add ethtool statistics. Each type of network device will have different set of named properties. How could this be implemented? So far, the only idea would be to dynamically build a vtable then register it? # busctl tree org.networkplumber.net1 └─/org └─/org/networkplumber └─/org/networkplumber/net1 └─/org/networkplumber/net1/interface ├─/org/networkplumber/net1/interface/eno1 ├─/org/networkplumber/net1/interface/eno2 ├─/org/networkplumber/net1/interface/ens11 └─/org/networkplumber/net1/interface/lo # busctl introspect org.networkplumber.net1 /org/networkplumber/net1/interface/eno1 NAMETYPE SIGNATURE RESULT/VALUE FLAGS org.freedesktop.DBus.Introspectable interface - -- .Introspect method- s- org.freedesktop.DBus.Peer interface - -- .GetMachineId method- s- .Ping method- -- org.freedesktop.DBus.Properties interface - -- .Getmethodssv- .GetAll methods a{sv}- .Setmethodssv -- .PropertiesChanged signalsa{sv}as -- org.networkplumber.net1.Interface interface - -- .carrierproperty q 1- .ifindexproperty q 2- .iflink property q 2- .mtuproperty q 1500 - Want to be able to add these: # ethtool -S eno1 | grep -v ' 0$' NIC statistics: rx_packets: 84980 tx_packets: 32068 rx_bytes: 107413644 tx_bytes: 9299204 rx_broadcast: 219 tx_broadcast: 84 rx_multicast: 152 tx_multicast: 157 multicast: 152 tx_tcp_seg_good: 1561 rx_long_byte_count: 107413644 tx_queue_0_packets: 6888 tx_queue_0_bytes: 3127349 tx_queue_1_packets: 6307 tx_queue_1_bytes: 3623152 tx_queue_2_packets: 12569 tx_queue_2_bytes: 1239345 tx_queue_3_packets: 6304 tx_queue_3_bytes: 1163512 rx_queue_0_packets: 17936 rx_queue_0_bytes: 21464312 rx_queue_1_packets: 20651 rx_queue_1_bytes: 27029893 rx_queue_2_packets: 12642 rx_queue_2_bytes: 13132543 rx_queue_3_packets: 33751 rx_queue_3_bytes: 45446976 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel