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


Golang dbus.ObjectPath函数代码示例

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


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

示例1: onSubBuildMenu

// onSubBuildMenu fills the menu with stream actions: select device.
//
func (app *Applet) onSubBuildMenu(icon string, menu cdtype.Menuer) { // stream actions menu: select device.
	dev := app.pulse.Stream(dbus.ObjectPath(icon))

	mute, _ := dev.Bool("Mute")
	menu.AddCheckEntry("Mute volume", mute, func() {
		toggleMute(dev)
	})

	sel, es := dev.ObjectPath("Device")
	if log.Err(es) {
		return
	}
	app.menuAddDevices(menu, sel, "Output", func(sink dbus.ObjectPath) error {
		return dev.Call("Move", 0, sink).Err
	})

	// Kill works but seem to leave the client app into a bugged state (same for stream or client kill).
	// app.menu.Append("Kill", func() {
	// 	// log.Err(dev.Call("Kill", 0).Err, "Kill") // kill stream.
	// client, ec := dev.ObjectPath("Client")
	// if ec != nil {
	// 	return
	// }
	// app.pulse.Client.Client(client).Call("Kill", 0) // kill client.
	// })
}
开发者ID:sqp,项目名称:godock,代码行数:28,代码来源:audio.go

示例2: initDispatch

func (c *Conn) initDispatch() {
	ch := make(chan *dbus.Signal, signalBuffer)

	c.sysconn.Signal(ch)

	go func() {
		for {
			signal, ok := <-ch
			if !ok {
				return
			}

			switch signal.Name {
			case "org.freedesktop.systemd1.Manager.JobRemoved":
				c.jobComplete(signal)

				unitName := signal.Body[2].(string)
				var unitPath dbus.ObjectPath
				c.sysobj.Call("org.freedesktop.systemd1.Manager.GetUnit", 0, unitName).Store(&unitPath)
				if unitPath != dbus.ObjectPath("") {
					c.sendSubStateUpdate(unitPath)
				}
			case "org.freedesktop.systemd1.Manager.UnitNew":
				c.sendSubStateUpdate(signal.Body[1].(dbus.ObjectPath))
			case "org.freedesktop.DBus.Properties.PropertiesChanged":
				if signal.Body[0].(string) == "org.freedesktop.systemd1.Unit" {
					// we only care about SubState updates, which are a Unit property
					c.sendSubStateUpdate(signal.Path)
				}
			}
		}
	}()
}
开发者ID:98pm,项目名称:docker,代码行数:33,代码来源:subscription.go

示例3: onSubMiddleClick

func (app *Applet) onSubMiddleClick(icon string) {
	switch app.conf.MiddleAction {
	case 3: // TODO: need more actions and constants to define them.
		log.Debug("mute")
		toggleMute(app.pulse.Stream(dbus.ObjectPath(icon)))
	}
}
开发者ID:sqp,项目名称:godock,代码行数:7,代码来源:audio.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: fetchAboutData

func (a *AllJoynBridge) fetchAboutData(svcInfo *AllJoynServiceInfo, objInfo *AllJoynBindingInfo) error {
	obj := a.bus.Object(svcInfo.dbusService, dbus.ObjectPath(objInfo.dbusPath))
	call := obj.Call(AJ_ABOUT_GETABOUTDATA, 0, "en")
	if call.Err != nil {
		log.Printf("Error calling %s: %v", AJ_ABOUT_GETABOUTDATA, call.Err)
		return call.Err
	}

	//	fill aboutData with values

	call.Store(&aboutData)

	log.Printf("ABOUT: %+v", aboutData)

	for key, value := range aboutData {
		//		log.Printf("%s(%s)", key, value.Signature())
		switch value.Signature().String() {
		case "ay":
			C.SetProperty(C.CString(key), unsafe.Pointer(C.CString(fmt.Sprintf("%x", value.Value()))))
		default:
			C.SetProperty(C.CString(key), unsafe.Pointer(C.CString(value.String())))

		}

	}

	return nil
}
开发者ID:sjenning,项目名称:IoT-framework,代码行数:28,代码来源:devicehive-alljoyn.go

示例6: newDbusServer

func newDbusServer() (*dbusServer, error) {
	conn, err := dbus.SystemBus()
	if err != nil {
		return nil, err
	}

	reply, err := conn.RequestName(busName, dbus.NameFlagDoNotQueue)
	if err != nil {
		return nil, err
	}
	if reply != dbus.RequestNameReplyPrimaryOwner {
		return nil, errors.New("Bus name is already owned")
	}
	ds := &dbusServer{}

	if err := conn.Export(ds, objectPath, interfaceName); err != nil {
		return nil, err
	}

	ps := strings.Split(objectPath, "/")
	path := "/"
	for _, p := range ps {
		if len(path) > 1 {
			path += "/"
		}
		path += p

		if err := conn.Export(ds, dbus.ObjectPath(path), "org.freedesktop.DBus.Introspectable"); err != nil {
			return nil, err
		}
	}
	ds.conn = conn
	ds.prompter = newPrompter(conn)
	return ds, nil
}
开发者ID:Safe3,项目名称:fw-daemon,代码行数:35,代码来源:dbus.go

