func recurseObjects(bus *dbus.Conn, service, prefix string) ([]string, error) { var s string err := bus.Object(service, dbus.ObjectPath(prefix)).Call("org.freedesktop.DBus.Introspectable.Introspect", 0).Store(&s) if err != nil { return nil, err } var n introspect.Node err = xml.Unmarshal([]byte(s), &n) if err != nil { return nil, err } names := make([]string, 0, 100) if len(n.Interfaces) > 1 { names = append(names, prefix) } for _, child := range n.Children { childPath := path.Join(prefix, child.Name) items, err := recurseObjects(bus, service, childPath) if err != nil { return nil, err } names = append(names, items...) } return names, nil }
func traverseDbusObjects(bus *dbus.Conn, dbusService, dbusPath string, fn func(path string, node *introspect.Node)) { var xmldata string var node introspect.Node var o = bus.Object(dbusService, dbus.ObjectPath(dbusPath)) err := o.Call("org.freedesktop.DBus.Introspectable.Introspect", 0).Store(&xmldata) if err != nil { log.Printf("Error getting introspect from [%s, %s]: %s", dbusService, dbusPath, err) } err = xml.NewDecoder(strings.NewReader(xmldata)).Decode(&node) if err != nil { log.Printf("Error decoding introspect from [%s, %s]: %s", dbusService, dbusPath, err) } // log.Printf("Introspect: %+v", node) if node.Name != "" && len(node.Interfaces) > 0 { fn(dbusPath, &node) } for _, child := range node.Children { traverseDbusObjects(bus, dbusService, dbusPath+"/"+child.Name, fn) } }
func newPrompter(conn *dbus.Conn) *prompter { p := new(prompter) p.cond = sync.NewCond(&p.lock) p.dbusObj = conn.Object("com.subgraph.FirewallPrompt", "/com/subgraph/FirewallPrompt") p.policyMap = make(map[string]*Policy) go p.promptLoop() return p }
func New(conn *dbus.Conn, name string) *Player { obj := conn.Object(name, dbusObjectPath).(*dbus.Object) return &Player{ &base{obj}, &player{obj}, } }
// SendNotification is same as Notifier.SendNotification // Provided for convenience. func SendNotification(conn *dbus.Conn, note Notification) (uint32, error) { obj := conn.Object(dbusNotificationsInterface, objectPath) call := obj.Call(notify, 0, note.AppName, note.ReplacesID, note.AppIcon, note.Summary, note.Body, note.Actions, note.Hints, note.ExpireTimeout) if call.Err != nil { return 0, call.Err } var ret uint32 err := call.Store(&ret) if err != nil { log.Printf("error getting uint32 ret value: %v", err) return ret, err } return ret, nil }
// dbusPath returns the dbus path of the job object. func (j *job) dbusPath(conn *dbus.Conn) (dbus.ObjectPath, error) { var jobpath dbus.ObjectPath // get the job path err := conn. Object(upstartServiceDBusPath, upstartManagerObject). Call("com.ubuntu.Upstart0_6.GetJobByName", 0, j.Name). Store(&jobpath) if err != nil { return jobpath, err } return jobpath, nil }
func systemdObject(conn *dbus.Conn) dbus.BusObject { return conn.Object("org.freedesktop.systemd1", dbus.ObjectPath("/org/freedesktop/systemd1")) }
func NewNotificationObject(conn *dbus.Conn) *NotificationObject { return &NotificationObject{ conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications"), } }
func NewCollection(conn *dbus.Conn, path dbus.ObjectPath) *Collection { return &Collection{ conn: conn, dbus: conn.Object(DBusServiceName, path), } }
func NewLogindObject(conn *dbus.Conn) *LogindObject { return &LogindObject{ conn.Object("org.freedesktop.login1", "/org/freedesktop/login1"), } }
func NewItem(conn *dbus.Conn, path dbus.ObjectPath) *Item { return &Item{ conn: conn, dbus: conn.Object(DBusServiceName, path), } }
func NewSession(conn *dbus.Conn, path dbus.ObjectPath) *Session { return &Session{ conn: conn, dbus: conn.Object(DBusServiceName, path), } }