Changes
Development Team/Almanac/Sugar.presence (view source)
Revision as of 10:39, 10 October 2008
, 10:39, 10 October 2008→Step 3: Coordinate sharing and joining in your activity using stream tubes and the client/server classes defined above.
#### Method: __init__, initialize this AnnotateActivity instance
#### Method: __init__, initialize this AnnotateActivity instance
def __init__(self, handle):
def __init__(self, handle):
...
#Joining activity needs to know which stream tubes are available for downloading
#Joining activity needs to know which stream tubes are available for downloading
# Wait for a successful join before trying to get the document
# Wait for a successful join before trying to get the document
self.connect("joined", self._joined_cb)
self.connect("joined", self._joined_cb)
...
######################## SETUP SERVER ON SHARING ACTIVITY ####################################
#### Method _shared_cb, which is called when this activity is successfully
# shared on a mesh channel.
def _shared_cb(self, activity):
# We initiated this activity and have now shared it, so by
# definition we have the file.
_logger.debug('SYSTEM:', '_shared_cb(): Activity being shared')
self._want_document = False;
self._share_document()
#### Method: _share_document, which sets up an http server that will serve a specific file to
# any joining activities.
def _share_document(self):
_logger.debug('SYSTEM', '_share_document() -- sharing file ' + str(object_path))
object_path = os.path.join(self.get_activity_root(), 'data', 'sample-shared-file.doc')
_logger.debug('SYSTEM', '_share_document() -- Starting HTTP server on port '+str(self.port))
self._fileserver = AnnotateHTTPServer(("", self.port), object_path)
# Make a tube for the server
chan = self._shared_activity.telepathy_tubes_chan
iface = chan[telepathy.CHANNEL_TYPE_TUBES]
self._fileserver_tube_id = iface.OfferStreamTube(ANNOTATE_STREAM_SERVICE,
{},
telepathy.SOCKET_ADDRESS_TYPE_IPV4,
('127.0.0.1', dbus.UInt16(self.port)),
telepathy.SOCKET_ACCESS_CONTROL_LOCALHOST, 0)