Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Williams <dcbw@localhost.localdomain>2006-07-24 15:55:42 (GMT)
committer Dan Williams <dcbw@localhost.localdomain>2006-07-24 15:55:42 (GMT)
commitf53c5326f2fa824265618104be96efdda85e43b6 (patch)
treea984e4cac18b1945829c5ab0f474775f61e4bdfd
parent7f39ed44e9427a0b045a8d5833b968a0807c9d8e (diff)
Add initial non-working bits of ShareActivity
-rw-r--r--shell/PresenceService/PresenceService.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/shell/PresenceService/PresenceService.py b/shell/PresenceService/PresenceService.py
index 04a4b63..e2aba2e 100644
--- a/shell/PresenceService/PresenceService.py
+++ b/shell/PresenceService/PresenceService.py
@@ -4,6 +4,7 @@ import Service
import random
import logging
from sugar import env
+from sugar import util
def _get_local_ip_address(ifname):
@@ -182,6 +183,11 @@ class PresenceServiceDBusHelper(dbus.service.Object):
port, domain)
return service.object_path()
+ def shareActivity(self, activity_id, stype, properties, address, port, domain):
+ service = self._parent.share_activity(name, stype, properties, address,
+ port, domain)
+ return service.object_path()
+
@dbus.service.method(_PRESENCE_DBUS_INTERFACE,
in_signature="s", out_signature="")
def registerServiceType(self, stype):
@@ -540,6 +546,31 @@ class PresenceService(object):
def _new_domain_cb_glue(self, interface, protocol, domain, flags=0):
gobject.idle_add(self._new_domain_cb, interface, protocol, domain, flags)
+ def share_activity(self, activity_id, stype, properties=None, address=None, port=None, domain=u"local"):
+ """Convenience function to share an activity with other buddies."""
+ if not util.validate_activity_id(activity_id):
+ raise ValueError("invalid activity id")
+ owner_nick = self._owner.get_nick_name()
+ real_name = Service.compose_service_name(owner_nick, actid)
+ if address and type(address) != type(u""):
+ raise ValueError("address must be a unicode string.")
+ if address == None:
+ # Use random currently unassigned multicast address
+ address = "232.%d.%d.%d" % (random.randint(0, 254), random.randint(1, 254),
+ random.randint(1, 254))
+ if port and (type(port) != type(1) or port <= 1024 or port >= 65535):
+ raise ValueError("port must be a number between 1024 and 65535")
+ if not port:
+ # random port #
+ port = random.randint(5000, 65535)
+
+ # Mark the activity as shared
+ if stype == activity.get_default_type():
+ activity.set_shared()
+
+ logging.debug('Share activity %s, type %s, address %s, port %d, properties %s' % (activity_id, stype, address, port, properties))
+ return self.register_service(real_name, stype, properties, address, port, domain)
+
def register_service(self, name, stype, properties={}, address=None, port=None, domain=u"local"):
"""Register a new service, advertising it to other Buddies on the network."""
if self.get_owner() and name != self.get_owner().get_nick_name():