[gnome-games/sudoku-tube] Call a callback when tube is received
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/sudoku-tube] Call a callback when tube is received
- Date: Thu, 25 Jun 2009 09:51:12 +0000 (UTC)
commit 6429d7a06ceb97c75b7fce25f50d13318dcd15b6
Author: Zhang Sen <zh jesse gmail com>
Date: Thu Jun 25 17:50:10 2009 +0800
Call a callback when tube is received
Also polish the way tubehandler is created
gnome-sudoku/src/lib/main.py | 6 +++++-
gnome-sudoku/src/lib/tube_handler.py | 30 +++++++++++++++++++++---------
2 files changed, 26 insertions(+), 10 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index 2511cd1..08664f5 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -138,7 +138,8 @@ class UI (gconf_wrapper.GConfWrapper):
)
self.setup_gui()
- self.tube_handler = tube_handler.TubeHandler(self.tube_service)
+ self.tube_handler = tube_handler.TubeHandler(self.tube_service,
+ callback=self._tube_received_cb)
self.timer = timer.ActiveTimer(self.w)
self.won = False
@@ -457,6 +458,9 @@ class UI (gconf_wrapper.GConfWrapper):
self.gconf[k] = v
self.player = self.gconf['player']
+ def _tube_received_cb(self, *args):
+ print args
+
def new_cb (self, *args):
if self._close_current_game():
choice = self._select_game()
diff --git a/gnome-sudoku/src/lib/tube_handler.py b/gnome-sudoku/src/lib/tube_handler.py
index 8cbd80c..528b313 100644
--- a/gnome-sudoku/src/lib/tube_handler.py
+++ b/gnome-sudoku/src/lib/tube_handler.py
@@ -14,26 +14,38 @@ from telepathy.interfaces import CHANNEL_TYPE_DBUS_TUBE
DBusGMainLoop(set_as_default=True)
logger = logging.getLogger("main.tubehandler")
+def _sanitize_service_name(service_name):
+ return service_name.replace('.', '_')
+
+def _build_bus_name(service_name):
+ return "org.gnome.Empathy.DTubeHandler.%s" % \
+ _sanitize_service_name(service_name)
+
+def _build_object_path(bus_name):
+ return '/' + bus_name.replace('.', '/')
+
class TubeHandler(dbus.service.Object):
"""Listen to coming tube and emit a signal for it"""
- def __init__(self, service_name):
+ def __init__(self, service_name, callback):
logger.info("creating TubeHandler")
- tmp = service_name.replace('.', '_')
- handler_busname = "org.gnome.Empathy.DTubeHandler." + tmp
- handler_path = "/org/gnome/Empathy/DTubeHandler/" + tmp
- logger.debug("Bus name: %s" % handler_busname)
- logger.debug("Object path: %s" % handler_path)
+ self._tube_received_cb = callback
+
+ bus_name = _build_bus_name(service_name)
+ obj_path = _build_object_path(bus_name)
+ logger.debug("Bus name: %s" % bus_name)
+ logger.debug("Object path: %s" % obj_path)
bus = dbus.SessionBus()
# this bus_name has to be retained, so make it a instance attribute
- self.bus_name = dbus.service.BusName(handler_busname, bus)
- super(TubeHandler, self).__init__(bus, handler_path)
+ self.busname = dbus.service.BusName(bus_name, bus)
+ super(TubeHandler, self).__init__(bus, obj_path)
@dbus.service.method(dbus_interface="org.gnome.Empathy.TubeHandler",
in_signature='soouu', out_signature='')
def HandleTube(self, bus_name, connection, channel, handle_type, handle):
"""Called when we are offered a tube"""
+ logger.info("Received tube")
conn = Connection(bus_name, connection)
chan = Channel(bus_name, channel)
@@ -41,4 +53,4 @@ class TubeHandler(dbus.service.Object):
SOCKET_ACCESS_CONTROL_CREDENTIALS)
tube_conn = dbus.connection.Connection(address)
- print 'emit a signal that connection is ready'
+ self._tube_received_cb(address, tube_conn)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]