diff options
Diffstat (limited to 'shell/PresenceService/PresenceService.py')
-rw-r--r-- | shell/PresenceService/PresenceService.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/shell/PresenceService/PresenceService.py b/shell/PresenceService/PresenceService.py index a3af824..81aa357 100644 --- a/shell/PresenceService/PresenceService.py +++ b/shell/PresenceService/PresenceService.py @@ -1,6 +1,7 @@ import avahi, dbus, dbus.glib, gobject import Buddy import Service +import Activity import random import logging from sugar import env @@ -178,13 +179,15 @@ class PresenceServiceDBusHelper(dbus.service.Object): @dbus.service.method(_PRESENCE_DBUS_INTERFACE, in_signature="ssa{ss}sis", out_signature="o") - def registerService(self, name, stype, properties, address, port, domain): - service = self._parent.register_service(name, stype, properties, address, + def shareActivity(self, activity_id, stype, properties, address, port, domain): + service = self._parent.share_activity(activity_id, stype, properties, address, 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, + @dbus.service.method(_PRESENCE_DBUS_INTERFACE, + in_signature="ssa{ss}sis", out_signature="o") + def registerService(self, name, stype, properties, address, port, domain): + service = self._parent.register_service(name, stype, properties, address, port, domain) return service.object_path() @@ -440,7 +443,7 @@ class PresenceService(object): self._local_addrs[interface] = addr # Decompose service name if we can - (actid, buddy_name) = Service._decompose_service_name(full_name) + (actid, buddy_name) = Service.decompose_service_name(full_name) # If we care about the service right now, resolve it resolve = False @@ -475,7 +478,7 @@ class PresenceService(object): return False # Decompose service name if we can - (actid, buddy_name) = Service._decompose_service_name(full_name) + (actid, buddy_name) = Service.decompose_service_name(full_name) # Remove the service from the buddy try: @@ -546,34 +549,28 @@ 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"): + def share_activity(self, activity_id, stype, properties=None, address=None, port=-1, 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) + owner_nick = self._owner.get_name() + real_name = Service.compose_service_name(owner_nick, activity_id) 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): + if port and port != -1 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"): + def register_service(self, name, stype, properties={}, address=None, port=-1, 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(): + (actid, person_name) = Service.decompose_service_name(name) + if self.get_owner() and person_name != self.get_owner().get_name(): raise RuntimeError("Tried to register a service that didn't have Owner nick as the service name!") if not domain or not len(domain): domain = u"local" |