示例7: ObjectPath

// ObjectPath creates a dbus.ObjectPath using the rules that systemd uses for
// serializing special characters.
func ObjectPath(path string) dbus.ObjectPath {
	path = strings.Replace(path, ".", "_2e", -1)
	path = strings.Replace(path, "-", "_2d", -1)
	path = strings.Replace(path, "@", "_40", -1)

	return dbus.ObjectPath(path)
}
开发者ID:98pm,项目名称:docker,代码行数:9,代码来源:dbus.go

示例8: initConnection

func (c *Conn) initConnection() error {
	var err error
	c.sysconn, err = dbus.SystemBusPrivate()
	if err != nil {
		return err
	}

	// Only use EXTERNAL method, and hardcode the uid (not username)
	// to avoid a username lookup (which requires a dynamically linked
	// libc)
	methods := []dbus.Auth{dbus.AuthExternal(strconv.Itoa(os.Getuid()))}

	err = c.sysconn.Auth(methods)
	if err != nil {
		c.sysconn.Close()
		return err
	}

	err = c.sysconn.Hello()
	if err != nil {
		c.sysconn.Close()
		return err
	}

	c.sysobj = c.sysconn.Object("org.freedesktop.systemd1", dbus.ObjectPath("/org/freedesktop/systemd1"))

	// Setup the listeners on jobs so that we can get completions
	c.sysconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
		"type='signal', interface='org.freedesktop.systemd1.Manager', member='JobRemoved'")
	c.initSubscription()
	c.initDispatch()

	return nil
}
开发者ID:98pm,项目名称:docker,代码行数:34,代码来源:dbus.go

示例9: 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

示例10: 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

示例11: newDbus

func newDbus() (*logindDbus, error) {
	conn, err := dbus.SystemBusPrivate()
	if err != nil {
		return nil, err
	}

	methods := []dbus.Auth{dbus.AuthExternal(strconv.Itoa(os.Getuid()))}

	err = conn.Auth(methods)
	if err != nil {
		conn.Close()
		return nil, err
	}

	err = conn.Hello()
	if err != nil {
		conn.Close()
		return nil, err
	}

	object := conn.Object(dbusObject, dbus.ObjectPath(dbusPath))

	return &logindDbus{
		conn:   conn,
		object: object,
	}, nil
}
开发者ID:Jean-Daniel,项目名称:node_exporter,代码行数:27,代码来源:logind_linux.go

示例12: initConnection

func (c *Conn) initConnection() error {
	var err error
	c.sysconn, err = dbus.SystemBusPrivate()
	if err != nil {
		return err
	}

	err = c.sysconn.Auth(nil)
	if err != nil {
		c.sysconn.Close()
		return err
	}

	err = c.sysconn.Hello()
	if err != nil {
		c.sysconn.Close()
		return err
	}

	c.sysobj = c.sysconn.Object("org.freedesktop.systemd1", dbus.ObjectPath("/org/freedesktop/systemd1"))

	// Setup the listeners on jobs so that we can get completions
	c.sysconn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
		"type='signal', interface='org.freedesktop.systemd1.Manager', member='JobRemoved'")
	c.initSubscription()
	c.initDispatch()

	return nil
}
开发者ID:jcantrill,项目名称:geard,代码行数:29,代码来源:dbus.go

示例13: main

func main() {
	bus, err := dbus.SystemBus()
	bus.RequestName("com.devicehive.alljoyn.test.basic",
		dbus.NameFlagDoNotQueue)

	if err != nil {
		log.Panic(err)
	}

	basicService := NewBasicService(bus)

	bus.Export(basicService, "/com/devicehive/alljoyn/test/basic", "org.alljoyn.About")
	bus.Export(basicService, "/com/devicehive/alljoyn/test/basic", "org.alljoyn.Bus.sample")
	bus.Export(basicService, "/com/devicehive/alljoyn/test/basic", "org.freedesktop.DBus.Introspectable")

	// Now try to register ourself in AllJoyn via dbus
	go func() {
		bridge := bus.Object("com.devicehive.alljoyn.bridge", dbus.ObjectPath("/com/devicehive/alljoyn/bridge"))
		res := bridge.Call("com.devicehive.alljoyn.bridge.AddService", 0, "/com/devicehive/alljoyn/test/basic", "com.devicehive.alljoyn.test.basic", "/sample", "org.alljoyn.Bus.sample", "")
		log.Printf("Result: %+v", res)
		res = bridge.Call("com.devicehive.alljoyn.bridge.StartAllJoyn", 0, "com.devicehive.alljoyn.test.basic")
	}()

	select {}
}
开发者ID:ndjido,项目名称:IoT-framework,代码行数:25,代码来源:basic-service.go

