Ensure that services this sugar instance registers are register with the owner as well.

This commit is contained in:
Dan Williams 2006-05-22 16:05:17 -04:00
parent 0c2940d56e
commit a7a2211b68
3 changed files with 20 additions and 2 deletions

View File

@ -105,3 +105,13 @@ class Owner(Buddy):
def register(self):
self._presence_service.register(self._group)
def notify_service_registered(self, service):
"""New services registered in our group are automatically owned
by us."""
self._services[service.get_type()] = service
def add_service(self, service):
"""Do nothing here, since all services we need to know about
are registered with us by our group."""
pass

View File

@ -90,6 +90,10 @@ class LocalGroup(Group):
if self._buddies.has_key(name):
return self._buddies[name]
return None
def notify_service_registered(self, service):
"""A new service is automatically owned by the owner of this group."""
self._owner.notify_service_registered(service)
def _add_buddy(self, buddy):
bid = buddy.get_nick_name()
@ -130,15 +134,17 @@ class LocalGroup(Group):
if key == 'group_address':
service.set_group_address(value)
# print "ServiceResolved: name=%s, stype=%s, port=%s, address=%s" % (name, stype, port, address)
print "ServiceResolved: name=%s, stype=%s, port=%s, address=%s" % (name, stype, port, address)
if stype in get_recognized_buddy_service_types():
# Service recognized as Buddy services either create a new
# buddy if one doesn't exist yet, or get added to the existing
# buddy
buddy = self.get_buddy(name)
if buddy:
print "Found buddy %s" % name
buddy.add_service(service)
else:
print "New buddy %s" % name
self._add_buddy(Buddy(service))
self.add_service(service)
elif stype.startswith(_OLPC_SERVICE_TYPE_PREFIX):

View File

@ -35,10 +35,12 @@ class Service(object):
def is_multicast(self):
return self._group_address != None
def register(self, group):
def register(self, group):
pannounce = presence.PresenceAnnounce()
if self._group_address:
pannounce.register_service(self._name, self._port, self._stype,
group_address = self._group_address)
else:
pannounce.register_service(self._name, self._port, self._stype)
# Notify the group that we're registering a new service
group.notify_service_registered(self)