177b8aac3SPatrick Williams# Interface YAML 277b8aac3SPatrick Williams 3f7944dcbSPatrick WilliamsD-Bus interfaces can be defined by creating a YAML file to describe the methods, 4f7944dcbSPatrick Williamsproperties, and signals they contain. From this YAML file, both documentation 5f7944dcbSPatrick Williamsand binding code may be generated. 677b8aac3SPatrick Williams 777b8aac3SPatrick Williams## YAML sections 877b8aac3SPatrick Williams 977b8aac3SPatrick WilliamsAn interface YAML may have the following sections: 1077b8aac3SPatrick Williams 1177b8aac3SPatrick Williams- description 12f7944dcbSPatrick Williams - A small documentation section describing the purpose of the interface. 1377b8aac3SPatrick Williams- methods 1477b8aac3SPatrick Williams - A list of methods provided by this D-Bus interface. 1577b8aac3SPatrick Williams- properties 1677b8aac3SPatrick Williams - A list of properties provided by this D-Bus interface. 1777b8aac3SPatrick Williams- signals 1877b8aac3SPatrick Williams - A list of signals generated by this D-Bus interface. 1977b8aac3SPatrick Williams- enumerations 2077b8aac3SPatrick Williams - A list of enumerations defined by this D-Bus interface. 21b50817c1SJagpal Singh Gill- paths 22b50817c1SJagpal Singh Gill - A list of D-Bus paths where this D-Bus interface will be implemented. 23b50817c1SJagpal Singh Gill- service_names 24b50817c1SJagpal Singh Gill - A default service name or a list of service names which can host this D-Bus 25b50817c1SJagpal Singh Gill interface. 2677b8aac3SPatrick Williams 2777b8aac3SPatrick Williams## Enumerations 2877b8aac3SPatrick Williams 29f7944dcbSPatrick WilliamsA common problem we have found with D-Bus interfaces is having a consistent way 30f7944dcbSPatrick Williamsto define enumerations. Two common practices are to either assign special 31f7944dcbSPatrick Williamsmeaning to integers, as a C compiler might do, or to have specific strings 32f7944dcbSPatrick Williamsrepresenting the enumeration name. The [D-Bus API design 33f7944dcbSPatrick Williamsguidelines][dbus-design-guidelines] specify both of these options: 3477b8aac3SPatrick Williams 3577b8aac3SPatrick Williams> For APIs being used in constrained situations, enumerated values should be 36f7944dcbSPatrick Williams> transmitted as unsigned integers. For APIs which need to be extended by third 37f7944dcbSPatrick Williams> parties or which are used in more loosely coupled systems, enumerated values 38f7944dcbSPatrick Williams> should be strings in some defined format. 3977b8aac3SPatrick Williams 4077b8aac3SPatrick WilliamsWhat we have done in `sdbus++` is to consider enumerations as a first-class 41f7944dcbSPatrick Williamstype. Within an interface you can define an enumeration and the bindings will 42f7944dcbSPatrick Williamshave a C++ enumeration defined for it. At a D-Bus level any property or method 43f7944dcbSPatrick Williamsparameter will be a string, but the string will contain a fully-qualified name 44f7944dcbSPatrick Williams"interface.enum-name.enum-value" like "org.freedesktop.Example.Color.Red". 45f7944dcbSPatrick WilliamsWithin the generated bindings, an automatic conversion is done between strings 46f7944dcbSPatrick Williamsand C++ enumeration values and clients will get an 47f7944dcbSPatrick Williams"xyz.openbmc_project.sdbusplus.Error.InvalidEnumString" error response if they 48f7944dcbSPatrick Williamsattempt to use an invalid string value. 4977b8aac3SPatrick Williams 5077b8aac3SPatrick WilliamsAn enumeration must have the YAML properties `name` and `values` and may 51f7944dcbSPatrick Williamsoptionally contain a `description`. The `name` is a word corresponding to the 52f7944dcbSPatrick Williamsdesired "enum-name" portion of the fully-qualified name and the resulting C++ 53f7944dcbSPatrick Williamsenum type. The `values` are a list of enumeration values each containing their 54f7944dcbSPatrick Williamsown `name` and optional `description`. 5577b8aac3SPatrick Williams 5677b8aac3SPatrick WilliamsExample: 5777b8aac3SPatrick Williams 5877b8aac3SPatrick Williams```yaml 5977b8aac3SPatrick Williamsenumerations: 6077b8aac3SPatrick Williams - name: Suits 6177b8aac3SPatrick Williams description: > 6277b8aac3SPatrick Williams The suits found in a deck of cards. 6377b8aac3SPatrick Williams values: 6477b8aac3SPatrick Williams - name: Diamonds 6577b8aac3SPatrick Williams - name: Hearts 6677b8aac3SPatrick Williams - name: Clubs 6777b8aac3SPatrick Williams description: > 6877b8aac3SPatrick Williams This is the suit that looks like a clover. 6977b8aac3SPatrick Williams - name: Spades 7077b8aac3SPatrick Williams``` 7177b8aac3SPatrick Williams 7277b8aac3SPatrick Williams## Types 7377b8aac3SPatrick Williams 7477b8aac3SPatrick Williams### Base types 7577b8aac3SPatrick Williams 76f7944dcbSPatrick WilliamsTypes are identified in YAML using their typename found in the [D-Bus 77f7944dcbSPatrick Williamsspecification][dbus-spec], but listed using lowercases: `int64` instead of 78f7944dcbSPatrick Williams`INT64` or C++ `int64_t`. 7977b8aac3SPatrick Williams 8077b8aac3SPatrick Williams- `byte` 8177b8aac3SPatrick Williams- `boolean` 8277b8aac3SPatrick Williams- `int16` 8377b8aac3SPatrick Williams- `uint16` 8477b8aac3SPatrick Williams- ... 8577b8aac3SPatrick Williams- `uint64` 8677b8aac3SPatrick Williams- `size` - maps to the C `size_t` for the architecture. 8777b8aac3SPatrick Williams- `ssize` - maps to the C `ssize_t` for the architecture. 8877b8aac3SPatrick Williams- `double` 8977b8aac3SPatrick Williams- `unixfd` 9077b8aac3SPatrick Williams- `string` 9177b8aac3SPatrick Williams- `object_path` 9277b8aac3SPatrick Williams- `signature` 9377b8aac3SPatrick Williams 9477b8aac3SPatrick Williams### Special type values 9577b8aac3SPatrick Williams 9677b8aac3SPatrick WilliamsNote: The special value identifiers are all case-insensitive. 9777b8aac3SPatrick Williams 9877b8aac3SPatrick WilliamsFor floating-point types it is possible to express one of the special values: 9977b8aac3SPatrick Williams 10077b8aac3SPatrick Williams- `NaN` - A quiet-type not-a-number value. 10177b8aac3SPatrick Williams- `Infinity` : A positive infinity value. 10277b8aac3SPatrick Williams- `-Infinity` : A negative infinity value. 10377b8aac3SPatrick Williams- `Epsilon` : An epsilon value. 10477b8aac3SPatrick Williams 10577b8aac3SPatrick WilliamsFor integer types it is possible to express one of the special values: 10677b8aac3SPatrick Williams 107*3baa3045SManojkiran Eda- `minint` - The minimum value the integer type can hold. 10877b8aac3SPatrick Williams- `maxint` - The maximum value the integer type can hold. 10977b8aac3SPatrick Williams 11077b8aac3SPatrick Williams### Container Types 11177b8aac3SPatrick Williams 11277b8aac3SPatrick WilliamsContainer types can also be expressed, but the contained-type should be 11377b8aac3SPatrick Williamsexpressed within square-brackets `[]`. The following containers are supported: 11477b8aac3SPatrick Williams 11577b8aac3SPatrick Williams- `array[type]` 11677b8aac3SPatrick Williams - C++ type is `std::vector` 11777b8aac3SPatrick Williams- `dict[keytype, valuetype]` 11877b8aac3SPatrick Williams - C++ type is `std::map` 11977b8aac3SPatrick Williams- `set[type]` 12077b8aac3SPatrick Williams - C++ type is `std::set` 12177b8aac3SPatrick Williams- `struct[type0, type1, ...]` 12277b8aac3SPatrick Williams - C++ type is `std::tuple` 12377b8aac3SPatrick Williams- `variant[type0, type1, ...]` 12477b8aac3SPatrick Williams - C++ type is `std::variant` 12577b8aac3SPatrick Williams 12677b8aac3SPatrick WilliamsIt may seem odd that variants are required to list the types they may contain, 12777b8aac3SPatrick Williamsbut this is due to C++ being a strongly-typed language. In order to generate 128f7944dcbSPatrick Williamsbindings, to read from and append to a message, the binding generator must know 129f7944dcbSPatrick Williamsall possible types the variant may contain. 13077b8aac3SPatrick Williams 13177b8aac3SPatrick Williams### Enumeration Types 13277b8aac3SPatrick Williams 13377b8aac3SPatrick WilliamsEnumerations are expressed like a container, but the contained-type is an 13477b8aac3SPatrick Williamsidentifier of the fully-qualified enum-name or a shortened `self.` identifier 13577b8aac3SPatrick Williamsfor locally defined types. 13677b8aac3SPatrick Williams 13777b8aac3SPatrick Williams- enum[org.freedesktop.Example.Suits] 13877b8aac3SPatrick Williams- enum[self.Suits] 13977b8aac3SPatrick Williams 14077b8aac3SPatrick Williams## Methods 14177b8aac3SPatrick Williams 14277b8aac3SPatrick WilliamsA method must have the YAML property `name` and may optionally have 14377b8aac3SPatrick Williams`parameters`, `returns`, `flags`, `errors`, and `description`. Each parameter 14477b8aac3SPatrick Williamsmust have a `name`, `type`, and optional `description`. Each return must have a 14577b8aac3SPatrick Williams`type` and may optionally have a `name` and `description`. Flags are a list of 14677b8aac3SPatrick Williamssd-bus vtable flags; the supported values are `deprecated`, `hidden`, 14777b8aac3SPatrick Williams`unprivileged`and `no_reply`, which corresponds to `SD_BUS_VTABLE_DEPRECATED`, 14877b8aac3SPatrick Williams`SD_BUS_VTABLE_HIDDEN`, `SD_BUS_VTABLE_UNPRIVILEGED`, 14977b8aac3SPatrick Williams`SD_BUS_VTABLE_METHOD_NO_REPLY`, respectively. Errors are a list of 15077b8aac3SPatrick Williamsfully-qualified or shortened `self.` identifiers for errors the method may 15177b8aac3SPatrick Williamsreturn, which must be defined in a corresponding errors YAML file. 15277b8aac3SPatrick Williams 15377b8aac3SPatrick WilliamsExample: 15477b8aac3SPatrick Williams 15577b8aac3SPatrick Williams```yaml 15677b8aac3SPatrick Williamsmethods: 15777b8aac3SPatrick Williams - name: Shuffle 15877b8aac3SPatrick Williams flags: 15977b8aac3SPatrick Williams - unprivileged 16077b8aac3SPatrick Williams errors: 16177b8aac3SPatrick Williams - self.Error.TooTired 16277b8aac3SPatrick Williams - name: Deal 16377b8aac3SPatrick Williams description: > 16477b8aac3SPatrick Williams Deals a new hand to each player. 16577b8aac3SPatrick Williams errors: 16677b8aac3SPatrick Williams - self.Error.OutOfCards 16777b8aac3SPatrick Williams - name: LookAtTop 16877b8aac3SPatrick Williams returns: 16977b8aac3SPatrick Williams - name: Card 17077b8aac3SPatrick Williams type: struct[enum[self.Suit], byte] 17177b8aac3SPatrick Williams - name: MoveToTop 17277b8aac3SPatrick Williams flags: 17377b8aac3SPatrick Williams - deprecated 17477b8aac3SPatrick Williams - no_reply 17577b8aac3SPatrick Williams parameters: 17677b8aac3SPatrick Williams - name: Card 17777b8aac3SPatrick Williams type: struct[enum[self.Suit], byte] 17877b8aac3SPatrick Williams``` 17977b8aac3SPatrick Williams 18077b8aac3SPatrick Williams## Properties 18177b8aac3SPatrick Williams 18277b8aac3SPatrick WilliamsA property must have the YAML property `name` and `type` and may optionally have 18377b8aac3SPatrick Williams`description`, `flags`, `default`, and `errors`. The `default` defines the 18477b8aac3SPatrick Williamsdefault value of the property. See the `Methods` section above for more 18577b8aac3SPatrick Williamsinformation on errors. 18677b8aac3SPatrick Williams 18777b8aac3SPatrick WilliamsThe supported values for `flags` are and their equivalent sd-bus flag setting: 18877b8aac3SPatrick Williams 18977b8aac3SPatrick Williams- `deprecated` - SD_BUS_VTABLE_DEPRECATED 19077b8aac3SPatrick Williams- `hidden` - SD_BUS_VTABLE_HIDDEN 19177b8aac3SPatrick Williams- `unprivileged` - SD_BUS_VTABLE_UNPRIVILEGED 19277b8aac3SPatrick Williams- `const` - SD_BUS_VTABLE_PROPERTY_CONST 19377b8aac3SPatrick Williams- `emits_change` - SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE 19477b8aac3SPatrick Williams- `emits_invalidation` - SD_BUS_VTABLE_PROPERTY_EMITS_INVALIDATION 19577b8aac3SPatrick Williams- `explicit` - SD_BUS_VTABLE_PROPERTY_EXPLICIT 19677b8aac3SPatrick Williams- `readonly` - (N/A) 19777b8aac3SPatrick Williams 19877b8aac3SPatrick WilliamsIf no flag is given, a property will default to `emits_change`. 19977b8aac3SPatrick Williams 200f7944dcbSPatrick WilliamsBoth `const` and `readonly` prevent D-Bus clients from being able to write to a 201f7944dcbSPatrick Williamsproperty. `const` is a D-Bus indication that the property can never change, 202f7944dcbSPatrick Williamswhile `readonly` properties can be changed by the D-Bus server itself. As 203f7944dcbSPatrick Williamsexamples, the `Version` property on a software object might be appropriate to be 204f7944dcbSPatrick Williams`const` and the `Value` property on a sensor object would likely be `readonly`. 20577b8aac3SPatrick Williams 20677b8aac3SPatrick WilliamsExample: 20777b8aac3SPatrick Williams 20877b8aac3SPatrick Williams```yaml 20977b8aac3SPatrick Williamsproperties: 21077b8aac3SPatrick Williams - name: CardsRemaining 21177b8aac3SPatrick Williams type: uint32 21277b8aac3SPatrick Williams default: 52 21377b8aac3SPatrick Williams flags: 21477b8aac3SPatrick Williams - const 21577b8aac3SPatrick Williams description: > 21677b8aac3SPatrick Williams The number of cards remaining in the deck. 21777b8aac3SPatrick Williams errors: 21877b8aac3SPatrick Williams - self.Error.InvalidNumber 21977b8aac3SPatrick Williams``` 22077b8aac3SPatrick Williams 22177b8aac3SPatrick Williams## Signals 22277b8aac3SPatrick Williams 22377b8aac3SPatrick WilliamsA signal must have the YAML property `name` and may optionally have a 224f7944dcbSPatrick Williams`description` and list of `properties`. Properties are specified the same as 225f7944dcbSPatrick Williamsinterface properties. 22677b8aac3SPatrick Williams 22777b8aac3SPatrick WilliamsExample: 22877b8aac3SPatrick Williams 22977b8aac3SPatrick Williams```yaml 23077b8aac3SPatrick Williamssignals: 23177b8aac3SPatrick Williams - name: Shuffled 23277b8aac3SPatrick Williams description: > 23377b8aac3SPatrick Williams The deck has been shuffled. 23477b8aac3SPatrick Williams - name: Cheated 23577b8aac3SPatrick Williams properties: 23677b8aac3SPatrick Williams - name: CardToTop 23777b8aac3SPatrick Williams type: struct[enum[self.Suit], byte] 23877b8aac3SPatrick Williams``` 23977b8aac3SPatrick Williams 24077b8aac3SPatrick Williams[dbus-design-guidelines]: https://dbus.freedesktop.org/doc/dbus-api-design.html 24177b8aac3SPatrick Williams[dbus-spec]: https://dbus.freedesktop.org/doc/dbus-specification.html 242b50817c1SJagpal Singh Gill 243b50817c1SJagpal Singh Gill## Paths 244b50817c1SJagpal Singh Gill 245b50817c1SJagpal Singh GillA path must have the YAML property `name` & `value` and may optionally have a 246b50817c1SJagpal Singh Gill`description` and `segments`. Each `segments` entry must have the YAML property 247b50817c1SJagpal Singh Gill`name` & `value` and may optionally have a `description` & nested `segments`. 248b50817c1SJagpal Singh Gill 249b50817c1SJagpal Singh GillExample: 250b50817c1SJagpal Singh Gill 251b50817c1SJagpal Singh Gill```yaml 252b50817c1SJagpal Singh Gillpaths: 253b50817c1SJagpal Singh Gill - name: CardGames 254b50817c1SJagpal Singh Gill description: > 255b50817c1SJagpal Singh Gill The root path for the card games. 256b50817c1SJagpal Singh Gill value: /xyz/openbmc_project/card_games 257b50817c1SJagpal Singh Gill segments: 258b50817c1SJagpal Singh Gill - name: BlackJack 259b50817c1SJagpal Singh Gill description: > 260b50817c1SJagpal Singh Gill The relative path for the black jack game. 261b50817c1SJagpal Singh Gill value: black_jack 262b50817c1SJagpal Singh Gill - name: Rummy 263b50817c1SJagpal Singh Gill description: > 264b50817c1SJagpal Singh Gill The relative path for the rummy game. 265b50817c1SJagpal Singh Gill value: rummy 266b50817c1SJagpal Singh Gill``` 267b50817c1SJagpal Singh Gill 268b50817c1SJagpal Singh GillA common approach is to have a single path which is used as a root of all 269b50817c1SJagpal Singh Gillinstances, which is often documented as a "namespace". For convenience, this can 270b50817c1SJagpal Singh Gillbe represented with a single `namespace` value. If the interface is intended to 271b50817c1SJagpal Singh Gillbe used as a singleton at a specific object path, similarly the `instance` value 272b50817c1SJagpal Singh Gillcan be used. 273b50817c1SJagpal Singh Gill 274b50817c1SJagpal Singh GillExample: 275b50817c1SJagpal Singh Gill 276b50817c1SJagpal Singh Gill```yaml 277b50817c1SJagpal Singh Gillpaths: 278b50817c1SJagpal Singh Gill - namespace: /xyz/openbmc_project/decks 279b50817c1SJagpal Singh Gill description: > 280b50817c1SJagpal Singh Gill The root path for all decks. 281b50817c1SJagpal Singh Gill - instance: /xyz/openbmc_projects/decks/standard 282b50817c1SJagpal Singh Gill description: > 283b50817c1SJagpal Singh Gill The root path for a standard deck of cards. 284b50817c1SJagpal Singh Gill``` 285b50817c1SJagpal Singh Gill 286b50817c1SJagpal Singh Gill## Service Name 287b50817c1SJagpal Singh Gill 288b50817c1SJagpal Singh GillAn interface can be implemented either by a single service or multiple services. 289b50817c1SJagpal Singh Gill 290b50817c1SJagpal Singh Gill### Singleton host service name 291b50817c1SJagpal Singh Gill 292b50817c1SJagpal Singh GillA singleton host service name must have the YAML property `default` and may 293b50817c1SJagpal Singh Gilloptionally have a `description`. `xyz.openbmc_project.ObjectMapper` is one such 294b50817c1SJagpal Singh Gillexample. 295b50817c1SJagpal Singh Gill 296b50817c1SJagpal Singh GillExample: 297b50817c1SJagpal Singh Gill 298b50817c1SJagpal Singh Gill```yaml 299b50817c1SJagpal Singh Gillservice_names: 300b50817c1SJagpal Singh Gill default: xyz.openbmc_project.deck 301b50817c1SJagpal Singh Gill description: > 302b50817c1SJagpal Singh Gill The service name for the card deck manager. 303b50817c1SJagpal Singh Gill``` 304b50817c1SJagpal Singh Gill 305b50817c1SJagpal Singh Gill### Multiton host service names 306b50817c1SJagpal Singh Gill 307b50817c1SJagpal Singh GillA multiton host service name must have the YAML property `name` & `value` and 308b50817c1SJagpal Singh Gillmay optionally have a `description`. 309b50817c1SJagpal Singh Gill 310b50817c1SJagpal Singh GillExample: 311b50817c1SJagpal Singh Gill 312b50817c1SJagpal Singh Gill```yaml 313b50817c1SJagpal Singh Gillservice_names: 314b50817c1SJagpal Singh Gill - name: BlackJack 315b50817c1SJagpal Singh Gill description: > 316b50817c1SJagpal Singh Gill The service name for the Back Jack game manager. 317b50817c1SJagpal Singh Gill value: xyz.openbmc_project.black_jack 318b50817c1SJagpal Singh Gill - name: Rummy 319b50817c1SJagpal Singh Gill description: > 320b50817c1SJagpal Singh Gill The service name for rummy game manager. 321b50817c1SJagpal Singh Gill value: xyz.openbmc_project.rummy 322b50817c1SJagpal Singh Gill``` 323