[gnome-games/sudoku-tube] Use a callback to begin offering tube
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/sudoku-tube] Use a callback to begin offering tube
- Date: Sat, 27 Jun 2009 14:46:09 +0000 (UTC)
commit 7bdb6cbd27e2b7b1c83f0260585770a452d09ca2
Author: Zhang Sen <zh jesse gmail com>
Date: Sat Jun 27 22:45:29 2009 +0800
Use a callback to begin offering tube
gnome-sudoku/src/lib/tp_tube.py | 2 ++
gnome-sudoku/src/lib/tube_handler.py | 24 ++++++++++++++++++------
2 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/tp_tube.py b/gnome-sudoku/src/lib/tp_tube.py
index a3b5c3e..53dc344 100644
--- a/gnome-sudoku/src/lib/tp_tube.py
+++ b/gnome-sudoku/src/lib/tp_tube.py
@@ -20,6 +20,8 @@ logger = logging.getLogger("main.tp_tube")
def tube_state_changed_cb(state):
if state == TUBE_CHANNEL_STATE_OPEN:
logger.info("Tube state changed ->open")
+ print "export a logic (something like a server), so the receiver can \
+ connect to it"
elif state == TUBE_CHANNEL_STATE_REMOTE_PENDING:
logger.info("Tube state changed ->remote-pending")
else:
diff --git a/gnome-sudoku/src/lib/tube_handler.py b/gnome-sudoku/src/lib/tube_handler.py
index 528b313..754f133 100644
--- a/gnome-sudoku/src/lib/tube_handler.py
+++ b/gnome-sudoku/src/lib/tube_handler.py
@@ -8,8 +8,12 @@ from dbus.mainloop.glib import DBusGMainLoop
from telepathy.client.conn import Connection
from telepathy.client.channel import Channel
-from telepathy.constants import SOCKET_ACCESS_CONTROL_CREDENTIALS
-from telepathy.interfaces import CHANNEL_TYPE_DBUS_TUBE
+from telepathy.constants import (
+ TUBE_STATE_OPEN,
+ SOCKET_ACCESS_CONTROL_CREDENTIALS)
+from telepathy.interfaces import (
+ CHANNEL_INTERFACE_TUBE,
+ CHANNEL_TYPE_DBUS_TUBE)
DBusGMainLoop(set_as_default=True)
logger = logging.getLogger("main.tubehandler")
@@ -45,12 +49,20 @@ class TubeHandler(dbus.service.Object):
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")
+ logger.info("Tube received on %s" % channel)
conn = Connection(bus_name, connection)
chan = Channel(bus_name, channel)
- address = chan[CHANNEL_TYPE_DBUS_TUBE].Accept(
+ self.address = chan[CHANNEL_TYPE_DBUS_TUBE].Accept(
SOCKET_ACCESS_CONTROL_CREDENTIALS)
- tube_conn = dbus.connection.Connection(address)
+ chan[CHANNEL_INTERFACE_TUBE].connect_to_signal(
+ 'TubeChannelStateChanged', self._tube_state_changed_cb)
- self._tube_received_cb(address, tube_conn)
+ def _tube_state_changed_cb(self, state):
+ if state == TUBE_STATE_OPEN:
+ logger.info("Tube state changed ->open")
+ tube_conn = dbus.connection.Connection(self.address)
+
+ self._tube_received_cb(self.address, tube_conn)
+ else:
+ logger.info("Tube state changed ->%s" % state)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]