本文整理汇总了Golang中github.com/godbus/dbus.Conn.Export方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.Export方法的具体用法?Golang Conn.Export怎么用?Golang Conn.Export使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/godbus/dbus.Conn
的用法示例。
在下文中一共展示了Conn.Export方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: exportDBusObject
// export main + introspectable DBus objects
func exportDBusObject(bus *dbus.Conn, w *DBusWrapper) {
bus.Export(w, ComDevicehiveCloudPath, ComDevicehiveCloudIface)
// main service interface
serviceInterface := introspect.Interface{
Name: ComDevicehiveCloudIface,
Methods: introspect.Methods(w),
Signals: []introspect.Signal{
{
Name: "CommandReceived",
Args: []introspect.Arg{
{"id", "t", "in"},
{"name", "s", "in"},
{"parameters", "s", "in"}, // JSON string
},
},
},
}
// main service node
n := &introspect.Node{
Name: ComDevicehiveCloudPath,
Interfaces: []introspect.Interface{
introspect.IntrospectData,
prop.IntrospectData,
serviceInterface},
}
n_obj := introspect.NewIntrospectable(n)
log.Tracef("%q introspectable: %s", ComDevicehiveCloudPath, n_obj)
bus.Export(n_obj, ComDevicehiveCloudPath, "org.freedesktop.DBus.Introspectable")
// root node
root := &introspect.Node{
Children: []introspect.Node{
{Name: ComDevicehiveCloudPath},
},
}
root_obj := introspect.NewIntrospectable(root)
log.Tracef("%q introspectable: %s", "/", root_obj)
bus.Export(root_obj, "/", "org.freedesktop.DBus.Introspectable")
}
示例2: wsImplementation
func wsImplementation(bus *dbus.Conn, config conf.Conf) {
var conn *ws.Conn
for {
info, err := rest.GetApiInfo(config.URL)
if err == nil {
say.Verbosef("API info: %+v", info)
c := ws.New(info.WebSocketServerUrl, config.DeviceID, config.SendNotificationQueueCapacity, func(m map[string]interface{}) {
p := m["parameters"]
params := ""
if p != nil {
b, err := json.Marshal(p)
if err != nil {
say.Fatalf("Could not generete JSON from command %+v\nWith error %s", m, err.Error())
}
params = string(b)
}
say.Verbosef("COMMAND %s -> %s(%v)", info.WebSocketServerUrl, m["command"].(string), params)
bus.Emit("/com/devicehive/cloud",
"com.devicehive.cloud.CommandReceived",
uint32(m["id"].(float64)),
m["command"].(string),
params)
})
conn = &c
if err == nil {
break
}
}
say.Infof("API info error: %s", err.Error())
time.Sleep(5 * time.Second)
}
w := NewDbusObjectWrapper(conn)
go conn.Run(config.AccessKey, func() {
conn.RegisterDevice(config.DeviceID, config.DeviceName, config.DeviceKey,
config.NetworkName, config.NetworkKey, config.NetworkDesc)
conn.Authenticate(config.DeviceID, config.DeviceKey)
conn.SubscribeCommands()
})
bus.Export(w, "/com/devicehive/cloud", DBusConnName)
// Introspectable
n := &introspect.Node{
Name: "/com/devicehive/cloud",
Interfaces: []introspect.Interface{
introspect.IntrospectData,
prop.IntrospectData,
{
Name: "com.devicehive.cloud",
Methods: introspect.Methods(w),
},
},
}
bus.Export(introspect.NewIntrospectable(n), "/com/devicehive/cloud", "org.freedesktop.DBus.Introspectable")
root := &introspect.Node{
Children: []introspect.Node{
{
Name: "com/devicehive/cloud",
},
},
}
bus.Export(introspect.NewIntrospectable(root), "/", "org.freedesktop.DBus.Introspectable")
select {}
}
示例3: New
// New returns a new Properties structure that manages the given properties.
// The key for the first-level map of props is the name of the interface; the
// second-level key is the name of the property. The returned structure will be
// exported as org.freedesktop.DBus.Properties on path.
func New(conn *dbus.Conn, path dbus.ObjectPath, props map[string]map[string]*Prop) *Properties {
p := &Properties{m: props, conn: conn, path: path}
conn.Export(p, path, "org.freedesktop.DBus.Properties")
return p
}
示例4: restImplementation
func restImplementation(bus *dbus.Conn, config conf.Conf) {
err := rest.DeviceRegisterEasy(config.URL, config.DeviceID, config.AccessKey,
config.DeviceName, config.DeviceKey, config.NetworkName,
config.NetworkKey, config.NetworkDesc)
if err != nil {
say.Infof("DeviceRegisterEasy error: %s", err.Error())
return
}
go func() {
nControl := rest.NewPollAsync()
cControl := rest.NewPollAsync()
nOut := make(chan rest.DeviceNotificationResource, 16)
cOut := make(chan rest.DeviceCmdResource, 16)
go rest.DeviceNotificationPollAsync(config.URL, config.DeviceID, config.AccessKey, nOut, nControl)
go rest.DeviceCmdPollAsync(config.URL, config.DeviceID, config.AccessKey, cOut, cControl)
for {
select {
case n := <-nOut:
parameters := ""
if n.Parameters != nil {
b, err := json.Marshal(n.Parameters)
if err != nil {
say.Infof("Could not generate JSON from parameters of notification %+v\nWith error %s", n, err.Error())
continue
}
parameters = string(b)
}
say.Verbosef("NOTIFICATION %s -> %s(%v)", config.URL, n.Notification, parameters)
bus.Emit(restObjectPath, restCommandName, uint32(n.Id), n.Notification, parameters)
case c := <-cOut:
parameters := ""
if c.Parameters != nil {
b, err := json.Marshal(c.Parameters)
if err != nil {
say.Infof("Could not generate JSON from parameters of command %+v\nWith error %s", c, err.Error())
continue
}
parameters = string(b)
}
say.Verbosef("COMMAND %s -> %s(%v)", config.URL, c.Command, parameters)
bus.Emit(restObjectPath, restCommandName, uint32(c.Id), c.Command, parameters)
}
}
}()
w := NewDbusRestWrapper(config)
bus.Export(w, "/com/devicehive/cloud", DBusConnName)
// Introspectable
n := &introspect.Node{
Name: "/com/devicehive/cloud",
Interfaces: []introspect.Interface{
introspect.IntrospectData,
prop.IntrospectData,
{
Name: "com.devicehive.cloud",
Methods: introspect.Methods(w),
},
},
}
bus.Export(introspect.NewIntrospectable(n), "/com/devicehive/cloud", "org.freedesktop.DBus.Introspectable")
root := &introspect.Node{
Children: []introspect.Node{
{
Name: "com/devicehive/cloud",
},
},
}
bus.Export(introspect.NewIntrospectable(root), "/", "org.freedesktop.DBus.Introspectable")
select {}
}
示例5: 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 {}
}