From 807d18770a3b39850e587bba771920637fd07e22 Mon Sep 17 00:00:00 2001 From: Bruce Leidl Date: Wed, 29 Jun 2016 18:25:50 +0000 Subject: [PATCH] No longer need to manually handle introspection subpaths --- dbus.go | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/dbus.go b/dbus.go index 16b6abd..074edf9 100644 --- a/dbus.go +++ b/dbus.go @@ -2,9 +2,7 @@ package main import ( "errors" - "fmt" "path" - "strings" "github.com/godbus/dbus" "github.com/godbus/dbus/introspect" @@ -82,44 +80,15 @@ func newDbusServer() (*dbusServer, error) { if err := conn.Export(ds, objectPath, interfaceName); err != nil { return nil, err } - - ps := strings.Split(objectPath, "/") - path := "/" - for _, p := range ps { - if len(path) > 1 { - path += "/" - } - path += p - - if err := conn.Export(ds, dbus.ObjectPath(path), "org.freedesktop.DBus.Introspectable"); err != nil { - return nil, err - } + if err := conn.Export(introspect.Introspectable(introspectXml), objectPath, "org.freedesktop.DBus.Introspectable"); err != nil { + return nil, err } + ds.conn = conn ds.prompter = newPrompter(conn) return ds, nil } -func (ds *dbusServer) Introspect(msg dbus.Message) (string, *dbus.Error) { - path := string(msg.Headers[dbus.FieldPath].Value().(dbus.ObjectPath)) - if path == objectPath { - return introspectXml, nil - } - parts := strings.Split(objectPath, "/") - current := "/" - for i := 0; i < len(parts)-1; i++ { - if len(current) > 1 { - current += "/" - } - current += parts[i] - if path == current { - next := parts[i+1] - return fmt.Sprintf("", next), nil - } - } - return "", nil -} - func (ds *dbusServer) SetEnabled(flag bool) *dbus.Error { log.Debug("SetEnabled(%v) called", flag) ds.fw.setEnabled(flag)