Esempio n. 1
0
func main() {
	// go func() {
	// 	log.Println(http.ListenAndServe("localhost:6060", nil))
	// }()

	var err error
	var bus *dbus.Conn
	bus, err = dbus.SystemBus()
	if err != nil {
		log.Panic(err)
	}

	reply, err := bus.RequestName("com.devicehive.bluetooth",
		dbus.NameFlagDoNotQueue)
	if err != nil {
		log.Panic(err)
	}

	if reply != dbus.RequestNameReplyPrimaryOwner {
		log.Fatal("name already taken")
	}

	w := NewBleDbusWrapper(bus)
	bus.Export(w, dbus.ObjectPath("/com/devicehive/bluetooth"), "com.devicehive.bluetooth")

	// Introspectable
	n := &introspect.Node{
		Interfaces: []introspect.Interface{
			{
				Name:    "com.devicehive.bluetooth",
				Methods: introspect.Methods(w),
				Signals: []introspect.Signal{
					introspect.Signal{
						Name: "PeripheralDiscovered",
						Args: []introspect.Arg{{"id", "s", "out"}, {"name", "s", "out"}, {"rssi", "i", "out"}},
					},
					introspect.Signal{
						Name: "PeripheralConnected",
						Args: []introspect.Arg{{"id", "s", "out"}},
					},
					introspect.Signal{
						Name: "PeripheralDisconnected",
						Args: []introspect.Arg{{"id", "s", "out"}},
					},
					introspect.Signal{
						Name: "NotificationReceived",
						Args: []introspect.Arg{{"mac", "s", "out"}, {"uuid", "s", "out"}, {"value", "s", "out"}},
					},
					introspect.Signal{
						Name: "IndicationReceived",
						Args: []introspect.Arg{{"mac", "s", "out"}, {"uuid", "s", "out"}, {"value", "s", "out"}},
					},
				},
			},
		},
	}

	root := &introspect.Node{
		Children: []introspect.Node{
			{
				Name: "com/devicehive/bluetooth",
			},
		},
	}

	bus.Export(introspect.NewIntrospectable(n), dbus.ObjectPath("/com/devicehive/bluetooth"), "org.freedesktop.DBus.Introspectable")
	bus.Export(introspect.NewIntrospectable(root), "/", "org.freedesktop.DBus.Introspectable") // workaroud for dbus issue #14

	select {}
}