示例14: initConnection

func (c *Conn) initConnection() error {
	var err error
	c.conn, err = dbus.SystemBusPrivate()
	if err != nil {
		return err
	}

	// Only use EXTERNAL method, and hardcode the uid (not username)
	// to avoid a username lookup (which requires a dynamically linked
	// libc)
	methods := []dbus.Auth{dbus.AuthExternal(strconv.Itoa(os.Getuid()))}

	err = c.conn.Auth(methods)
	if err != nil {
		c.conn.Close()
		return err
	}

	err = c.conn.Hello()
	if err != nil {
		c.conn.Close()
		return err
	}

	c.object = c.conn.Object("org.freedesktop.login1", dbus.ObjectPath(dbusPath))

	return nil
}
开发者ID:98pm,项目名称:docker,代码行数:28,代码来源:dbus.go

示例15: callRemoteMethod

func (m *AllJoynMessenger) callRemoteMethod(message *C.AJ_Message, path, member string, arguments []interface{}) (err error) {
	log.Printf("MSG: message.hdr=%p", message.hdr)
	remote := m.bus.Object(m.dbusService, dbus.ObjectPath(path))
	// log.Printf("%s Argument[0] %+v", member, reflect.ValueOf(arguments[0]).Type())
	res := remote.Call(member, 0, arguments...)

	if res.Err != nil {
		log.Printf("Error calling dbus method (%s): %s", member, res.Err)
		return res.Err
	}

	//pad := 4 - (int)(message.bodyBytes)%4
	//C.WriteBytes((*C.AJ_Message)(message), nil, (C.size_t)(0), (C.size_t)(pad))

	buf := new(bytes.Buffer)
	buf.Write(make([]byte, (int)(message.bodyBytes)))
	enc := ajmarshal.NewEncoderAtOffset(buf, (int)(message.bodyBytes), binary.LittleEndian)
	pad, err := enc.Encode(res.Body...)
	// log.Printf("Padding of the encoded buffer: %d", pad)
	if err != nil {
		log.Printf("Error encoding result: %s", err)
		return err
	}
	/*
		C.AJ_MarshalContainer((*C.AJ_Message)(message), (*C.AJ_Arg)(C.Get_Arg()), C.AJ_ARG_ARRAY)

		C.AJ_MarshalArgs_cgo((*C.AJ_Message)(message), C.CString("{sv}"), C.CString("DeviceName"), C.CString("s"), C.CString("Golang-device"))

		C.AJ_MarshalCloseContainer((*C.AJ_Message)(message), (*C.AJ_Arg)(C.Get_Arg()))
	*/
	//log.Printf("Encoded reply, len: %+v, %d", buf.Bytes(), buf.Len())
	// log.Printf("Length before: %d", message.bodyBytes)

	newBuf := buf.Bytes()[(int)(message.bodyBytes)+pad:]
	//log.Printf("Buffer to write into AllJoyn: %+v, %d", newBuf, len(newBuf))
	//	hdr := message.hdr
	//	if hdr.flags&C.uint8_t(C.AJ_FLAG_ENCRYPTED) == 0 {
	//		hdr = nil
	//	} else {
	//		message.hdr.flags &= ^C.uint8_t(C.AJ_FLAG_ENCRYPTED)
	//	}

	if len(newBuf) > 0 {
		log.Printf("MSG: message.hdr=%p", message.hdr)
		C.AJ_DeliverMsgPartial((*C.AJ_Message)(message), C.uint32_t(len(newBuf)))
		log.Printf("MSG: message.hdr=%p", message.hdr)

		C.AJ_MarshalRaw((*C.AJ_Message)(message), unsafe.Pointer(&newBuf[0]), C.size_t(len(newBuf)))
	} else {
		C.AJ_MarshalRaw((*C.AJ_Message)(message), unsafe.Pointer(&newBuf), C.size_t(0))
	}
	//log.Printf("New buff reply, len: %+v, %d", newBuf, len(newBuf))
	//	if hdr != nil {
	//		message.hdr = hdr
	//		message.hdr.flags &= ^C.uint8_t(C.AJ_FLAG_ENCRYPTED)
	//	}
	log.Printf("MSG: message.hdr=%p", message.hdr)
	return nil
}
开发者ID:sjenning,项目名称:IoT-framework,代码行数:59,代码来源:devicehive-alljoyn.go


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