amenzhinsky / dbus-codegen-go

D-Bus code-generation for golang
MIT License
16 stars 14 forks source link

Expose interfaces for introspection #12

Open GaikwadPratik opened 2 years ago

GaikwadPratik commented 2 years ago

This extends @knightpp's idea and actually exposes interfaces for introspection when server is running.

Related to #8 and #9

GaikwadPratik commented 2 years ago

@amenzhinsky,

Hope you had nice weekend...

any thoughts on PR?

amenzhinsky commented 2 years ago

Hi @GaikwadPratik, sorry for the late response.

Thanks I really did :)

I don't quite understand the need of the feature, can you give an example?

GaikwadPratik commented 2 years ago

Hi @amenzhinsky,

I believe you are familiar with dbus-inspect.

In the attached video, first half is WITHOUT the PR while the second is WITH the PR.

https://user-images.githubusercontent.com/5595263/164250552-3509e6ee-8b10-4057-b976-e163209242c1.mp4

Basically, I'm writing a dbus-service(server instance) in Golang. When another developer wants to interact with the service, they WILL NOT know the interface(s) definition unless

  1. they look at source code OR
  2. perform Introspection on service at object path OR
  3. I will have to hardcode interface in the source code as shown here. I prefer to keep xml separate from code.

As shown in the above video, introspection returns nothing without the changes in PR.

GaikwadPratik commented 2 years ago

@amenzhinsky ,

I hope above video and explanation was sufficient. Basic answer is that you won't be able to introspect and by extension call dbus server unless you know the api correctly from somewhere. I can't explain or provide any example simple than this.

P.S. I apologize for high resolution of the video. It would be better if you download it and then view it.

amenzhinsky commented 2 years ago

So, to generate server-side code you already have an introspection xml file, you can export org.freedesktop.DBus.Introspectable.Introspect that has only one method Introspect() string which can return its content.

GaikwadPratik commented 2 years ago

@amenzhinsky ,

That didn't help. Please see attached video.

https://user-images.githubusercontent.com/5595263/165413843-6ab70576-b9a6-4443-8684-1c54471b732f.mp4

The example in above video is from clien_server. Perhaps you can directly update that.

P.S. please point out if I am doing any mistake in the above video

amenzhinsky commented 2 years ago

You need to do something like this:

conn.ExportMethodTable(map[string]interface{}{
    "Introspect": func() string {
        return "your-xml-goes-here"
    },
}, "/org/example/Demo", "org.freedesktop.DBus.Introspectable.Introspect")
GaikwadPratik commented 2 years ago

that's what this PR does. Just automatically instead of asking consumers to do it manually. Or am I missing something?

maltegrosse commented 1 year ago

would be great to see this PR merged.... @GaikwadPratik have you also considered in your PR the Unexport function?

maltegrosse commented 1 year ago

@GaikwadPratik adding err := conn.Export(nil, path, "org.freedesktop.DBus.Introspectable") if err != nil { return err } to the unexport method seems to work

By trying to access the properties, I get following error: string "Object does not implement the interface 'org.freedesktop.DBus.Properties'"

GaikwadPratik commented 1 year ago

@maltegrosse ,

err := conn.Export(nil, path, "org.freedesktop.DBus.Introspectable") if err != nil { return err } to the unexport method seems to work

Though I am not sure why would we want to UnExport these, I'll try to work on it.

By trying to access the properties, I get following error: string "Object does not implement the interface 'org.freedesktop.DBus.Properties'"

Last time I tried this, it worked. How are you trying to access it?