gatt-python icon indicating copy to clipboard operation
gatt-python copied to clipboard

Migrate all the D-Bus calls to GDBus.

Open tommie-lie opened this issue 6 years ago • 14 comments

Disclaimer: This pull-request does not "fix" an "issue" but is rather a proposal and is a 1:1 migration. I plan on expanding on that idea, creating proper DBusProxy subclasses, somehow resect the requirement for a non-user-controlled mainloop and thus improve the integratability of gatt-python for my own projects. If you think this migration is rubbish, just close the pull-request ;-)

--

Given that the python-dbus interface only receives fixes and is considered by its author and maintainer as un-pythonic and is not recommended by him, it seems more logical to use another, more recommendable interface.

As gatt-python already makes use of PyGI and GLib, it makes sense to use GDBus which comes as a part of GLib.

This also effectively removes the python-dbus dependency.

tommie-lie avatar Nov 03 '17 21:11 tommie-lie

I'm the original author of this library and I find your PR very promising. As it is removing the dependency of dbus and using GDBus instead, I consider this PR a good step forward. Unfortunately I don't have suitable hardware to test your PR as I'm not working with team Senic at the moment. Maybe someone from @getsenic can give the PR a try? It should make their build process slightly simpler.

larsblumberg avatar Nov 05 '17 09:11 larsblumberg

@tommie-lie This is really great. Tested your PR using real hardware and I fixed some issues - seems all well now with some minor exceptions but not critical for the applications. I created another PR on your fork(I created a PR for this PR basically :smile: ).

@larsblumberg @tommie-lie What was tested:

  1. Discovery - works
  2. Connecting - works
  3. Notifications - works

mtiutiu avatar Nov 10 '17 14:11 mtiutiu

Sorry for having been silent for so long, but I had some quite busy weeks and did not work on my Bluetooth pet project.

I'm a bit puzzled as to why my code ever worked with the issues found by @mtiutiu but they are fixed now and I found some other placed where the error-handling was wrong. I also rebased the commit to the latest master (and adapted the new DeviceManager.remove_all_devices method).

@mtiutiu I sincerely apologize for not giving credit to you in the git history but I found it rather hard to integrate your PR (see there for more info). Please let me know if you are okay with this or if I should add you to the commit message.

tommie-lie avatar Jan 02 '18 00:01 tommie-lie

@tommie-lie You can merge your changes I don't need any credits for this. I'm glad I could be of help.

mtiutiu avatar Jan 02 '18 18:01 mtiutiu

@TheMeaningfulEngineer Where you guys able to test this PR? It should make your build process easier as it makes the necessity for the dbus lib obsolete.

larsblumberg avatar Jan 15 '18 18:01 larsblumberg

Hey @larsblumberg given the current load, and that it's a feature improvement I'd say somewhere in March.

And thanks @tommie-lie and @mtiutiu, sorry for not being very responsive at the moment.

TheMeaningfulEngineer avatar Jan 16 '18 09:01 TheMeaningfulEngineer

While I wouldn't consider the dbus replacement a feature (from the user perspective) I understand that you got more important things to do in the moment. I'm looking forward to seeing those changes implemented at some point as it eases the overall build process, not only for the Senic Hub.

larsblumberg avatar Jan 16 '18 18:01 larsblumberg

Hey peeps, got a chance to test the PR with our current stack. Unfortunately it broke it and I can't spend the time atm to debug it, will check it out in the soonest available time slot.

Where it fails is on the wrapper library that abstracts the gatt and allows us to think in terms of functionalities of the device. @larsblumberg Do feel free to rephrase, that how I understood the stack :)

  File "/home/root/nuimo-linux-python/nuimo/nuimo.py", line 38, in start_discovery                                                                                                                          
    super().start_discovery(service_uuids=Controller.SERVICE_UUIDS)                                                                                                                                         
  File "/home/root/gatt-python/gatt/gatt_linux.py", line 142, in start_discovery                                                                                                                            
    self._adapter.SetDiscoveryFilter('(a{sv})', discovery_filter)                                                                                                                                           
  File "/usr/lib/python3.5/site-packages/gi/overrides/Gio.py", line 157, in __call__                                                                                                                        
    arg_variant = GLib.Variant(signature, tuple(args))                                                                                                                                                      
  File "/usr/lib/python3.5/site-packages/gi/overrides/GLib.py", line 243, in __new__                                                                                                                        
    (v, rest_format, _) = creator._create(format_string, [value])                                                                                                                                           
  File "/usr/lib/python3.5/site-packages/gi/overrides/GLib.py", line 132, in _create                                                                                                                        
    return self._create_tuple(format, args)                                                                                                                                                                 
  File "/usr/lib/python3.5/site-packages/gi/overrides/GLib.py", line 167, in _create_tuple                                                                                                                  
    (v, format, _) = self._create(format, args[0][i:])                                                                                                                                                      
  File "/usr/lib/python3.5/site-packages/gi/overrides/GLib.py", line 135, in _create                                                                                                                        
    return self._create_dict(format, args)                                                                                                                                                                  
  File "/usr/lib/python3.5/site-packages/gi/overrides/GLib.py", line 194, in _create_dict                                                                                                                   
    (val_v, rest_format, _) = self._create(rest_format, [v])                                                                                                                                                
  File "/usr/lib/python3.5/site-packages/gi/overrides/GLib.py", line 126, in _create                                                                                                                        
    v = constructor(args[0])                                                                                                                                                                                
TypeError: argument value: Expected GLib.Variant, but got list

TheMeaningfulEngineer avatar Feb 19 '18 17:02 TheMeaningfulEngineer

@mtiutiu could you please elaborate on what issues were fixed for you?

Snevzor avatar Mar 21 '19 11:03 Snevzor

@Snevzor I'm sorry but this thing is too old for me now to remember all the details. The initial problem was due to some incompatible methods signature and/or class constructors. But to be honest I don't remember which and the "why". This PR cleaned those up and made my custom application a bit more stable. Initially I had to do some hacks to overcome some related issues - sorry I can't remember those either.

I'm sorry for not being too helpful here but I really don't remember the details and I don't have the time and luxury to search in my old messy code for that application (although it seems to work even now as it is :smile: )

mtiutiu avatar Mar 21 '19 12:03 mtiutiu

@mtiutiu no worries! Thanks for responding anyhow.

Snevzor avatar Mar 21 '19 13:03 Snevzor

I would like to continue the work on this PR.

@mtiutiu Is your PR to this PR already included?

larsblumberg avatar Mar 24 '19 13:03 larsblumberg

@larsblumberg As far as I know it should but @tommie-lie knows better as he worked more on it.

mtiutiu avatar Mar 25 '19 07:03 mtiutiu

Any updates on this? I’d love to see this merged and especially removing the dependency. Gave me headaches. Anything I can help with?

rngtng avatar Mar 09 '20 18:03 rngtng