Help with godbus introspection


(Ken Bassford) #1

Hi folks,

Well I’m back at working on DBus again and due to the lack of examples resembling anything in the real world, I’m having a bit of trouble.

When I get introspection to work, I can only get one method to work (if you load another, it overwrites the first. See the server.go under _examples. On the other hand, I can get all my methods to work, but not introspection.

Here’s what I have currently …

type server struct {
    id int
}
var dbmethods []introspect.Method

// Foo : test export
func (server) Foo() (string, *dbus.Error) {
    return "Bar!", nil
}

// Ping : test
func (server) Ping() (string, *dbus.Error) {
    return "Pong!", nil
}

func (dbo dbusobj) registerServerMethods() error {
	// Register all methods associated with out server.
	var methods []reflect.Method
	serverType := reflect.TypeOf(server{})
	for i := 0; i < serverType.NumMethod(); i++ {
		servmethod := serverType.Method(i)
		methods = append(methods, servmethod)
		fmt.Println("Server Method:", servmethod.Name)
		fmt.Println("Server Method:", servmethod)
		methNames[servmethod.Name] = strings.ToLower(servmethod.Name)
		err := dbo.Conn.ExportWithMap(server{}, methNames, dbo.Path, dbo.Iface)
		if err != nil {
			return err
		}
		// Try to introspect.
		// node := &introspect.Node{}
		// node.Name = dbo.Iface
		// iface := &introspect.Interface{}
		// iface.Name = dbo.Iface
		// dbmethods = append(dbmethods, introspect.Methods(servmethod)[0])
		// iface.Methods = dbmethods
		// node.Interfaces = append(node.Interfaces, *iface)
		// dbusXMLinsp := introspect.NewIntrospectable(node)
		// fmt.Println("Method debug ...")   // Debug
		// printXML(fmt.Sprint(dbusXMLinsp)) // Debug
		// err = dbo.Conn.Export(dbusXMLinsp, dbo.Path, "org.freedesktop.DBus.Introspectable")
		// if err != nil {
		// 	return err
		// }

	}
	return nil
}

The commented-out portion is the part that I’m trying to get working. Any suggestions?


(Ken Bassford) #2

Anybody? I did not want to hard code the introspection (as I did the last time).


(Eric Lindblad) #3

There were a number of commits made in _examples on 4 Dec. 2019.

There are presently 2 open and 5 closed issues as follows:

introspect is:issue is:open

introspect is:issue is:closed

% date
Thu Dec 12 21:06:47 Rom 2019
%

(Ken Bassford) #4

Hi Eric,

Thank you for replying. Looking at the changes, they appear to be related to issue #183 (which I filed and subsequently closed). I took Mr. Southworth for a bit of a loop in creating a private instance of the system bus (for testing).

The problem is that the examples use two completely different techniques in registering methods (tied to a server struct), and registering introspection (tied to a typed string that MUST be a lowercase form of your function name). Even the current maintainer (Mr. Southworth) admits that he does not use the introspection in godbus. I looked at what he is doing, but it is tailored to his application too much to be an effective example.