当前位置: 首页>>代码示例>>Golang>>正文


Golang Conn.RequestName方法代码示例

本文整理汇总了Golang中github.com/godbus/dbus.Conn.RequestName方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.RequestName方法的具体用法?Golang Conn.RequestName怎么用?Golang Conn.RequestName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/godbus/dbus.Conn的用法示例。


在下文中一共展示了Conn.RequestName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

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 {}
}
开发者ID:sjenning,项目名称:IoT-framework,代码行数:70,代码来源:devicehive-ble.go


注:本文中的github.com/godbus/dbus.Conn.RequestName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。