Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    Dbus Help

    Reply
    Page 1 of 2 | 1   2   | Next
    xur17 | # 1 | 2010-10-08, 18:47 | Report

    I am trying to monitor a dbus signal, and make my n900 output some text when a specific signal is received.

    I am using python. This is the signal that I am monitoring for (any presence change for a user on my jabber account). I got this using the dbus-monitor command:

    Code:
    signal sender=:1.496 -> dest=(null destination) serial=3979 path=/org/freedesktop/Telepathy/Connection/gabble/jabber/username_40gmail_2ecom_2fMaemo; interface=org.freedesktop.Telepathy.Connection.Interface.SimplePresence; member=PresencesChanged
       array [
          dict entry(
             uint32 209
             struct {
                uint32 2
                string "available"
                string "243"
             }
          )
       ]
    Here is my code:

    Code:
    #! /usr/bin/python
    import gobject, dbus
    from dbus.mainloop.glib import DBusGMainLoop
    
    def handle_presence():
        print "status changed"
    
    if __name__ == '__main__':
    	print "starting"
    	DBusGMainLoop(set_as_default=True)
    	bus = dbus.SystemBus()
    	bus.add_signal_receiver(handle_presence, 'PresencesChanged', 'org.freedesktop.Telepathy.Connection.Interface.SimplePresence', None, '/org/freedesktop/Telepathy/Connection/gabble/jabber/username_40gmail_2ecom_2fMaemo')
    	gobject.MainLoop().run()
    As far as I can tell, this should work, but nothing is outputted.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    kureyon | # 2 | 2010-10-08, 19:46 | Report

    Have you used dbus-monitor to confirm that the events you expect are being triggered?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    xur17 | # 3 | 2010-10-08, 19:51 | Report

    Originally Posted by kureyon View Post
    Have you used dbus-monitor to confirm that the events you expect are being triggered?
    Yes, and they definitely are. I manually changed a user's presence that is on my buddy list while running dbus-monitor. I copied that exact line into this post, and made my script using it.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    daperl | # 4 | 2010-10-08, 21:35 | Report

    Change

    bus = dbus.SystemBus()

    to

    bus = dbus.SessionBus()

    and all should be good.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to daperl For This Useful Post:
    nicolai, xur17

     
    xur17 | # 5 | 2010-10-08, 22:01 | Report

    Originally Posted by daperl View Post
    Change

    bus = dbus.SystemBus()

    to

    bus = dbus.SessionBus()

    and all should be good.
    Thank you! I have been playing around with it for hours, and this fixed it for me!

    Edit | Forward | Quote | Quick Reply | Thanks

     
    xur17 | # 6 | 2010-10-08, 22:31 | Report

    Do you know what type is passed to handle_presence?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    nicolai | # 7 | 2010-10-08, 22:40 | Report

    http://telepathy.freedesktop.org/spe...esencesChanged

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to nicolai For This Useful Post:
    daperl

     
    daperl | # 8 | 2010-10-08, 22:54 | Report

    I changed your code to this:

    Code:
    def handle_presence(*args):
        print "status changed",args
    and here's the output:

    Code:
    status changed (dbus.Dictionary({dbus.UInt32(1L): dbus.Struct((dbus.UInt32(2L), dbus.String(u'available'), dbus.String(u'')), signature=None)}, signature=dbus.Signature('u(uss)')),)
    So, it looks like a one-value tuple with a dbus.Dictionary.

    But I noticed that no events occur when the account is disabled, so maybe you also want to listen for this:

    Code:
    bus.add_signal_receiver(handle_presence, 'StatusChanged', 'org.freedesktop.Telepathy.Connection', None, '/org/freedesktop/Telepathy/Connection/gabble/jabber/username_40gmail_2ecom_2fMaemo')
    Here's the output when I swap that with the other receiver call:

    enabled:

    Code:
    status changed (dbus.UInt32(1L), dbus.UInt32(1L))
    status changed (dbus.UInt32(0L), dbus.UInt32(1L))
    disabled:

    Code:
    status changed (dbus.UInt32(2L), dbus.UInt32(1L))

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to daperl For This Useful Post:
    nicolai, xur17

     
    xur17 | # 9 | 2010-10-09, 00:13 | Report

    What variable type is args?

    I receive the following when I do print args:

    Code:
    (dbus.Dictionary({dbus.UInt32(3L): dbus.Struct((dbus.UInt32(4L), dbus.String(u'xa'), dbus.String(u"I'm away from my computer")), signature=None)}, signature=dbus.Signature('u(uss)')),)
    It appears that it is a structure inside of a dictionary. How do I set a variable to the value of the status ("I'm away from my computer")?

    Edit | Forward | Quote | Quick Reply | Thanks

     
    daperl | # 10 | 2010-10-09, 01:17 | Report

    I think all is answered by following nicolai's link and the dbus-python tutorial. According to the Data Types section, dbus.Dictionary is a sub-class of dict.

    Remove the '*' from '*arg' and arg should just be a dbus.Dictionary.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to daperl For This Useful Post:
    xur17

     
    Page 1 of 2 | 1   2   | Next
vBulletin® Version 3.8.8
Normal Logout