本文整理汇总了Golang中github.com/godbus/dbus.Conn类的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Conn类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ConnectEvents
// ConnectEvents registers to receive Dbus applet events.
//
func (cda *CDDbus) ConnectEvents(conn *dbus.Conn) (e error) {
cda.dbusIcon, e = dbuscommon.GetClient(dockpath.DbusObject, string(cda.busPath), dockpath.DbusInterfaceApplet)
if e != nil {
return e
}
cda.dbusSub, e = dbuscommon.GetClient(dockpath.DbusObject, string(cda.busPath)+"/sub_icons", dockpath.DbusInterfaceSubapplet)
if e != nil {
return e
}
if cda.dbusIcon == nil || cda.dbusSub == nil {
return errors.New("missing Dbus interface")
}
// Log all errors returned from DBus calls. Applets won't have to bother about that.
cda.dbusIcon.SetTestErr(cda.testErr)
cda.dbusSub.SetTestErr(cda.testErr)
// Listen to all events emitted for the icon.
matchIcon := "type='signal',path='" + string(cda.busPath) + "',interface='" + dockpath.DbusInterfaceApplet + "',sender='" + dockpath.DbusObject + "'"
matchSubs := "type='signal',path='" + string(cda.busPath) + "/sub_icons',interface='" + dockpath.DbusInterfaceSubapplet + "',sender='" + dockpath.DbusObject + "'"
e = conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, matchIcon).Err
if cda.log.Err(e, "connect to icon DBus events") {
return e
}
e = conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, matchSubs).Err
cda.log.Err(e, "connect to subicons DBus events")
return e
}
开发者ID:sqp,项目名称:godock,代码行数:34,代码来源:appdbus.go
示例2: SubscribeToSignals
func SubscribeToSignals(bus *dbus.Conn, service *AllJoynServiceInfo) {
for _, obj := range service.objects {
query := "type='signal',sender='" + service.dbusService + "',path='" + obj.dbusPath + "'"
bus.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, query)
// log.Printf("FILTERING SIGNALS: %s", query)
}
}
开发者ID:sjenning,项目名称:IoT-framework,代码行数:7,代码来源:devicehive-alljoyn.go
示例3: traverseDbusObjects
func traverseDbusObjects(bus *dbus.Conn, dbusService, dbusPath string, fn func(path string, node *introspect.Node)) {
var xmldata string
var node introspect.Node
var o = bus.Object(dbusService, dbus.ObjectPath(dbusPath))
err := o.Call("org.freedesktop.DBus.Introspectable.Introspect", 0).Store(&xmldata)
if err != nil {
log.Printf("Error getting introspect from [%s, %s]: %s", dbusService, dbusPath, err)
}
err = xml.NewDecoder(strings.NewReader(xmldata)).Decode(&node)
if err != nil {
log.Printf("Error decoding introspect from [%s, %s]: %s", dbusService, dbusPath, err)
}
// log.Printf("Introspect: %+v", node)
if node.Name != "" && len(node.Interfaces) > 0 {
fn(dbusPath, &node)
}
for _, child := range node.Children {
traverseDbusObjects(bus, dbusService, dbusPath+"/"+child.Name, fn)
}
}
开发者ID:sjenning,项目名称:IoT-framework,代码行数:25,代码来源:devicehive-alljoyn.go
示例4: recurseObjects
func recurseObjects(bus *dbus.Conn, service, prefix string) ([]string, error) {
var s string
err := bus.Object(service, dbus.ObjectPath(prefix)).Call("org.freedesktop.DBus.Introspectable.Introspect", 0).Store(&s)
if err != nil {
return nil, err
}
var n introspect.Node
err = xml.Unmarshal([]byte(s), &n)
if err != nil {
return nil, err
}
names := make([]string, 0, 100)
if len(n.Interfaces) > 1 {
names = append(names, prefix)
}
for _, child := range n.Children {
childPath := path.Join(prefix, child.Name)
items, err := recurseObjects(bus, service, childPath)
if err != nil {
return nil, err
}
names = append(names, items...)
}
return names, nil
}
开发者ID:mastercactapus,项目名称:dbus-inspector,代码行数:30,代码来源:app.go
示例5: newPrompter
func newPrompter(conn *dbus.Conn) *prompter {
p := new(prompter)
p.cond = sync.NewCond(&p.lock)
p.dbusObj = conn.Object("com.subgraph.FirewallPrompt", "/com/subgraph/FirewallPrompt")
p.policyMap = make(map[string]*Policy)
go p.promptLoop()
return p
}
开发者ID:Safe3,项目名称:fw-daemon,代码行数:8,代码来源:prompt.go
示例6: New
func New(conn *dbus.Conn, name string) *Player {
obj := conn.Object(name, dbusObjectPath).(*dbus.Object)
return &Player{
&base{obj},
&player{obj},
}
}
开发者ID:emersion,项目名称:go-mpris,代码行数:8,代码来源:mpris.go
示例7: ListServices
func ListServices(bus *dbus.Conn) ([]string, error) {
if bus == nil {
return nil, fmt.Errorf("bus not available")
}
var services []string
err := bus.BusObject().Call("org.freedesktop.DBus.ListNames", 0).Store(&services)
if err != nil {
return nil, err
}
return services, nil
}
开发者ID:mastercactapus,项目名称:dbus-inspector,代码行数:11,代码来源:main.go
示例8: NewAllJoynBridge
func NewAllJoynBridge(bus *dbus.Conn) *AllJoynBridge {
bridge := new(AllJoynBridge)
bridge.bus = bus
bridge.signals = make(chan *dbus.Signal, 100)
bridge.services = make(map[string]*AllJoynServiceInfo)
bridge.sessions = []uint32{}
sbuffer := make(chan *dbus.Signal, 100)
go bridge.signalsPump(sbuffer)
bus.Signal(sbuffer)
return bridge
}
开发者ID:kgoutsos,项目名称:IoT-framework,代码行数:13,代码来源:alljoyn-bridge.go
示例9: mainLoop
// main loop
func mainLoop(bus *dbus.Conn, service devicehive.Service, config conf.Conf) {
// getting server info
info, err := service.GetServerInfo(waitTimeout)
if err != nil {
log.Warnf("Cannot get service info (error: %s)", err)
return
}
// registering device
device := devicehive.NewDevice(config.DeviceID, config.DeviceName,
devicehive.NewDeviceClass("go-gateway-class", "0.1"))
device.Key = config.DeviceKey
if len(config.NetworkName) != 0 || len(config.NetworkKey) != 0 {
device.Network = devicehive.NewNetwork(config.NetworkName, config.NetworkKey)
device.Network.Description = config.NetworkDesc
}
err = service.RegisterDevice(device, waitTimeout)
if err != nil {
log.Warnf("Cannot register device (error: %s)", err)
return
}
// start polling commands
listener, err := service.SubscribeCommands(device, info.Timestamp, waitTimeout)
if err != nil {
log.Warnf("Cannot subscribe commands (error: %s)")
return
}
wrapper := DBusWrapper{service: service, device: device}
exportDBusObject(bus, &wrapper)
for {
select {
case cmd := <-listener.C:
params := ""
if cmd.Parameters != nil {
buf, err := json.Marshal(cmd.Parameters)
if err != nil {
log.Warnf("Cannot generate JSON from parameters of command %+v (error: %s)", cmd, err)
continue
}
params = string(buf)
}
log.Infof("COMMAND %s -> %s(%v)", config.URL, cmd.Name, params)
bus.Emit(ComDevicehiveCloudPath, ComDevicehiveCloudIface+".CommandReceived", cmd.Id, cmd.Name, params)
}
//time.Sleep(5 * time.Second)
}
}
开发者ID:ndjido,项目名称:IoT-framework,代码行数:52,代码来源:main-loop.go
示例10: List
func List(conn *dbus.Conn) ([]string, error) {
var names []string
err := conn.BusObject().Call("org.freedesktop.DBus.ListNames", 0).Store(&names)
if err != nil {
return nil, err
}
var mprisNames []string
for _, name := range names {
if strings.HasPrefix(name, baseInterface) {
mprisNames = append(mprisNames, name)
}
}
return mprisNames, nil
}
开发者ID:emersion,项目名称:go-mpris,代码行数:15,代码来源:mpris.go
示例11: dbusSignalHandler
func (fw *Interface) dbusSignalHandler(bus *dbus.Conn) {
rule := fmt.Sprintf("type='signal',sender='%s',path='%s',interface='%s',member='Reloaded'", firewalldName, firewalldPath, firewalldInterface)
bus.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)
rule = fmt.Sprintf("type='signal',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus',sender='org.freedesktop.DBus',arg0='%s'", firewalldName)
bus.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, rule)
signal := make(chan *dbus.Signal, 10)
bus.Signal(signal)
for s := range signal {
if s.Name == "org.freedesktop.DBus.NameOwnerChanged" {
name := s.Body[0].(string)
new_owner := s.Body[2].(string)
if name != firewalldName || len(new_owner) == 0 {
continue
}
// FirewallD startup (specifically the part where it deletes
// all existing iptables rules) may not yet be complete when
// we get this signal, so make a dummy request to it to
// synchronize.
fw.obj.Call(firewalldInterface+".getDefaultZone", 0)
fw.reload()
} else if s.Name == firewalldInterface+".Reloaded" {
fw.reload()
}
}
}
开发者ID:nitintutlani,项目名称:origin,代码行数:31,代码来源:firewalld.go
示例12: SendNotification
// SendNotification is same as Notifier.SendNotification
// Provided for convenience.
func SendNotification(conn *dbus.Conn, note Notification) (uint32, error) {
obj := conn.Object(dbusNotificationsInterface, objectPath)
call := obj.Call(notify, 0,
note.AppName,
note.ReplacesID,
note.AppIcon,
note.Summary,
note.Body,
note.Actions,
note.Hints,
note.ExpireTimeout)
if call.Err != nil {
return 0, call.Err
}
var ret uint32
err := call.Store(&ret)
if err != nil {
log.Printf("error getting uint32 ret value: %v", err)
return ret, err
}
return ret, nil
}
开发者ID:emersion,项目名称:notify,代码行数:24,代码来源:notification.go
示例13: dbusPath
// dbusPath returns the dbus path of the job object.
func (j *job) dbusPath(conn *dbus.Conn) (dbus.ObjectPath, error) {
var jobpath dbus.ObjectPath
// get the job path
err := conn.
Object(upstartServiceDBusPath, upstartManagerObject).
Call("com.ubuntu.Upstart0_6.GetJobByName", 0, j.Name).
Store(&jobpath)
if err != nil {
return jobpath, err
}
return jobpath, nil
}
开发者ID:amoghe,项目名称:go-upstart,代码行数:16,代码来源:job.go
示例14: monitor
func monitor(conn *dbus.Conn, name string) {
call := conn.BusObject().Call("org.freedesktop.DBus.Monitoring.BecomeMonitor", 0, []string{}, uint32(0))
if call.Err != nil {
log.Warnln("BecomeMonitor not supported, falling back to AddMatch:", call.Err)
for _, v := range []string{"method_call", "method_return", "error", "signal"} {
call = conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
"eavesdrop='true',type='"+v+"'")
if call.Err != nil {
log.Fatalln("add match:", call.Err)
}
}
}
ch := make(chan *dbus.Message, 1000)
conn.Eavesdrop(ch)
log.Infoln("Monitoring", name, "bus")
for m := range ch {
log.WithField("bus", name).Infoln(m)
}
}
开发者ID:mastercactapus,项目名称:dbus-inspector,代码行数:20,代码来源:main.go
示例15: 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")
}
开发者ID:ndjido,项目名称:IoT-framework,代码行数:42,代码来源:main-loop.go
示例16: NewCollection
func NewCollection(conn *dbus.Conn, path dbus.ObjectPath) *Collection {
return &Collection{
conn: conn,
dbus: conn.Object(DBusServiceName, path),
}
}
开发者ID:99designs,项目名称:aws-vault,代码行数:6,代码来源:collection.go
示例17: systemdObject
func systemdObject(conn *dbus.Conn) dbus.BusObject {
return conn.Object("org.freedesktop.systemd1", dbus.ObjectPath("/org/freedesktop/systemd1"))
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:3,代码来源:dbus.go
示例18: 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
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:9,代码来源:prop.go
示例19: NewSession
func NewSession(conn *dbus.Conn, path dbus.ObjectPath) *Session {
return &Session{
conn: conn,
dbus: conn.Object(DBusServiceName, path),
}
}
开发者ID:99designs,项目名称:aws-vault,代码行数:6,代码来源:session.go
示例20: NewItem
func NewItem(conn *dbus.Conn, path dbus.ObjectPath) *Item {
return &Item{
conn: conn,
dbus: conn.Object(DBusServiceName, path),
}
}
开发者ID:99designs,项目名称:aws-vault,代码行数:6,代码来源:item.go
注:本文中的github.com/godbus/dbus.Conn类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论