Esempio n. 1
0
func monitor(conn *dbus.Conn, name string) {
	call := conn.BusObject().Call("org.freedesktop.DBus.Monitoring.BecomeMonitor", 0, []string{}, uint32(0))
	if call.Err != nil {
		log.Warnln("BecomeMonitor not supported, falling back to AddMatch:", call.Err)
		for _, v := range []string{"method_call", "method_return", "error", "signal"} {
			call = conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
				"eavesdrop='true',type='"+v+"'")
			if call.Err != nil {
				log.Fatalln("add match:", call.Err)
			}
		}
	}

	ch := make(chan *dbus.Message, 1000)
	conn.Eavesdrop(ch)
	log.Infoln("Monitoring", name, "bus")
	for m := range ch {
		log.WithField("bus", name).Infoln(m)
	}
}