Guest User

Untitled

a guest
Oct 20th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "os"
  5. "fmt"
  6. "github.com/godbus/dbus"
  7. )
  8.  
  9. const (
  10. NETBOOK_BRIGHTNESS_FILE = "/sys/class/backlight/intel_backlight/brightness"
  11. SUSPEND_FILE = "/sys/power/state"
  12. )
  13.  
  14. type foo string
  15. type foo1 string
  16.  
  17. func (f foo) GetDevice() (string, *dbus.Error) {
  18. fmt.Println(f)
  19. return string(f), nil
  20. }
  21.  
  22. func (g foo1) Foo() (string, *dbus.Error) {
  23. fmt.Println(g)
  24. return string(g), nil
  25. }
  26.  
  27. func main() {
  28. conn, err := dbus.SystemBus()
  29. if err != nil {
  30. panic(err)
  31. }
  32. reply, err := conn.RequestName("org.cneo.cneod",
  33. dbus.NameFlagDoNotQueue)
  34. if err != nil {
  35. panic(err)
  36. }
  37. if reply != dbus.RequestNameReplyPrimaryOwner {
  38. fmt.Fprintln(os.Stderr, "name already taken")
  39. os.Exit(1)
  40. }
  41.  
  42. var f foo
  43. if _, err := os.Stat(NETBOOK_BRIGHTNESS_FILE); !os.IsNotExist(err) {
  44. f = foo("/org/cneo/Netbook")
  45. } else {
  46. f = foo("/org/cneo/GTA02")
  47. }
  48.  
  49. var g foo1
  50. g = foo1("bar")
  51. conn.Export(f, "/", "org.cneo.System")
  52. conn.Export(g, "/", "org.cneo.System")
  53. fmt.Println("Listening on org.cneo.cneod ...")
  54. select {}
  55. }
Add Comment
Please, Sign In to add comment