Beispiel #1
0
func initDBusIFC() error {
	var err error

	dbusObj, err = libdbus.NewDBusDaemon("org.freedesktop.DBus",
		"/")
	if err != nil {
		logger.Error("New DBusDaemon Failed: ", err)
		return err
	}

	mediaKeyObj, err = libkeybind.NewMediaKey(
		"com.deepin.daemon.KeyBinding",
		"/com/deepin/daemon/MediaKey")
	if err != nil {
		logger.Error("New MediaKey Object Failed: ", err)
		return err
	}

	loginObj, err = liblogin1.NewManager("org.freedesktop.login1",
		"/org/freedesktop/login1")
	if err != nil {
		logger.Error("New Login1 Manager Failed: ", err)
		return err
	}

	return nil
}
Beispiel #2
0
func isDBusSenderExist(sender string) bool {
	dbusDaemon, err := dbus.NewDBusDaemon("org.freedesktop.DBus", "/")
	if err != nil {
		logger.Error("Create freedesktop DBus failed:", err)
		return false
	}
	defer dbus.DestroyDBusDaemon(dbusDaemon)

	names, _ := dbusDaemon.ListNames()
	for _, name := range names {
		if name == sender {
			return true
		}
	}

	return false
}
Beispiel #3
0
func (m *EntryProxyerManager) watchEntries() {
	var err error
	busdaemon, err = pkgbus.NewDBusDaemon("org.freedesktop.DBus", "/org/freedesktop/DBus")
	if err != nil {
		panic(err)
	}

	// register existed entries
	names, err := busdaemon.ListNames()
	if err != nil {
		panic(err)
	}
	for _, n := range names {
		m.registerEntry(n)
	}

	// monitor name lost, name acquire
	busdaemon.ConnectNameOwnerChanged(func(name, oldOwner, newOwner string) {
		// if a new dbus session was installed, the name and newOwner
		// will be not empty, if a dbus session was uninstalled, the
		// name and oldOwner will be not empty
		if len(newOwner) != 0 {
			if name == "com.deepin.dde.TrayManager" {
				dbus.Emit(m, "TrayInited")
			}
			go func() {
				// FIXME: how long time should to wait for
				time.Sleep(60 * time.Millisecond)
				m.entrireLocker.Lock()
				defer m.entrireLocker.Unlock()
				m.registerEntry(name)
			}()
		} else {
			m.entrireLocker.Lock()
			defer m.entrireLocker.Unlock()
			m.unregisterEntry(name)
		}
	})
}