Skip to content
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

Add support for deep introspection #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leogermond
Copy link

@leogermond leogermond commented Apr 7, 2017

This commit adds support for a deep object introspection; it means that any child object that is described with a node tag, will be introspected as well, recursively.
This way a whole hierarchy of objects can be introspected in a single get() call.

The children are then added to the nodes dictionnary attribute.

Typical use case is:

from pydbus import SystemBus
s = SystemBus()
bluez = s.get('org.bluez')
bluez.nodes[bluez.nodes.keys()[0]].StartDiscovery()

Instead of the more complicated:

from pydbus import SystemBus
from xml.etree import ElementTree
s = SystemBus()
bluez = s.get('org.bluez')
et = ElementTree.fromstring(bluez.Introspect())
nodes = {n: s.get('org.bluez', '/org/bluez/' + n) for n in [
    e.attrib['name'] for e in et if e.tag == 'node' ] }
nodes[bluez.nodes.keys()[0]].StartDiscovery()

@leogermond leogermond changed the title add support for deep introspection Add support for deep introspection Apr 7, 2017
@ukBaz
Copy link

ukBaz commented Apr 7, 2017

On BlueZ if I want to get all of the objects I get it by:

from pydbus import SystemBus
bus = SystemBus()
mngr = bus.get('org.bluez', '/')
mngr_objs = mngr.GetManagedObjects()

This returns a dictionary of all the items. Is this doing the same at your deep object introspection?

@leogermond
Copy link
Author

leogermond commented Apr 7, 2017

Ho ok; I did not know how to access GetManagedObjects so that's great. Introspection and ObjectManager are two different way of doing that kind of stuff but ObjectManager is actually the one used by Bluez and it's more versatile. Thanks for the tip 👍

@hcoin
Copy link

hcoin commented Apr 7, 2017

Apropos, take a look at https://github.com/hcoin/pydbus/wiki
There is defined an entire translation infrastructure that moves dbus closer to what than how.
Named variables, introspection including when python to dbus that has a 'v', etc.

@leogermond
Copy link
Author

leogermond commented Apr 7, 2017

That's neat, it seems to be convergent with the efforts I'm making to build open IoT devices that "just work".

@hcoin
Copy link

hcoin commented Apr 7, 2017

I'm hoping those who publish dbus services, or those who care about dbus services use in python, will maintain the translation dictionaries necessary. The whole point is to remove from the python dbus user the obligation to keep track of which variable goes in what position, glue code to create 'call by reference', all the engine room stuff. I've just uploaded the bulk of the code that implements all that. I'm testing the rewrite logic for when dbus service publishers include a 'v' so the python code writers do not have to cope with any glib 'variant' logic. Once that passes unit tests, it will be testing the named variable glue and then .. that's it. All the '0 means off' and '1 means cold' an '2 means hot' and 0x40 means flag x and 0x20 means flag y is done. Basically everything to do with variables passed by argument position is done. All the docs are done.

@hcoin
Copy link

hcoin commented Apr 7, 2017

I like that IoT concept you mention. The problem I'm aiming to solve is 'deprecation' and change in dbus specs. So many 'little changes' happen that sooner or later Iot code in the field needs to be 'updated' to 'keep up with where it was'. Now, the translation dictionary writer can ADD variables to dbus calls to include version numbers or defaults for programs that are 'old' that don't provide the necessary. That way, code stays compatible without change and only the folks that want the value of the new thing need to cope with it.

@hcoin
Copy link

hcoin commented Apr 7, 2017

And.. the code I've uploaded is 100% backward compatible will all current pydbus uses.

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

Successfully merging this pull request may close these issues.

3 participants