~ubuntu-branches/ubuntu/maverick/coherence/maverick

« back to all changes in this revision

Viewing changes to coherence/extern/telepathy/tube.py

  • Committer: Bazaar Package Importer
  • Author(s): Charlie Smotherman
  • Date: 2010-01-02 10:57:15 UTC
  • mfrom: (1.1.7 upstream) (3.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20100102105715-sghzl2nw4lr5b1ob
Tags: 0.6.6.2-1
*  New  upstream release, summary of changes:
    - adding all necessary files to MANIFEST.in, to compensate for the
      gone 'auto-include-all-files-under-version-control' setuptools
      feature.
    - rearranging genre and genres attribute in DIDLLite - thx Caleb  
    - fix face_path typo, fixes #275.   

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Licensed under the MIT license
 
2
# http://opensource.org/licenses/mit-license.php
 
3
 
 
4
# Copyright 2009 Philippe Normand <phil@base-art.net>
 
5
 
 
6
from telepathy.interfaces import CHANNEL_INTERFACE, CONNECTION_INTERFACE_REQUESTS, \
 
7
     CHANNEL_TYPE_DBUS_TUBE
 
8
from telepathy.constants import CONNECTION_HANDLE_TYPE_ROOM, \
 
9
     SOCKET_ACCESS_CONTROL_CREDENTIALS
 
10
 
 
11
from coherence.extern.telepathy.client import Client
 
12
 
 
13
class TubePublisherMixin(object):
 
14
 
 
15
    def __init__(self, tubes_to_offer):
 
16
        self._tubes_to_offer = tubes_to_offer
 
17
 
 
18
    def muc_joined(self):
 
19
        self.info("muc joined. Offering the tubes")
 
20
        conn_iface = self.conn[CONNECTION_INTERFACE_REQUESTS]
 
21
        params = {CHANNEL_INTERFACE + ".ChannelType": CHANNEL_TYPE_DBUS_TUBE,
 
22
                  CHANNEL_INTERFACE + ".TargetHandleType": CONNECTION_HANDLE_TYPE_ROOM,
 
23
                  CHANNEL_INTERFACE + ".TargetID": self.muc_id}
 
24
        for interface in self._tubes_to_offer.keys():
 
25
            params[CHANNEL_TYPE_DBUS_TUBE + ".ServiceName"] = interface
 
26
            conn_iface.CreateChannel(params)
 
27
 
 
28
    def got_tube(self, tube):
 
29
        super(TubePublisherMixin, self).got_tube(tube)
 
30
        initiator_handle = tube.props[CHANNEL_INTERFACE + ".InitiatorHandle"]
 
31
        if initiator_handle == self.self_handle:
 
32
            self.finish_tube_offer(tube)
 
33
 
 
34
    def finish_tube_offer(self, tube):
 
35
        self.info("offering my tube located at %r", tube.object_path)
 
36
        service_name = tube.props[CHANNEL_TYPE_DBUS_TUBE + ".ServiceName"]
 
37
        params = self._tubes_to_offer[service_name]
 
38
        params["initiator"] = self.account["account"]
 
39
        address = tube[CHANNEL_TYPE_DBUS_TUBE].Offer(params,
 
40
                                                     SOCKET_ACCESS_CONTROL_CREDENTIALS)
 
41
        tube.local_address = address
 
42
        self.info("local tube address: %r", address)
 
43
 
 
44
class TubePublisher(TubePublisherMixin, Client):
 
45
    logCategory = "tube_publisher"
 
46
 
 
47
    def __init__(self, manager, protocol, account, muc_id, tubes_to_offer):
 
48
        TubePublisherMixin.__init__(self, tubes_to_offer)
 
49
        Client.__init__(self, manager, protocol, account, muc_id)
 
50
 
 
51
 
 
52
class TubeConsumerMixin(object):
 
53
    logCategory = "tube_consumer"
 
54
 
 
55
    def __init__(self, found_peer_callback=None, disapeared_peer_callback=None):
 
56
        self.found_peer_callback = found_peer_callback
 
57
        self.disapeared_peer_callback = disapeared_peer_callback
 
58
 
 
59
    def got_tube(self, tube):
 
60
        super(TubeConsumerMixin, self).got_tube(tube)
 
61
        self.accept_tube(tube)
 
62
 
 
63
    def accept_tube(self, tube):
 
64
        if self.pre_accept_tube(tube):
 
65
            self.info("accepting tube %r", tube.object_path)
 
66
            tube_iface = tube[CHANNEL_TYPE_DBUS_TUBE]
 
67
            tube.local_address = tube_iface.Accept(SOCKET_ACCESS_CONTROL_CREDENTIALS)
 
68
        else:
 
69
            self.warning("tube %r not allowed", tube)
 
70
 
 
71
    def pre_accept_tube(self, tube):
 
72
        return True
 
73
 
 
74
    def tube_closed(self, tube):
 
75
        self.disapeared_peer_callback(tube)
 
76
        super(TubeConsumerMixin, self).tube_closed(tube)
 
77
 
 
78
class TubeConsumer(TubeConsumerMixin, Client):
 
79
    logCategory = "tube_consumer"
 
80
 
 
81
    def __init__(self, manager, protocol,
 
82
                 account, muc_id, found_peer_callback=None,
 
83
                 disapeared_peer_callback=None):
 
84
        TubeConsumerMixin.__init__(self, found_peer_callback=found_peer_callback,
 
85
                                   disapeared_peer_callback=disapeared_peer_callback)
 
86
        Client.__init__(self, manager, protocol, account, muc_id)