Example #1
0
// ConnectEvents registers to receive Dbus applet events.
//
func (cda *CDDbus) ConnectEvents(conn *dbus.Conn) (e error) {
	cda.dbusIcon, e = dbuscommon.GetClient(dockpath.DbusObject, string(cda.busPath), dockpath.DbusInterfaceApplet)
	if e != nil {
		return e
	}

	cda.dbusSub, e = dbuscommon.GetClient(dockpath.DbusObject, string(cda.busPath)+"/sub_icons", dockpath.DbusInterfaceSubapplet)
	if e != nil {
		return e
	}

	if cda.dbusIcon == nil || cda.dbusSub == nil {
		return errors.New("missing Dbus interface")
	}

	// Log all errors returned from DBus calls. Applets won't have to bother about that.
	cda.dbusIcon.SetTestErr(cda.testErr)
	cda.dbusSub.SetTestErr(cda.testErr)

	// Listen to all events emitted for the icon.
	matchIcon := "type='signal',path='" + string(cda.busPath) + "',interface='" + dockpath.DbusInterfaceApplet + "',sender='" + dockpath.DbusObject + "'"
	matchSubs := "type='signal',path='" + string(cda.busPath) + "/sub_icons',interface='" + dockpath.DbusInterfaceSubapplet + "',sender='" + dockpath.DbusObject + "'"

	e = conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, matchIcon).Err
	if cda.log.Err(e, "connect to icon DBus events") {
		return e
	}
	e = conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, matchSubs).Err
	cda.log.Err(e, "connect to subicons DBus events")

	return e
}
func SubscribeToSignals(bus *dbus.Conn, service *AllJoynServiceInfo) {
	for _, obj := range service.objects {
		query := "type='signal',sender='" + service.dbusService + "',path='" + obj.dbusPath + "'"
		bus.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, query)
		// log.Printf("FILTERING SIGNALS: %s", query)
	}
}
Example #3
0
func ListServices(bus *dbus.Conn) ([]string, error) {
	if bus == nil {
		return nil, fmt.Errorf("bus not available")
	}
	var services []string
	err := bus.BusObject().Call("org.freedesktop.DBus.ListNames", 0).Store(&services)
	if err != nil {
		return nil, err
	}
	return services, nil
}
Example #4
0
func List(conn *dbus.Conn) ([]string, error) {
	var names []string
	err := conn.BusObject().Call("org.freedesktop.DBus.ListNames", 0).Store(&names)
	if err != nil {
		return nil, err
	}

	var mprisNames []string
	for _, name := range names {
		if strings.HasPrefix(name, baseInterface) {
			mprisNames = append(mprisNames, name)
		}
	}
	return mprisNames, nil
}
Example #5
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)
	}
}
Example #6
-1
func (fw *Interface) dbusSignalHandler(bus *dbus.Conn) {
	rule := fmt.Sprintf("type='signal',sender='%s',path='%s',interface='%s',member='Reloaded'", firewalldName, firewalldPath, firewalldInterface)
	bus.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)

	rule = fmt.Sprintf("type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus',sender='org.freedesktop.DBus',arg0='%s'", firewalldName)
	bus.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)

	signal := make(chan *dbus.Signal, 10)
	bus.Signal(signal)

	for s := range signal {
		if s.Name == "org.freedesktop.DBus.NameOwnerChanged" {
			name := s.Body[0].(string)
			new_owner := s.Body[2].(string)

			if name != firewalldName || len(new_owner) == 0 {
				continue
			}

			// FirewallD startup (specifically the part where it deletes
			// all existing iptables rules) may not yet be complete when
			// we get this signal, so make a dummy request to it to
			// synchronize.
			fw.obj.Call(firewalldInterface+".getDefaultZone", 0)

			fw.reload()
		} else if s.Name == firewalldInterface+".Reloaded" {
			fw.reload()
		}
	}
}