adding more convenience functions, improve some argument receivers
This commit is contained in:
29
funcs.go
29
funcs.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user