add service unregistration
This commit is contained in:
parent
ebd27c2cbb
commit
3117d454b9
@ -208,6 +208,19 @@ class PresenceServiceDBusHelper(dbus.service.Object):
|
||||
port, domain)
|
||||
return service.object_path()
|
||||
|
||||
@dbus.service.method(_PRESENCE_DBUS_INTERFACE,
|
||||
in_signature="o", out_signature="")
|
||||
def unregisterService(self, service_op):
|
||||
found_serv = None
|
||||
serv = self._parent.get_services()
|
||||
for serv in services:
|
||||
if serv.object_path() == service_op:
|
||||
found_serv = serv
|
||||
break
|
||||
if not found_serv:
|
||||
raise NotFoundError("The activity %s was not found." % service_op)
|
||||
return self._parent.unregister_service(found_serv)
|
||||
|
||||
@dbus.service.method(_PRESENCE_DBUS_INTERFACE,
|
||||
in_signature="s", out_signature="")
|
||||
def registerServiceType(self, stype):
|
||||
@ -628,6 +641,7 @@ class PresenceService(object):
|
||||
group.AddService(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, 0, dbus.String(name),
|
||||
dbus.String(stype), dbus.String(domain), dbus.String(""), # let Avahi figure the 'host' out
|
||||
dbus.UInt16(port), info)
|
||||
service.set_avahi_entry_group(group)
|
||||
group.Commit()
|
||||
except dbus.exceptions.DBusException, exc:
|
||||
# FIXME: ignore local name collisions, since that means
|
||||
@ -638,6 +652,14 @@ class PresenceService(object):
|
||||
self.register_service_type(stype)
|
||||
return service
|
||||
|
||||
def unregister_service(self, service):
|
||||
group = service.get_avahi_entry_group()
|
||||
if not group:
|
||||
raise ValueError("Service was not a local service provided by this laptop!")
|
||||
group.Free()
|
||||
key = (service.get_full_name(), service.get_type())
|
||||
del self._services[key]
|
||||
|
||||
def register_service_type(self, stype):
|
||||
"""Requests that the Presence service look for and recognize
|
||||
a certain mDNS service types."""
|
||||
|
@ -137,6 +137,7 @@ class Service(object):
|
||||
self.set_port(port)
|
||||
self._properties = {}
|
||||
self.set_properties(properties)
|
||||
self._avahi_entry_group = None
|
||||
|
||||
# Source address is the unicast source IP
|
||||
self._source_address = None
|
||||
@ -257,11 +258,15 @@ class Service(object):
|
||||
self._address = address
|
||||
self._properties['address'] = address
|
||||
|
||||
|
||||
def get_domain(self):
|
||||
"""Return the ZeroConf/mDNS domain the service was found in."""
|
||||
return self._domain
|
||||
|
||||
def set_avahi_entry_group(self, group):
|
||||
self._avahi_entry_group = group
|
||||
|
||||
def get_avahi_entry_group(self):
|
||||
return self._avahi_entry_group
|
||||
|
||||
#################################################################
|
||||
# Tests
|
||||
|
@ -194,6 +194,9 @@ class PresenceService(gobject.GObject):
|
||||
serv_op = self._ps.registerService(name, stype, properties, address, port, domain)
|
||||
return self._new_object(serv_op)
|
||||
|
||||
def unregister_service(self, service):
|
||||
self._ps.unregisterService(service.object_path())
|
||||
|
||||
def register_service_type(self, stype):
|
||||
self._ps.registerServiceType(stype)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user