aboutsummaryrefslogtreecommitdiffstats
path: root/examples/dbus
diff options
context:
space:
mode:
authordavemds <dave@gurumeditation.it>2013-04-06 23:38:55 +0200
committerdavemds <dave@gurumeditation.it>2013-04-06 23:38:55 +0200
commita52dac21456056ab24f3cdecba373472ece82523 (patch)
tree4761583dcfd19a0c0c3f83800f4e6a7f61f4e3c5 /examples/dbus
parentPython-EFL: use eina_log in dbus_mainloop (diff)
downloadpython-efl-a52dac21456056ab24f3cdecba373472ece82523.tar.gz
Python-EFL: move dbus examples to the examples/ folder. Other tests chmod +x
Diffstat (limited to 'examples/dbus')
-rwxr-xr-xexamples/dbus/test_bt_list_handles.py28
-rwxr-xr-xexamples/dbus/test_bt_search_devices.py53
-rwxr-xr-xexamples/dbus/test_signal_emitter.py37
-rwxr-xr-xexamples/dbus/test_signal_recipient.py48
-rwxr-xr-xexamples/dbus/test_signal_simple.py16
5 files changed, 182 insertions, 0 deletions
diff --git a/examples/dbus/test_bt_list_handles.py b/examples/dbus/test_bt_list_handles.py
new file mode 100755
index 0000000..8c11d81
--- /dev/null
+++ b/examples/dbus/test_bt_list_handles.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import sys
+import dbus
+from efl import dbus_mainloop
+from efl import ecore
+
+
+def print_remote_handles(adapter, bdaddr):
+ handles = [hex(int(h)) \
+ for h in list(adapter.GetRemoteServiceHandles(bdaddr, ""))]
+ print "Handles:", handles
+ ecore.idler_add(ecore.main_loop_quit)
+ return False
+
+
+if len(sys.argv) != 2:
+ print "USAGE: %s <bdaddr>" % sys.argv[0]
+ sys.exit(1)
+
+dbus_ml = dbus_mainloop.DBusEcoreMainLoop()
+bus = dbus.SystemBus(mainloop=dbus_ml);
+
+obj = bus.get_object("org.bluez", "/org/bluez/hci0")
+adapter = dbus.Interface(obj, "org.bluez.Adapter")
+
+ecore.idler_add(print_remote_handles, adapter, sys.argv[1])
+ecore.main_loop_begin()
diff --git a/examples/dbus/test_bt_search_devices.py b/examples/dbus/test_bt_search_devices.py
new file mode 100755
index 0000000..9736f52
--- /dev/null
+++ b/examples/dbus/test_bt_search_devices.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+import dbus
+from efl import dbus_mainloop
+from efl import ecore
+
+
+def disc_started_signal():
+ print "Signal: DiscoveryStarted()"
+
+
+def rem_dev_found_signal(address, cls, rssi):
+ print "Signal: RemoteDeviceFound(%s, %s, %s)" % (address, cls, rssi)
+
+
+def rem_dev_name_signal(address, name):
+ print "Signal: RemoteNameUpdated(%s, %s)" % (address, name)
+
+
+def disc_completed_signal():
+ print "Signal: DiscoveryCompleted()"
+ ecore.idler_add(ecore.main_loop_quit)
+
+
+dbus_ml = dbus_mainloop.DBusEcoreMainLoop()
+bus = dbus.SystemBus(mainloop=dbus_ml)
+
+bus.add_signal_receiver(disc_started_signal,
+ "DiscoveryStarted",
+ "org.bluez.Adapter",
+ "org.bluez",
+ "/org/bluez/hci0")
+bus.add_signal_receiver(rem_dev_found_signal,
+ "RemoteDeviceFound",
+ "org.bluez.Adapter",
+ "org.bluez",
+ "/org/bluez/hci0")
+bus.add_signal_receiver(rem_dev_name_signal,
+ "RemoteNameUpdated",
+ "org.bluez.Adapter",
+ "org.bluez",
+ "/org/bluez/hci0")
+bus.add_signal_receiver(disc_completed_signal,
+ "DiscoveryCompleted",
+ "org.bluez.Adapter",
+ "org.bluez",
+ "/org/bluez/hci0")
+
+obj = bus.get_object("org.bluez", "/org/bluez/hci0")
+adapter = dbus.Interface(obj, "org.bluez.Adapter")
+
+adapter.DiscoverDevices()
+ecore.main_loop_begin()
diff --git a/examples/dbus/test_signal_emitter.py b/examples/dbus/test_signal_emitter.py
new file mode 100755
index 0000000..37b1732
--- /dev/null
+++ b/examples/dbus/test_signal_emitter.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+
+import dbus
+import dbus.service
+from efl import dbus_mainloop
+from efl import ecore
+
+
+class TestObject(dbus.service.Object):
+ def __init__(self, conn, object_path="/com/example/TestService/object"):
+ dbus.service.Object.__init__(self, conn, object_path)
+
+ @dbus.service.signal("com.example.TestService")
+ def HelloSignal(self, message):
+ # The signal is emitted when this method exits
+ # You can have code here if you wish
+ pass
+
+ @dbus.service.method("com.example.TestService")
+ def emitHelloSignal(self):
+ #you emit signals by calling the signal"s skeleton method
+ self.HelloSignal("Hello")
+ return "Signal emitted"
+
+ @dbus.service.method("com.example.TestService",
+ in_signature="", out_signature="")
+ def Exit(self):
+ ecore.idler_add(ecore.main_loop_quit)
+
+
+dbus_ml = dbus_mainloop.DBusEcoreMainLoop()
+session_bus = dbus.SessionBus(mainloop=dbus_ml)
+
+name = dbus.service.BusName("com.example.TestService", session_bus)
+obj = TestObject(session_bus)
+
+ecore.main_loop_begin()
diff --git a/examples/dbus/test_signal_recipient.py b/examples/dbus/test_signal_recipient.py
new file mode 100755
index 0000000..9a97e11
--- /dev/null
+++ b/examples/dbus/test_signal_recipient.py
@@ -0,0 +1,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()
diff --git a/examples/dbus/test_signal_simple.py b/examples/dbus/test_signal_simple.py
new file mode 100755
index 0000000..b113fbb
--- /dev/null
+++ b/examples/dbus/test_signal_simple.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+import dbus
+from efl import dbus_mainloop
+from efl import ecore
+
+
+def print_name_owner_changed(obj, old, new):
+ print "Obj = '%s', Old = '%s', New = '%s'" % (obj, old, new)
+
+
+dbus_ml = dbus_mainloop.DBusEcoreMainLoop()
+bus = dbus.SystemBus(mainloop=dbus_ml)
+
+bus.add_signal_receiver(print_name_owner_changed, "NameOwnerChanged")
+ecore.main_loop_begin()