1# The ObjectMapper 2 3The `xyz.openbmc_project.ObjectMapper` service, commonly referred to as just the 4mapper, is an OpenBMC application that attempts to ease the pain of using D-Bus 5by providing APIs that help in discovering and associating other D-Bus objects. 6 7The mapper has two major pieces of functionality: 8 9- [Methods](#methods) - Provides D-Bus discovery related functionality. 10- [Associations](#associations) - Associates two different objects with each 11 other. 12 13## Methods 14 15The official YAML interface definition can be found [here][1]. 16 17### GetObject 18 19Use this method to find the services, with their interfaces, that implement a 20certain object path. The output is a map of service names to their implemented 21interfaces. An optional list of interfaces may also be passed in to constrain 22the output to services that implement those specific interfaces. 23 24Inputs: 25 26- path: object path 27- param: interfaces - an optional list of interfaces to constrain the search to 28 29Output: 30 31- Map of service names to their interfaces 32 33``` 34dbus-send --system --print-reply \ 35--dest=xyz.openbmc_project.ObjectMapper \ 36/xyz/openbmc_project/object_mapper \ 37xyz.openbmc_project.ObjectMapper.GetObject \ 38string:"/xyz/openbmc_project/sensors/voltage/ps1_input_voltage" array:string: 39 40 array [ 41 dict entry( 42 string "xyz.openbmc_project.Hwmon-1025936882.Hwmon1" 43 array [ 44 string "xyz.openbmc_project.Sensor.Threshold.Critical" 45 string "xyz.openbmc_project.Sensor.Threshold.Warning" 46 string "xyz.openbmc_project.Sensor.Value" 47 ] 48 ) 49 ] 50``` 51 52#### Example Use Case 53 54Find the service name that has the desired object path so it can be passed into 55a get property call. 56 57### GetSubTree 58 59Use this method to find the objects, services, and interfaces in the specified 60subtree that implement a certain interface. If no interfaces are passed in, then 61all objects/services/interfaces in the subtree are returned. If interfaces are 62passed in, then only those interfaces are returned in the output. 63 64Inputs: 65 66- param: subtree - the root of the tree. Using "/" will search the whole tree 67- param: depth - the maximum depth of the tree past the root to search. Use 0 to 68 search all 69- param: interfaces - an optional list of interfaces to constrain the search to 70 71Output: 72 73- Map of object paths to a map of service names to their interfaces 74 75``` 76dbus-send --system --print-reply \ 77--dest=xyz.openbmc_project.ObjectMapper \ 78/xyz/openbmc_project/object_mapper \ 79xyz.openbmc_project.ObjectMapper.GetSubTree \ 80string:"/" int32:0 array:string:"xyz.openbmc_project.Sensor.Threshold.Warning" 81 82 array [ 83 dict entry( 84 string "/xyz/openbmc_project/sensors/current/ps0_output_current" 85 array [ 86 dict entry( 87 string "xyz.openbmc_project.Hwmon-1040041051.Hwmon1" 88 array [ 89 string "xyz.openbmc_project.Sensor.Threshold.Critical" 90 string "xyz.openbmc_project.Sensor.Threshold.Warning" 91 string "xyz.openbmc_project.Sensor.Value" 92 ] 93 ) 94 ] 95 ) 96 dict entry( 97 string "/xyz/openbmc_project/sensors/current/ps1_output_current" 98 array [ 99 dict entry( 100 string "xyz.openbmc_project.Hwmon-1025936882.Hwmon1" 101 array [ 102 string "xyz.openbmc_project.Sensor.Threshold.Critical" 103 string "xyz.openbmc_project.Sensor.Threshold.Warning" 104 string "xyz.openbmc_project.Sensor.Value" 105 ] 106 ) 107 ] 108 ) 109... 110 111``` 112 113#### Example Use Case 114 115Find all object paths and services that implement a specific interface. 116 117### GetSubTreePaths 118 119This is the same as GetSubTree, but only returns object paths 120 121Inputs: 122 123- param: subtree - the root of the tree. Using "/" will search the whole tree 124- param: depth - the maximum depth of the tree past the root to search. Use 0 to 125 search all 126- param: interfaces - an optional list of interfaces to constrain the search to 127 128Output: 129 130- array of object paths in that subtree 131 132``` 133dbus-send --system --print-reply \ 134--dest=xyz.openbmc_project.ObjectMapper \ 135/xyz/openbmc_project/object_mapper \ 136xyz.openbmc_project.ObjectMapper.GetSubTreePaths \ 137string:"/" int32:0 array:string:"xyz.openbmc_project.Sensor.Threshold.Warning" 138 139 array [ 140 string "/xyz/openbmc_project/sensors/current/ps0_output_current" 141 string "/xyz/openbmc_project/sensors/current/ps1_output_current" 142 string "/xyz/openbmc_project/sensors/power/ps0_input_power" 143... 144 ] 145``` 146 147#### Example Use Case 148 149Find all object paths that implement a specific interface. 150 151### GetAncestors 152 153Use this method to find all ancestors of an object that implement a specific 154interface. If no interfaces are passed in, then all ancestor 155paths/services/interfaces are returned. 156 157Inputs: 158 159- param: path - the object path to find the ancestors of 160- param: interfaces - an optional list of interfaces to constrain the search to 161 162Output: 163 164- A map of object paths to a map of services names to their interfaces 165 166``` 167 168dbus-send --system --print-reply \ 169--dest=xyz.openbmc_project.ObjectMapper \ 170/xyz/openbmc_project/object_mapper \ 171xyz.openbmc_project.ObjectMapper.GetAncestors \ 172string:"/xyz/openbmc_project/inventory/system" array:string: 173 174 array [ 175 dict entry( 176 string "/xyz/openbmc_project" 177 array [ 178 dict entry( 179 string "xyz.openbmc_project.ObjectMapper" 180 array [ 181 string "org.freedesktop.DBus.ObjectManager" 182 ] 183 ) 184 ] 185 ) 186 dict entry( 187 string "/xyz/openbmc_project/inventory" 188 array [ 189 dict entry( 190 string "xyz.openbmc_project.Inventory.Manager" 191 array [ 192 string "xyz.openbmc_project.Inventory.Manager" 193 string "org.freedesktop.DBus.ObjectManager" 194 ] 195 ) 196 ] 197 ) 198 dict entry( 199 string "/" 200 array [ 201 dict entry( 202 string "xyz.openbmc_project.Settings" 203 array [ 204 string "org.freedesktop.DBus.ObjectManager" 205 ] 206 ) 207 ] 208 ) 209 ] 210``` 211 212#### Example Use Case 213 214Find a parent object that implements a specific interface. 215 216## Associations 217 218Associations are special D-Bus objects created by the mapper to associate two 219objects with each other. For this to occur, some application must implement the 220`xyz.openbmc_project.Association.Definitions` interface, and then when an 221association is desired, the `Associations` property on that interface needs to 222be written. 223 224This `Associations` property is an array of tuples of the form: 225 226``` 227[forward, reverse, object path] 228``` 229 230- forward: this is the name of the forward association object 231- reverse: this is the name of the reverse association object 232- object path: this is the other object to associate with 233 234When an object with, for example, an object path of `pathA` uses the following 235values: 236 237``` 238["foo", "bar", "pathB"] 239``` 240 241The mapper will create 2 new objects: 242 2431. `pathA/foo` 2442. `pathB/bar` 245 246On each of these objects, the interface `xyz.openbmc_project.Association` will 247be implemented, which has a single `endpoints` property. This property is an 248array that holds the object paths to the other end of the association. 249 250So, `pathA/foo->endpoints` will contain `pathB`, and `pathB/bar->endpoints` will 251contain `pathA`. 252 253If another object, say `pathC`, also has an association to `pathB`, then a 254second entry, `pathC`, will be added into `pathB`\'s endpoints property. 255 256These new objects will match the lifetime of the associated objects. For 257example, if `pathA` is deleted, then `pathA/foo` will also be deleted, and 258`pathA` will be removed from the endpoints property of `pathB/bar`. If that was 259the last entry in that property, then `pathB/bar` will also be deleted. In 260addition, if the endpoint path is removed from D-Bus, in this case `pathB`, then 261the mapper will remove the 2 association paths until `pathB` shows back up 262again. 263 264Note: The original name of the association definition interface was 265`org.openbmc.Associations`. While the mapper still supports this interface as 266well for the time being, new code should use the `xyz` version. 267 268#### Example Use Case 269 270Associate an error log with the inventory item that caused it. 271 272``` 273# Error log 274"/xyz/openbmc_project/logging/entry/3": { 275... 276 "associations": [ 277 [ 278 "callout", 279 "fault", 280 "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0" 281 ] 282 ] 283} 284 285# Newly created forward association object 286"/xyz/openbmc_project/logging/entry/3/callout": { 287 "endpoints": [ 288 "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0" 289 ] 290} 291 292# Newly created reverse association object 293"/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0/fault": { 294 "endpoints": [ 295 "/xyz/openbmc_project/logging/entry/3" 296 ] 297} 298 299``` 300 301[1]: 302 https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/ObjectMapper.interface.yaml 303