本文整理汇总了Golang中github.com/godbus/dbus.SessionBus函数的典型用法代码示例。如果您正苦于以下问题:Golang SessionBus函数的具体用法?Golang SessionBus怎么用?Golang SessionBus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SessionBus函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Attach
// Attaches to the running Skype instance.
// Client must already be logged-in.
// More than one Skype client is unsupported.
func Attach() (*Connection, error) {
conn, err := dbus.SessionBus()
if err != nil {
return nil, err
}
c := &Connection{}
c.Events = make(chan Event, 10)
c.conn = conn
c.obj = conn.Object("com.Skype.API", "/com/Skype")
l := Listener{conn: c}
if err := conn.Export(l, "/com/Skype/Client", "com.Skype.API.Client"); err != nil {
return nil, err
}
if err := c.SetName("skype4go"); err != nil {
return nil, err
}
if err := c.SetProtocol(7); err != nil {
return nil, err
}
return c, nil
}
开发者ID:alexzorin,项目名称:skype4go,代码行数:29,代码来源:skype4go.go
示例2: Show
// Show sends the information in the notification object to the server to be
// displayed.
func (n Notification) Show() (id uint32, err error) {
conn, err := dbus.SessionBus()
if err != nil {
return
}
// We need to convert the interface type of the map to dbus.Variant as
// people dont want to have to import the dbus package just to make use
// of the notification hints.
hints := map[string]dbus.Variant{}
for k, v := range n.Hints {
hints[k] = dbus.MakeVariant(v)
}
obj := conn.Object(interfacePath, objectPath)
call := obj.Call(
notify,
0,
n.AppName,
n.ReplacesID,
n.AppIcon,
n.Summary,
n.Body,
n.Actions,
hints,
n.Timeout)
if err = call.Err; err != nil {
return
}
err = call.Store(&id)
return
}
开发者ID:xSmurf,项目名称:go-notify,代码行数:35,代码来源:notify.go
示例3: GetClient
// GetClient return a connection to the active instance of the internal Dbus
// service if any. Return nil, nil if none found.
// InterfacePath is an optional string to provide if the object use an interface
// path different from SrvObj
//
func GetClient(SrvObj, SrvPath string, InterfacePath ...string) (*Client, error) {
conn, ec := dbus.SessionBus()
if ec != nil {
return nil, ec
}
reply, e := conn.RequestName(SrvObj, dbus.NameFlagDoNotQueue)
if e != nil {
return nil, e
}
conn.ReleaseName(SrvObj)
if reply == dbus.RequestNameReplyPrimaryOwner { // no active instance.
return nil, errors.New("no service found")
}
if len(InterfacePath) == 0 { // Set default interface path = object name.
InterfacePath = []string{SrvObj}
}
// Found active instance, return client.
return &Client{
BusObject: conn.Object(SrvObj, dbus.ObjectPath(SrvPath)),
srvObj: InterfacePath[0],
testErr: func(e error, method string) {},
}, nil
}
开发者ID:sqp,项目名称:godock,代码行数:32,代码来源:dbuscommon.go
示例4: getAddressBookContactsFromDBus
// getAddgetAddressBookContactsFromDBus gets the phone contacts via the address-book DBus service
func getAddressBookContactsFromDBus() ([]textsecure.Contact, error) {
var o dbus.ObjectPath
var vcardContacts []string
conn, err := dbus.SessionBus()
if err != nil {
return nil, err
}
obj := conn.Object("com.canonical.pim", "/com/canonical/pim/AddressBook")
err = obj.Call("com.canonical.pim.AddressBook.query", 0, "", "", []string{}).Store(&o)
if err != nil {
return nil, err
}
obj2 := conn.Object("com.canonical.pim", o)
err = obj2.Call("com.canonical.pim.AddressBookView.contactsDetails", 0, []string{}, int32(0), int32(-1)).Store(&vcardContacts)
if err != nil {
return nil, err
}
obj.Call("com.canonical.pim.AddressBook.close", 0)
if err != nil {
return nil, err
}
return parseVCards(vcardContacts)
}
开发者ID:janimo,项目名称:textsecure-qml,代码行数:27,代码来源:contacts.go
示例5: main
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
flag.Parse()
conn, err := dbus.SessionBus()
if err != nil {
log.Fatal(err)
}
o := conn.Object("org.gnome.SessionManager", "/org/gnome/SessionManager")
inhibit(o, "inhibitor", "inhibiting", inhibitIdle)
inhibit(o, "inhibitor", "inhibiting", inhibitSuspend)
if *pid == 0 {
fmt.Fprint(os.Stderr, "Inhibiting until this process is killed\n")
select {}
}
fmt.Fprintf(os.Stderr, "Inhibiting until this process or PID %d is killed\n", *pid)
for {
_, err := os.Stat(fmt.Sprintf("/proc/%d", *pid))
if os.IsNotExist(err) {
break
}
if err != nil {
log.Fatal(err)
}
time.Sleep(*d)
}
}
开发者ID:Luit,项目名称:inhibitor,代码行数:26,代码来源:inhibitor.go
示例6: NewdbusWrapper
func NewdbusWrapper(path string, iface string) (*dbusWrapper, error) {
d := new(dbusWrapper)
conn, err := dbus.SystemBus()
if err != nil {
conn, err = dbus.SessionBus()
if err != nil {
log.Panic(err)
}
}
d.handlers = make(map[string]signalHandler)
d.conn = conn
d.path = path
d.iface = iface
d.queue = &signalQueue{cond: &sync.Cond{L: &sync.Mutex{}}}
heap.Init(d.queue)
filter := fmt.Sprintf("type='signal',path='%[1]s',interface='%[2]s',sender='%[2]s'", path, iface)
log.Printf("Filter: %s", filter)
conn.Object("org.freedesktop.DBus", "/org/freedesktop/DBus").Call("org.freedesktop.DBus.AddMatch", 0, filter)
go func() {
ch := make(chan *dbus.Signal, 2*QueueCapacity)
conn.Signal(ch)
for signal := range ch {
if !((strings.Index(signal.Name, iface) == 0) && (string(signal.Path) == path)) {
continue
}
if val, ok := d.handlers[signal.Name]; ok {
for d.queue.Len() > QueueCapacity-1 {
item := heap.Remove(d.queue, d.queue.Len()-1)
log.Printf("Removing %+v from queue", item)
}
heap.Push(d.queue, signalItem{handler: val, signal: signal, timestamp: uint64(time.Now().Unix())})
} else {
log.Printf("Unhandled signal: %s", signal.Name)
}
}
}()
go func() {
for {
d.queue.cond.L.Lock()
for d.queue.Len() == 0 {
d.queue.cond.Wait()
}
d.queue.cond.L.Unlock()
item := heap.Pop(d.queue).(signalItem)
item.handler.handler(item.signal.Body...)
}
}()
return d, nil
}
开发者ID:ndjido,项目名称:IoT-framework,代码行数:57,代码来源:wrapper.go
示例7: SessionBus
// SessionBus creates a Dbus session with a listening chan.
//
func SessionBus() (*dbus.Conn, chan *dbus.Signal, error) {
conn, e := dbus.SessionBus()
if e != nil {
return nil, nil, e
}
c := make(chan *dbus.Signal, 10)
conn.Signal(c)
return conn, c, nil
}
开发者ID:sqp,项目名称:godock,代码行数:12,代码来源:dbuscommon.go
示例8: newDesktopNotifications
func newDesktopNotifications() *desktopNotifications {
if _, err := dbus.SessionBus(); err != nil {
log.Printf("Error enabling dbus based notifications! %+v\n", err)
return createDesktopNotifications()
}
dn := createDesktopNotifications()
dn.supported = true
dn.notifications = make(map[string]uint32)
return dn
}
开发者ID:twstrike,项目名称:coyim,代码行数:11,代码来源:desktop_notifications_linux.go
示例9: SessionBus
// SessionBus is part of Interface
func (db *dbusImpl) SessionBus() (Connection, error) {
if db.sessionBus == nil {
bus, err := godbus.SessionBus()
if err != nil {
return nil, err
}
db.sessionBus = &connImpl{bus}
}
return db.sessionBus, nil
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:12,代码来源:dbus.go
示例10: CloseNotification
// CloseNotification closes the notification if it exists using its id.
func CloseNotification(id uint32) (err error) {
conn, err := dbus.SessionBus()
if err != nil {
return
}
obj := conn.Object(interfacePath, objectPath)
call := obj.Call(closeNotification, 0, id)
err = call.Err
return
}
开发者ID:xSmurf,项目名称:go-notify,代码行数:12,代码来源:notify.go
示例11: NewService
func NewService() (*Service, error) {
conn, err := dbus.SessionBus()
if err != nil {
return &Service{}, err
}
return &Service{
conn: conn,
dbus: conn.Object(DBusServiceName, DBusPath),
}, nil
}
开发者ID:99designs,项目名称:aws-vault,代码行数:11,代码来源:service.go
示例12: connDbus
func connDbus() *dbus.Object {
conn, err := dbus.SessionBus()
// couldnt connect to session bus
if err != nil {
panic(err)
}
return conn.Object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
}
开发者ID:hoffoo,项目名称:spotify-ctrl,代码行数:11,代码来源:spotify.go
示例13: main
func main() {
conn, err := dbus.SessionBus()
if err != nil {
panic(err)
}
node, err := introspect.Call(conn.Object("org.freedesktop.DBus", "/org/freedesktop/DBus"))
if err != nil {
panic(err)
}
data, _ := json.MarshalIndent(node, "", " ")
os.Stdout.Write(data)
}
开发者ID:98pm,项目名称:docker,代码行数:12,代码来源:introspect.go
示例14: ConnectToDBus
func ConnectToDBus(bus string) (*DBusClient, error) {
c := new(DBusClient)
var err error
switch bus {
case "session":
c.bus, err = dbus.SessionBus()
case "system":
c.bus, err = dbus.SystemBus()
default:
c.bus, err = dbus.Dial(bus)
}
if err != nil {
return nil, err
}
if !c.bus.SupportsUnixFDs() {
return nil, errors.New("DBus connection does not support file descriptors")
}
c.path = dbus.ObjectPath("/com/firelizzard/teasvc/Client")
err = c.bus.Export(c, c.path, "com.firelizzard.teasvc.Client")
if err != nil {
return nil, err
}
c.sigchans = make(map[string](chan *dbus.Signal))
chsig := make(chan *dbus.Signal, 10)
go func() {
for {
sig := <-chsig
ch, ok := c.sigchans[sig.Name]
if !ok {
log.Print("Unhandled signal: " + sig.Name)
}
select {
case ch <- sig:
// sent singal, done
default:
log.Print("Unhandled signal (full channel): " + sig.Name)
}
}
}()
c.bus.Signal(chsig)
c.bus.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, "type='signal',interface='com.firelizzard.teasvc',member='Pong'")
return c, nil
}
开发者ID:firelizzard18,项目名称:Tea-Service,代码行数:53,代码来源:DBusClient.go
示例15: GetCapabilities
// GetCapabilities returns the capabilities of the notification server.
func GetCapabilities() (c Capabilities, err error) {
conn, err := dbus.SessionBus()
if err != nil {
return
}
obj := conn.Object(interfacePath, objectPath)
call := obj.Call(getCapabilities, 0)
if err = call.Err; err != nil {
return
}
s := []string{}
if err = call.Store(&s); err != nil {
return
}
for _, v := range s {
switch v {
case "action-icons":
c.ActionIcons = true
break
case "actions":
c.Actions = true
break
case "body":
c.Body = true
break
case "body-hyperlinks":
c.BodyHyperlinks = true
break
case "body-images":
c.BodyImages = true
break
case "body-markup":
c.BodyMarkup = true
break
case "icon-multi":
c.IconMulti = true
break
case "icon-static":
c.IconStatic = true
break
case "persistence":
c.Persistence = true
break
case "sound":
c.Sound = true
break
}
}
return
}
开发者ID:xSmurf,项目名称:go-notify,代码行数:54,代码来源:notify.go
示例16: GetCapabilities
// GetCapabilities returns the capabilities of the notification server.
func GetCapabilities() (c Capabilities, err error) {
connection, err := dbus.SessionBus()
if err != nil {
return
}
obj := connection.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
call := obj.Call("org.freedesktop.Notifications.GetCapabilities", 0)
if call.Err != nil {
return Capabilities{}, call.Err
}
s := []string{}
if err = call.Store(&s); err != nil {
return
}
for _, v := range s {
switch v {
case "action-icons":
c.ActionIcons = true
break
case "actions":
c.Actions = true
break
case "body":
c.Body = true
break
case "body-hyperlinks":
c.BodyHyperlinks = true
break
case "body-images":
c.BodyImages = true
break
case "body-markup":
c.BodyMarkup = true
break
case "icon-multi":
c.IconMulti = true
break
case "icon-static":
c.IconStatic = true
break
case "persistence":
c.Persistence = true
break
case "sound":
c.Sound = true
break
}
}
return
}
开发者ID:postfix,项目名称:go-notify-1,代码行数:53,代码来源:notify.go
示例17: EavesDrop
// EavesDrop registers to receive Dbus events for custom parsing.
//
func EavesDrop(match string) (chan *dbus.Message, error) {
conn, e := dbus.SessionBus()
if e != nil {
return nil, e
}
e = conn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0, match).Err
if e != nil {
return nil, e
}
c := make(chan *dbus.Message, 10)
conn.Eavesdrop(c)
return c, nil
}
开发者ID:sqp,项目名称:godock,代码行数:15,代码来源:dbuscommon.go
示例18: CloseNotification
// CloseNotification closes the notification if it exists using its id.
func CloseNotification(id uint32) (err error) {
connection, err := dbus.SessionBus()
if err != nil {
return
}
obj := connection.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
call := obj.Call("org.freedesktop.Notifications.CloseNotification", 0, id)
if call.Err != nil {
return call.Err
}
return
}
开发者ID:postfix,项目名称:go-notify-1,代码行数:14,代码来源:notify.go
示例19: main
func main() {
conn, err := dbus.SessionBus()
if err != nil {
panic(err)
}
obj := conn.Object("org.freedesktop.Notifications", "/org/freedesktop/Notifications")
call := obj.Call("org.freedesktop.Notifications.Notify", 0, "", uint32(0),
"", "Test", "This is a test of the DBus bindings for go.", []string{},
map[string]dbus.Variant{}, int32(5000))
if call.Err != nil {
panic(call.Err)
}
}
开发者ID:98pm,项目名称:docker,代码行数:13,代码来源:notification.go
示例20: main
func main() {
conn, err := dbus.SessionBus()
if err != nil {
panic(err)
}
reply, err := conn.RequestName("com.github.guelfey.Demo",
dbus.NameFlagDoNotQueue)
if err != nil {
panic(err)
}
if reply != dbus.RequestNameReplyPrimaryOwner {
fmt.Fprintln(os.Stderr, "name already taken")
os.Exit(1)
}
propsSpec := map[string]map[string]*prop.Prop{
"com.github.guelfey.Demo": {
"SomeInt": {
int32(0),
true,
prop.EmitTrue,
func(c *prop.Change) *dbus.Error {
fmt.Println(c.Name, "changed to", c.Value)
return nil
},
},
},
}
f := foo("Bar")
conn.Export(f, "/com/github/guelfey/Demo", "com.github.guelfey.Demo")
props := prop.New(conn, "/com/github/guelfey/Demo", propsSpec)
n := &introspect.Node{
Name: "/com/github/guelfey/Demo",
Interfaces: []introspect.Interface{
introspect.IntrospectData,
prop.IntrospectData,
{
Name: "com.github.guelfey.Demo",
Methods: introspect.Methods(f),
Properties: props.Introspection("com.github.guelfey.Demo"),
},
},
}
conn.Export(introspect.NewIntrospectable(n), "/com/github/guelfey/Demo",
"org.freedesktop.DBus.Introspectable")
fmt.Println("Listening on com.github.guelfey.Demo / /com/github/guelfey/Demo ...")
c := make(chan *dbus.Signal)
conn.Signal(c)
for _ = range c {
}
}
开发者ID:98pm,项目名称:docker,代码行数:51,代码来源:prop.go
注:本文中的github.com/godbus/dbus.SessionBus函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论