xref: /openbmc/phosphor-dbus-interfaces/requirements.md (revision 921791c73008a3edfc6507afb5bc15e48963d295)
1e8821cc8SPatrick Williams# Requirements and Expectations for dbus interfaces
2e8821cc8SPatrick Williams
3a1347418SPatrick WilliamsThis document outlines requirements and expectations for dbus interfaces. These
4a1347418SPatrick Williamsare usually specified as requirements due to our dbus architecture or for
5a1347418SPatrick Williamsconsistency in implementations.
6e8821cc8SPatrick Williams
7e8821cc8SPatrick Williams## General
8e8821cc8SPatrick Williams
9e8821cc8SPatrick Williams### Prefer `size` and `uint64`/`int64` over explicit sizes
10e8821cc8SPatrick Williams
11e8821cc8SPatrick WilliamsDo not over-optimize properties by selecting explicit sizes such as `uint8`
12e8821cc8SPatrick Williamsunless there is a strong basis for it (usually driven by hardware or another
13e8821cc8SPatrick Williamsprotocol's specification).
14e8821cc8SPatrick Williams
15e8821cc8SPatrick WilliamsFor countable entities always prefer `size`, which are an sdbusplus implemented
16e8821cc8SPatrick Williamstype that maps to the C equivalent of `size_t` on the architecture. For
17e8821cc8SPatrick Williamsnon-countable values prefer `uint64` or `int64`.
18e8821cc8SPatrick Williams
19e8821cc8SPatrick Williams### Avoid use of arbitrary strings
20e8821cc8SPatrick Williams
21a1347418SPatrick WilliamsArbitrary strings should only be utilized for human consumption and never parsed
22a1347418SPatrick Williamsby code. Any arbitrary string is typically expected to have a description such
23a1347418SPatrick Williamsas "... can be shown in user interfaces but this field should not be used for
24a1347418SPatrick Williamsany programmatic interrogation of an object".
25e8821cc8SPatrick Williams
26e8821cc8SPatrick Williams### Leverage enumerations instead of strings or magic values
27e8821cc8SPatrick Williams
28a1347418SPatrick WilliamsThe sdbusplus implementation has built-in support for enumerations, which flow
29a1347418SPatrick Williamsacross the dbus as uniquely encoded string values but has support in the
30e8821cc8SPatrick Williamsbindings for automatically converting to a C++ enum type.
31e8821cc8SPatrick Williams
32e8821cc8SPatrick WilliamsIn some cases it is useful to have hardware-specific or OEM values for
33a1347418SPatrick Williamsenumerations. In those cases a property may be a string, but should specify that
34a1347418SPatrick Williamsthe values contained within are to be sdbusplus-enumerations of a specific
35*921791c7SManojkiran Edapattern. See the [software compatibility][software-compat] and [dump
36a1347418SPatrick Williamsinterface][dump-interface] as two current examples of this.
37e8821cc8SPatrick Williams
38a1347418SPatrick Williams[software-compat]:
39a1347418SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Software/README.md#compatibility
40a1347418SPatrick Williams[dump-interface]:
41a1347418SPatrick Williams  https://github.com/openbmc/phosphor-dbus-interfaces/blob/991b2b8bdbc950f2a85aebfc29d1b34ea3264686/yaml/xyz/openbmc_project/Dump/Create.interface.yaml#L25
42e8821cc8SPatrick Williams
43e8821cc8SPatrick Williams## Interfaces
44e8821cc8SPatrick Williams
45e8821cc8SPatrick Williams## Methods
46e8821cc8SPatrick Williams
47e8821cc8SPatrick Williams## Properties
48e8821cc8SPatrick Williams
49e8821cc8SPatrick Williams## Signals
50e8821cc8SPatrick Williams
51e8821cc8SPatrick Williams## Associations
52e8821cc8SPatrick Williams
53e8821cc8SPatrick WilliamsThere are typically two types of associations we use:
54e8821cc8SPatrick Williams
55e8821cc8SPatrick Williams- Peer associations.
56e8821cc8SPatrick Williams- Directed associations.
57e8821cc8SPatrick Williams
58e8821cc8SPatrick WilliamsPeer associations are rare, but are used to link a single entity that is
59e8821cc8SPatrick Williamsrequired to be represented in different dbus path hierarchies due to some
60e8821cc8SPatrick Williamsoverriding aspect of the dbus design.
61e8821cc8SPatrick Williams
62e8821cc8SPatrick WilliamsDirected associations are more common and are used to show a relationship
63a1347418SPatrick Williamsbetween two different entities. Though it may at times feel contrived, directed
64a1347418SPatrick Williamsassociations should be considered to have a "primary" and "secondary" end, which
65a1347418SPatrick Williamshelps establish a pattern for naming consistency. For example, a chassis might
66a1347418SPatrick Williamsbe "containing" (primary) any number of other inventory objects which are
67a1347418SPatrick Williams"contained_by" (secondary) the chassis.
68e8821cc8SPatrick Williams
69e8821cc8SPatrick Williams### Peer associations should be named with hierarchy names
70e8821cc8SPatrick Williams
71e8821cc8SPatrick WilliamsConsider an entity which is contained at `/.../foo/entity` and
72a1347418SPatrick Williams`/.../bar/entity`. The association is what links the `foo` and `bar` aspects of
73a1347418SPatrick Williamsthe entity in the dbus path hierarchy. Accordingly, the association should be
74a1347418SPatrick Williamsnamed with end-points "foo" and "bar".
75e8821cc8SPatrick Williams
76e8821cc8SPatrick WilliamsA made-up example of a peer association might be a `Inventory.Processor`,
77e8821cc8SPatrick Williamslocated under the `.../inventory` hierarchy, and a `Control.Power.Cap` for that
78e8821cc8SPatrick Williamsprocessor, located under the `.../control` hierarchy. The peer association
79a1347418SPatrick Williamsallows traversal between the `inventory` and `control` namespaces for the single
80a1347418SPatrick WilliamsProcessor entity.
81e8821cc8SPatrick Williams
82e8821cc8SPatrick Williams### Directed associations should not codify type
83e8821cc8SPatrick Williams
84e8821cc8SPatrick WilliamsThe end-point names of an association should not codify the types of the
85e8821cc8SPatrick Williamsinterfaces pointed to by the association.
86e8821cc8SPatrick Williams
87e8821cc8SPatrick Williams- Bad: powered_processor
88e8821cc8SPatrick Williams- Good: powering
89e8821cc8SPatrick Williams
90e8821cc8SPatrick Williams### Directed associations should be named with participle verbs
91e8821cc8SPatrick Williams
92e8821cc8SPatrick WilliamsThe primary relationship should be a verb with a Present Participle tense
93e8821cc8SPatrick Williams(ending in '-ing'). The secondary relationship should be a verb with a Past
94e8821cc8SPatrick WilliamsParticiple tense (typically ending in '-ed').
95e8821cc8SPatrick Williams
96a1347418SPatrick WilliamsThe association end-points should be named in a way that the following sentences
97a1347418SPatrick Williamsare grammatically correct:
98e8821cc8SPatrick Williams
99e8821cc8SPatrick Williams- The `{primary element}` is `{primary association}` the `{secondary element}`.
100e8821cc8SPatrick Williams- The `{secondary element}` is `{secondary association}` the
101e8821cc8SPatrick Williams  `{primary element}`.
102e8821cc8SPatrick Williams
1038cca11f0SMatt SpinlerThese correspond to the mapper D-Bus object paths
104*921791c7SManojkiran Eda`{primary element}/{primary association}` with an endpoints property value of
1058cca11f0SMatt Spinler`{secondary element}` and `{secondary element}/{secondary association}` with an
1068cca11f0SMatt Spinlerendpoints property value of `{primary element}`.
1078cca11f0SMatt Spinler
108e8821cc8SPatrick WilliamsIn some cases it may be required for grammatical correctness to add a
1098cca11f0SMatt Spinlerpreposition to the secondary association, such as 'by' or 'with'.
1108cca11f0SMatt Spinler
1118cca11f0SMatt SpinlerAdditional information on associations is in the [mapper documentation][].
1128cca11f0SMatt Spinler
1138cca11f0SMatt Spinler[mapper documentation]:
1148cca11f0SMatt Spinler  https://github.com/openbmc/docs/blob/master/architecture/object-mapper.md#associations
115