8000 Some questions about DBus with Ignis · Issue #12 · linkfrg/ignis · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Some questions about DBus with Ignis #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gauravsatish opened this issue Oct 5, 2024 · 7 comments
Closed

Some questions about DBus with Ignis #12

gauravsatish opened this issue Oct 5, 2024 · 7 comments

Comments

@gauravsatish
Copy link
Contributor

Hello,

First off, I am somewhat new to this kind of stuff, ie, dbus, gtk etc, so apologies if I'm being stupid on my end.
Secondly, i hope this is the right forum to be asking such questions

My main problem is when using DBusProxy to call the method GetSession in the interface org.freedesktop.login1.Manager.

Here's the argument and return types of the method as show by gdbus introspect:
$ gdbus introspect --system --dest org.freedesktop.login1 --object-path /org/freedesktop/login1
Relevant Output:

interface org.freedesktop.login1.Manager {
    methods:
      GetSession(in s session_id, out o object_path);
}

And now here's my attempt:

Corresponding org.freedesktop.login1.Manager.xml in my code:

<node>
  <interface name="org.freedesktop.login1.Manager">
    <method name="GetSession">
      <arg type="s" name="session_id" direction="in"/>
      <arg type="o" name="object_path" direction="out"/>
    </method>
  </interface>
</node>

This is the code that will be calling the method:

self.__dbus = DBusProxy(
    name="org.freedesktop.login1",
    object_path="/org/freedesktop/login1",
    info=load_interface_xml("org.freedesktop.login1.Manager"),
    interface_name="org.freedesktop.login1.Manager"
)

sessionpath = self.__dbus.GetSession('(s)', str(sessionid)) # Assume sessionid to be predefined and correct

I'm assuming this to be correct, but I am not sure if this is how you go about it
the API Reference doesn't say anything about how to handle the return data, but i think this is correct (This could very well be wrong)

However, when i run this, this error is being created:
gi.repository.GLib.GError: g-dbus-error-quark: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name is not activatable (2) along with a large traceback which I can share if required

I think this is because it is using the user bus and not the system bus? Either that or my name value or info value is wrong in the DBusProxy initialisation
If its the former, how do i use the system bus
If its the latter, what would be the correct solution

Thanks

@linkfrg
Copy link
Owner
linkfrg commented Oct 5, 2024
  1. Yes, DBusProxy currently support only the session (user) bus.
    In principle, it is will be very easy to make support for the system bus, I am just not at home at the moment and will not be able to do everything here and now. In fact, this is implemented in feat: add UPower Service #10, but I think that I will revert all the commits to do everything again, since those changes related to dbus will not be needed specifically in this pull request after migrating to UPowerGlib. And I will add all the dbus related stuff as separate commits directly to the main branch.

  2. Regarding handling return data, you are doing everything right

  3. You added the interface xml to the Ignis source itself (ignis/dbus)? I didn't really think that anyone would use d-bus, so Utils.load_interface_xml() doesn't support any paths except ignis/dbus.

self.__dbus.GetSession('(s)', str(sessionid))

Here the second argument must be a tuple, so correctly will be this:
EDIT: Everything is ok

If you need it here and now you can use Gio.DbusProxy directly, but note that it does not support some features provided by the ignis implementation

@gauravsatish
Copy link
Contributor Author
gauravsatish commented Oct 5, 2024

Thank you so much,

  1. Yep I added the interface xml directly to ignis/dbus
  2. What features does the ignis implementation add?

Here the second argument must be a tuple

Could you elaborate on that? Does that mean that all arguments supplied to the DBus method must be wrapped in a tuple?

And once again, thank you so much. This project is really some wonderful work

@linkfrg
Copy link
Owner
linkfrg commented Oct 5, 2024
  1. Getting D-Bus properties using python way. Gio.DbusProxy only supports calling D-Bus methods.

  2. Not always, in the method you are calling the required type is "(s)", brackets () mean that the second argument must be a tuple. If there is just "s", you can pass simply a string. Usually d-bus methods require a tuple.

@gauravsatish
Copy link
Contributor Author

Actually the d-bus method just takes a string, not a struct/tuple. I was following the API Reference which says:

The first argument always needs to be the DBus signature tuple of the method call. Subsequent arguments must match the provided D-Bus signature.

with this given code example:

from ignis.dbus import DBusProxy
proxy = DBusProxy(...)
proxy.MyMethod("(is)", 42, "hello")

Initially I assumed that the () around is didn't denote anything special and was just a "requirement"
but if the () did denote a container type such as tuple, then shouldn't the statement be:

proxy.MyMethod("(is)", (42, "hello"))

@linkfrg
Copy link
Owner
linkfrg commented Oct 5, 2024

Oh wait, i forgot. For D-Bus methods you don't need to specify tuple, just provide all arguments in a row and pygobject will initialize Glib.Variant with tuple automatically. You only need to explicitly specify tuple if you manually initialize Glib.Variant.

Sorry for misleading you

And your original version of the d-bus method call is correct

@gauravsatish
Copy link
Contributor Author

All good, thank you

@linkfrg
Copy link
Owner
linkfrg commented Oct 8, 2024

Regarding system bus support, looks like #10 will not be merged soon, so i made a commit to the main branch: 47c7800

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0