func NewAllJoynBridge(bus *dbus.Conn) *AllJoynBridge { bridge := new(AllJoynBridge) bridge.bus = bus bridge.signals = make(chan *dbus.Signal, 100) bridge.services = make(map[string]*AllJoynServiceInfo) bridge.sessions = []uint32{} sbuffer := make(chan *dbus.Signal, 100) go bridge.signalsPump(sbuffer) bus.Signal(sbuffer) return bridge }
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() } } }