[gnome-games/sudoku-tube] Can offer/accept tube
- From: Zhang Sen <zhangsen src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games/sudoku-tube] Can offer/accept tube
- Date: Tue, 23 Jun 2009 08:51:46 -0400 (EDT)
commit eeffa21a48895e49ef8f03602aaeb54ae4c6b582
Author: Zhang Sen <zh jesse gmail com>
Date: Tue Jun 23 20:51:24 2009 +0800
Can offer/accept tube
gnome-sudoku/src/lib/main.py | 13 ++++---
gnome-sudoku/src/lib/tp_tube.py | 68 ++++++++++++++++++++++++++++-----------
2 files changed, 57 insertions(+), 24 deletions(-)
---
diff --git a/gnome-sudoku/src/lib/main.py b/gnome-sudoku/src/lib/main.py
index 2f02a1c..48e9e6a 100644
--- a/gnome-sudoku/src/lib/main.py
+++ b/gnome-sudoku/src/lib/main.py
@@ -123,6 +123,7 @@ class UI (gconf_wrapper.GConfWrapper):
'height': 675,
'auto_save_interval':60 # auto-save interval in seconds...
}
+ tube_service = 'org.gnome.Sudoku'
def __init__ (self, run_selector = True):
"""run_selector means that we start our regular game.
@@ -136,8 +137,7 @@ class UI (gconf_wrapper.GConfWrapper):
)
self.setup_gui()
- tube_service = 'org.gnome.Sudoku'
- bus_name, tube_handler = tp_tube.create_tube_handler(tube_service)
+ bus_name, tube_handler = tp_tube.create_tube_handler(self.tube_service)
self.bus_name, self.tube_handler = bus_name, tube_handler
self.timer = timer.ActiveTimer(self.w)
@@ -466,10 +466,11 @@ class UI (gconf_wrapper.GConfWrapper):
def _new_with_contact_cb(self, action):
choice = contact_selector.contact_selector_run(self.w)
if choice:
- print "selected: %s\nconnection: %s\nhandle: %d" % (
- choice[2].alias, choice[0].service_name, choice[1])
+ logger.info("selected: %s\nconnection: %s\nhandle: %d" % (
+ choice[2].alias, choice[0].service_name, choice[1]))
+ tp_tube.offer_tube(choice[0], choice[1], self.tube_service)
else:
- print "None selected"
+ logger.info("None selected")
def _close_current_game (self):
"""Close current running game
@@ -864,6 +865,8 @@ def start_game(debug=False):
if debug:
print 'Starting GNOME Sudoku in debug mode'
logger.setLevel(logging.DEBUG)
+ else:
+ logger.setLevel(logging.INFO)
## You must call g_thread_init() before executing any other GLib
## functions in a threaded GLib program.
diff --git a/gnome-sudoku/src/lib/tp_tube.py b/gnome-sudoku/src/lib/tp_tube.py
index b369c3b..bfd1d1e 100644
--- a/gnome-sudoku/src/lib/tp_tube.py
+++ b/gnome-sudoku/src/lib/tp_tube.py
@@ -7,31 +7,40 @@ import dbus.service
from telepathy.client.conn import Connection
from telepathy.client.channel import Channel
-from telepathy.interfaces import CHANNEL_TYPE_DBUS_TUBE
+from telepathy.interfaces import (
+ CHANNEL_INTERFACE,
+ CHANNEL_INTERFACE_TUBE,
+ CHANNEL_TYPE_DBUS_TUBE,
+ CONNECTION_INTERFACE_REQUESTS)
+from telepathy.constants import (
+ HANDLE_TYPE_CONTACT,
+ SOCKET_ACCESS_CONTROL_CREDENTIALS,
+ TUBE_CHANNEL_STATE_OPEN,
+ TUBE_CHANNEL_STATE_REMOTE_PENDING)
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
logger = logging.getLogger("main.tp_tube")
-def create_tube_handler (service_name):
+def create_tube_handler(service_name):
"""Create a DBus service on SessionBus and create tube handler on it
Return the created BusName and the TubeHandler"""
+ 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)
+
bus = dbus.SessionBus()
- # the 'service', or 'bus name', or 'connection'
- handler_name = "org.gnome.Empathy.DTubeHandler.%s" % service_name
- # the object path on the above connection/service
- handler_path = "/org/gnome/Empathy/DTubeHandler/%s" % \
- service_name.replace('.','/')
-
- bus_name = dbus.service.BusName(handler_name, bus)
- logger.debug("creating TubeHandler")
+ bus_name = dbus.service.BusName(handler_busname, bus)
tube_handler = TubeHandler(bus, handler_path)
return bus_name, tube_handler
-class TubeHandler (dbus.service.Object):
+class TubeHandler(dbus.service.Object):
"""Listen to coming tube and emit a signal for it"""
@dbus.service.method(dbus_interface="org.gnome.Empathy.TubeHandler",
@@ -41,18 +50,39 @@ class TubeHandler (dbus.service.Object):
conn = Connection(bus_name, connection)
chan = Channel(bus_name, channel)
- address = chan[CHANNEL_TYPE_DBUS_TUBE].Accept()
+ address = chan[CHANNEL_TYPE_DBUS_TUBE].Accept(
+ SOCKET_ACCESS_CONTROL_CREDENTIALS)
tube_conn = dbus.connection.Connection(address)
print 'emit a signal that connection is ready'
-def _test ():
- """do some test-running"""
- import gtk
- name, handler = create_tube_handler('org.gnome.sudoku.test')
- gtk.main()
+def tube_state_changed_cb(state):
+ if state == TUBE_CHANNEL_STATE_OPEN:
+ logger.info("Tube state changed ->open")
+ elif state == TUBE_CHANNEL_STATE_REMOTE_PENDING:
+ logger.info("Tube state changed ->remote-pending")
+ else:
+ logger.info("Tube state changed ->%s" % state)
+
+
+def tube_closed_cb():
+ logger.info("tube closed")
+
+
+def offer_tube(conn, handle, tube_service):
+ # TODO: check if contact supports our tube
+ logger.debug("create tube channel")
+ path, props = conn[CONNECTION_INTERFACE_REQUESTS].CreateChannel({
+ CHANNEL_INTERFACE + ".ChannelType": CHANNEL_TYPE_DBUS_TUBE,
+ CHANNEL_INTERFACE + ".TargetHandleType": HANDLE_TYPE_CONTACT,
+ CHANNEL_INTERFACE + ".TargetHandle": handle,
+ CHANNEL_TYPE_DBUS_TUBE + ".ServiceName": tube_service})
+ chan = Channel(conn.service_name, path)
+ chan[CHANNEL_INTERFACE_TUBE].connect_to_signal('TubeChannelStateChanged',
+ tube_state_changed_cb)
+ chan[CHANNEL_INTERFACE].connect_to_signal('Closed', tube_closed_cb)
-if __name__ == '__main__':
- _test()
+ logger.debug("offering tube")
+ chan[CHANNEL_TYPE_DBUS_TUBE].Offer({}, SOCKET_ACCESS_CONTROL_CREDENTIALS)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]