func main() {
	conn, err := dbus.SystemBus()
	if err != nil {
		log.Fatalln(err)
	}
	reply, err := conn.RequestName("system.powermanager", dbus.NameFlagDoNotQueue)
	if err != nil {
		log.Fatalln(err)
	}
	if reply != dbus.RequestNameReplyPrimaryOwner {
		log.Fatalln("system.powermanager already registered")
	}
	log.Infoln(conn.Names())
	pm := NewPowerManager(conn)
	err = conn.Export(&pm, "/powermanager", "system.powermanager")
	if err != nil {
		log.Fatalln("export powermanager:", err)
	}
	err = conn.Export(introspect.Introspectable(introRoot), "/", "org.freedesktop.DBus.Introspectable")
	if err != nil {
		log.Fatalln("export powermanager (introspectable-root):", err)
	}
	err = conn.Export(introspect.Introspectable(intro), "/powermanager", "org.freedesktop.DBus.Introspectable")
	if err != nil {
		log.Fatalln("export powermanager (introspectable):", err)
	}

	log.Fatalln(exec.Command("/home/steam/app_run.sh").Run())
}
示例#2
0
文件: server.go 项目: 98pm/docker
func main() {
	conn, err := dbus.SessionBus()
	if err != nil {
		panic(err)
	}
	reply, err := conn.RequestName("com.github.guelfey.Demo",
		dbus.NameFlagDoNotQueue)
	if err != nil {
		panic(err)
	}
	if reply != dbus.RequestNameReplyPrimaryOwner {
		fmt.Fprintln(os.Stderr, "name already taken")
		os.Exit(1)
	}
	f := foo("Bar!")
	conn.Export(f, "/com/github/guelfey/Demo", "com.github.guelfey.Demo")
	conn.Export(introspect.Introspectable(intro), "/com/github/guelfey/Demo",
		"org.freedesktop.DBus.Introspectable")
	fmt.Println("Listening on com.github.guelfey.Demo / /com/github/guelfey/Demo ...")
	select {}
}
示例#3
0
func Run(p *player.Player) error {
	conn, err := dbus.SessionBus()
	if err != nil {
		return fmt.Errorf("Could not get session bus: %s", err)
	}

	reply, err := conn.RequestName(bus_name, dbus.NameFlagDoNotQueue)
	if err != nil {
		return fmt.Errorf("Could not request name: %s", err)
	}

	if reply != dbus.RequestNameReplyPrimaryOwner {
		return fmt.Errorf("Name already take")
	}

	bus_props_spec := map[string]map[string]*prop.Prop{
		bus_interface_player: {
			"PlaybackStatus": {
				p.Status.String(), false,
				prop.EmitTrue, nil,
			},

			"LoopStatus": {
				"none", true, prop.EmitTrue, SetLoopStatus,
			},

			"TrackMetadata": {
				map[string]string{}, false, prop.EmitTrue, nil,
			},

			"TrackPath": {
				"", false, prop.EmitTrue, nil,
			},

			"TrackLength": {
				float64(0), false, prop.EmitTrue, nil,
			},

			"TrackTitle": {
				"", false, prop.EmitTrue, nil,
			},

			"Tracks": {
				[]string{}, false, prop.EmitTrue, nil,
			},

			"Volume": {
				0.0, true, prop.EmitTrue, SetVolume,
			},
		},
	}

	bus = &Bus{
		player: p,
		props:  prop.New(conn, bus_path, bus_props_spec),
	}

	conn.Export(bus, bus_path, bus_interface_player)

	p.HandleStatusChange = HandleStatusChange
	p.HandleTrackChange = HandleTrackChange
	p.HandleTracksChange = HandleTracksChange
	p.HandleVolumeChange = HandleVolumeChange

	introspect := introspect.Introspectable(bus_introspection)
	conn.Export(introspect, bus_path, bus_interface_introspect)

	return nil
}