aboutsummaryrefslogtreecommitdiffstats
path: root/examples/dbus/test_signal_recipient.py
blob: 9a97e11361f6ff14eb66ff8fe4980f2c7464104b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python

import dbus
from efl import dbus_mainloop
from efl import ecore


def emit_signal(obj):
    obj.emitHelloSignal(dbus_interface="com.example.TestService")
    obj.Exit(dbus_interface="com.example.TestService")

    ecore.idler_add(ecore.main_loop_quit)
    return False


def hello_signal_handler(hello_string):
    print "Received signal (by connecting using remote " \
          "object) and it says: %s" % hello_string


def catchall_hello_signals_handler(hello_string):
    print "Received a hello signal and it says: %s" % hello_string


def catchall_testservice_interface_handler(hello_string, dbus_message):
    print "com.example.TestService interface says %s " \
          "when it sent signal %s" % (hello_string, dbus_message.get_member())


dbus_ml = dbus_mainloop.DBusEcoreMainLoop()
bus = dbus.SessionBus(mainloop=dbus_ml)

obj = bus.get_object("com.example.TestService",
                     "/com/example/TestService/object")
obj.connect_to_signal("HelloSignal",
                      hello_signal_handler,
                      dbus_interface="com.example.TestService",
                      arg0="Hello")

bus.add_signal_receiver(catchall_hello_signals_handler,
                        dbus_interface = "com.example.TestService",
                        signal_name = "HelloSignal")
bus.add_signal_receiver(catchall_testservice_interface_handler,
                        dbus_interface = "com.example.TestService",
                        message_keyword="dbus_message")

ecore.timer_add(1.0, emit_signal, obj)
ecore.main_loop_begin()