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): def register(self):
self._presence_service.register(self._group) 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

@ -91,6 +91,10 @@ class LocalGroup(Group):
return self._buddies[name] return self._buddies[name]
return None 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): def _add_buddy(self, buddy):
bid = buddy.get_nick_name() bid = buddy.get_nick_name()
if not self._buddies.has_key(bid): if not self._buddies.has_key(bid):
@ -130,15 +134,17 @@ class LocalGroup(Group):
if key == 'group_address': if key == 'group_address':
service.set_group_address(value) 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(): if stype in get_recognized_buddy_service_types():
# Service recognized as Buddy services either create a new # Service recognized as Buddy services either create a new
# buddy if one doesn't exist yet, or get added to the existing # buddy if one doesn't exist yet, or get added to the existing
# buddy # buddy
buddy = self.get_buddy(name) buddy = self.get_buddy(name)
if buddy: if buddy:
print "Found buddy %s" % name
buddy.add_service(service) buddy.add_service(service)
else: else:
print "New buddy %s" % name
self._add_buddy(Buddy(service)) self._add_buddy(Buddy(service))
self.add_service(service) self.add_service(service)
elif stype.startswith(_OLPC_SERVICE_TYPE_PREFIX): elif stype.startswith(_OLPC_SERVICE_TYPE_PREFIX):

View File

@ -42,3 +42,5 @@ class Service(object):
group_address = self._group_address) group_address = self._group_address)
else: else:
pannounce.register_service(self._name, self._port, self._stype) pannounce.register_service(self._name, self._port, self._stype)
# Notify the group that we're registering a new service
group.notify_service_registered(self)