adding more convenience functions, improve some argument receivers

This commit is contained in:
2021-12-13 04:04:03 -05:00
parent b9f529ad56
commit 09f3c9b73e
11 changed files with 394 additions and 85 deletions

View File

@@ -115,3 +115,32 @@ func pathsFromPath(bus dbus.BusObject, path string) (paths []dbus.ObjectPath, er
return
}
/*
NameFromPath returns an actual name (as it appears in Dbus) from a dbus.ObjectPath.
Note that you can get any object's dbus.ObjectPath via <object.Dbus.Path().
path is validated to ensure it is not an empty string.
*/
func NameFromPath(path dbus.ObjectPath) (name string, err error) {
var strSplit []string
var ok bool
if ok, err = pathIsValid(path); err != nil {
return
} else if !ok {
err = ErrBadDbusPath
return
}
strSplit = strings.Split(string(path), "/")
if len(strSplit) < 1 {
err = ErrBadDbusPath
return
}
name = strSplit[len(strSplit)-1]
return
}