示例#1
0
文件: dbus.go 项目: jcswart/godock
// Connect the applet manager to the Cairo-Dock core. Saves interfaces to the
// icon and subicon DBus interfaces and connects events callbacks.
//
func (cda *CdDbus) ConnectToBus() (e error) {
	cda.dbus, e = dbus.Connect(dbus.SessionBus)
	if e != nil {
		log.Info("DBus Connect", e)
		return e
	}
	if e = cda.dbus.Authenticate(); e != nil {
		log.Info("Failed Connection.Authenticate:", e.Error())
		return e
	}

	cda.dbusIcon = cda.dbus.Object(DbusObject, cda.BusPath).Interface(DbusInterfaceApplet)
	cda.dbusSub = cda.dbus.Object(DbusObject, cda.BusPath+"/sub_icons").Interface(DbusInterfaceSubapplet)
	if cda.dbusIcon == nil || cda.dbusSub == nil {
		return errors.New("No DBus interface")
	}

	// Connect defined events callbacks.
	typ := reflect.TypeOf(cda.Events)
	elem := reflect.ValueOf(&cda.Events).Elem()
	for i := 0; i < typ.NumField(); i++ { // Parsing all fields in type.
		cda.connectEvent(elem.Field(i), typ.Field(i))
	}
	return nil
}
示例#2
0
func TestList(t *testing.T) {
	bus, err := dbus.Connect(dbus.SystemBus)
	if err != nil {
		t.Fatal(err)
	}
	err = bus.Authenticate()
	if err != nil {
		t.Fatal(err)
	}

	out, err := ListUnits(bus)
	if err != nil {
		t.Fatal(err)
	}
	buf := new(bytes.Buffer)
	PrintUnits(buf, out)
	t.Logf("%s", buf)
}