Hi Folks,

I have been trying to implement godbus's Export function to no avail.  
Looking at server.go (under the examples folder) is not very helpful as an 
inspection of export.go contains what appear to be cheater functions that 
enable the example to work.  Rename "Foo" to "Ping and it fails.

With that out of the way, I have not been able to find any current projects 
that utilize godbus server functions as a good example (I'm readily open to 
suggestions).  Snippets of what I currently have are as follows ...

First I created a structure to server as a basis for follow-on functions 
(since you can't expand *dbus.Conn as it is predefined in another package) 
...
```
type dbusobj struct {
Conn *dbus.Conn
Iface string
Path dbus.ObjectPath
}
```
.. a function to populate the structure ...
```
func newDbusObject(conn *dbus.Conn, iface string, path dbus.ObjectPath) 
dbusobj {
pdbo := new(dbusobj)
pdbo.Conn = conn
pdbo.Iface = iface
pdbo.Path = path
return *pdbo
}
```
... and a simple function to export a named method interface ...
```
func (co dbusobj) addResponseMethod(methodname string) error {
var methodxml = `
<node>
<interface name="` + co.Iface + `">
<method name="` + methodname + `">
<arg direction="out" type="s"/>
</method>
</interface>` + introspect.IntrospectDataString +
`</node>`
return co.Conn.Export(introspect.Introspectable(methodxml), co.Path, 
co.Iface)
}
```
Implementation of the above looks like this ...
```
// Create our private dbus connection structure
dbc := newDbusObject(conn, dbusiface, dbuspath)
err = dbc.addResponseMethod("Ping")
if err != nil {
fmt.Println("Failed to export method to system bus:", err)
}
```
The function does not throw any error, but an introspection of the dbus 
shows ...
```
DBUS_SYSTEM_BUS_ADDRESS="unix:path=/var/run/dbusalt/system_bus_socket" 
dbus-send --system --print-reply --type=method_call 
--dest='org.openxt.ndvm.wifi' '/org/openxt/ndvm/wifi' 
org.freedesktop.DBus.Introspectable.Introspect
method return time=1574178759.805460 sender=:1.0 -> destination=:1.1 
serial=4 reply_serial=2
   string "
<node>
<interface name="org.openxt.ndvm.wifi">
<method name="Foo">
<arg direction="out" type="s"/>
</method>
</interface>
<interface name="org.freedesktop.DBus.Introspectable">
<method name="Introspect">
<arg name="out" direction="out" type="s"/>
</method>
</interface>
</node>"

```
Calls to the unaltered "Foo" work, "Ping" does not (of course).

What am I doing wrong?
Are there some good (current) examples in a project where they have not 
abstracted the interface so much as to be useless for learning?
Is there a mailing list more suitable for these questions?  (I could not 
find one and I hate to open issues just to ask questions.)

It would be nice if someone updated the examples used under godbus to 
reflect what an actual user would have to go through to implement a full, 
usable method.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/04668c83-50da-40fa-bedf-49782f2ddf5c%40googlegroups.com.

Reply via email to