Fix up registered service type checking code
This commit is contained in:
parent
922b7238b9
commit
14763c0f5c
@ -389,6 +389,12 @@ class PresenceService(object):
|
|||||||
adv_list.append(adv)
|
adv_list.append(adv)
|
||||||
return adv_list
|
return adv_list
|
||||||
|
|
||||||
|
def _find_registered_service_type(self, stype):
|
||||||
|
for item in self._registered_service_types:
|
||||||
|
if item.get_type() == stype:
|
||||||
|
return item
|
||||||
|
return None
|
||||||
|
|
||||||
def _handle_new_service_for_buddy(self, service, local):
|
def _handle_new_service_for_buddy(self, service, local):
|
||||||
"""Deal with a new discovered service object."""
|
"""Deal with a new discovered service object."""
|
||||||
# Once a service is resolved, we match it up to an existing buddy,
|
# Once a service is resolved, we match it up to an existing buddy,
|
||||||
@ -522,7 +528,8 @@ class PresenceService(object):
|
|||||||
|
|
||||||
# If we care about the service right now, resolve it
|
# If we care about the service right now, resolve it
|
||||||
resolve = False
|
resolve = False
|
||||||
if actid is not None or stype in self._registered_service_types:
|
item = self._find_registered_service_type(stype)
|
||||||
|
if actid is not None or item is not None:
|
||||||
resolve = True
|
resolve = True
|
||||||
if resolve and adv.state() == _SA_UNRESOLVED:
|
if resolve and adv.state() == _SA_UNRESOLVED:
|
||||||
logging.debug("Found '%s' (%d) of type '%s' in domain" \
|
logging.debug("Found '%s' (%d) of type '%s' in domain" \
|
||||||
@ -699,7 +706,7 @@ class PresenceService(object):
|
|||||||
self._services[(name, stype)] = service
|
self._services[(name, stype)] = service
|
||||||
port = service.get_port()
|
port = service.get_port()
|
||||||
|
|
||||||
logging.debug("PS: Will register service with name='%s', stype='%s'," \
|
logging.debug("Will register service with name='%s', stype='%s'," \
|
||||||
" domain='%s', address='%s', port=%d, info='%s'" % (name, stype,
|
" domain='%s', address='%s', port=%d, info='%s'" % (name, stype,
|
||||||
domain, address, port, info))
|
domain, address, port, info))
|
||||||
group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, 0, dbus.String(name),
|
group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, 0, dbus.String(name),
|
||||||
@ -719,7 +726,7 @@ class PresenceService(object):
|
|||||||
def unregister_service(self, service, sender=None):
|
def unregister_service(self, service, sender=None):
|
||||||
local_publisher = service.get_local_publisher()
|
local_publisher = service.get_local_publisher()
|
||||||
if sender is not None and local_publisher != sender:
|
if sender is not None and local_publisher != sender:
|
||||||
raise ValueError("Service was not not registered by requesting process!")
|
raise ValueError("Service was not registered by requesting process!")
|
||||||
group = service.get_avahi_entry_group()
|
group = service.get_avahi_entry_group()
|
||||||
if not group:
|
if not group:
|
||||||
raise ValueError("Service was not a local service provided by this laptop!")
|
raise ValueError("Service was not a local service provided by this laptop!")
|
||||||
@ -732,8 +739,8 @@ class PresenceService(object):
|
|||||||
raise ValueError("service type must be a unicode string.")
|
raise ValueError("service type must be a unicode string.")
|
||||||
|
|
||||||
# If we've already registered it as a service type, ref it and return
|
# If we've already registered it as a service type, ref it and return
|
||||||
for item in self._registered_service_types:
|
item = self._find_registered_service_type(stype)
|
||||||
if item.get_type() == stype:
|
if item is not None:
|
||||||
item.ref()
|
item.ref()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -757,12 +764,11 @@ class PresenceService(object):
|
|||||||
"""Stop tracking a certain mDNS service."""
|
"""Stop tracking a certain mDNS service."""
|
||||||
if type(stype) != type(u""):
|
if type(stype) != type(u""):
|
||||||
raise ValueError("service type must be a unicode string.")
|
raise ValueError("service type must be a unicode string.")
|
||||||
item = None
|
|
||||||
for item in self._registered_service_types:
|
|
||||||
if item.get_type() == stype:
|
|
||||||
break
|
|
||||||
# if it was found, unref it and possibly remove it
|
# if it was found, unref it and possibly remove it
|
||||||
if item is not None:
|
item = self._find_registered_service_type(stype)
|
||||||
|
if not item:
|
||||||
|
return
|
||||||
if item.unref() <= 0:
|
if item.unref() <= 0:
|
||||||
self._registered_service_types.remove(item)
|
self._registered_service_types.remove(item)
|
||||||
del item
|
del item
|
||||||
|
Loading…
Reference in New Issue
Block a user