baseclass: Simplify cleaning up gobject signals

Just add a custom connect/disconnect to keep track of the signals for us.
This commit is contained in:
Cole Robinson 2011-04-11 13:06:59 -04:00
parent 85340ca491
commit d74066da21
4 changed files with 27 additions and 17 deletions

View File

@ -52,24 +52,27 @@ class vmmGObject(gobject.GObject):
for h in self._gconf_handles[:]:
self.remove_gconf_handle(h)
for h in self._gobject_handles[:]:
self.remove_gobject_handle(h)
self.disconnect(h)
for h in self._gobject_timeouts[:]:
self.remove_gobject_timeout(h)
except:
logging.exception("Error cleaning up %s" % self)
def connect(self, name, callback, *args):
ret = gobject.GObject.connect(self, name, callback, *args)
self._gobject_handles.append(ret)
return ret
def disconnect(self, handle):
ret = gobject.GObject.disconnect(self, handle)
self._gobject_handles.remove(handle)
return ret
def add_gconf_handle(self, handle):
self._gconf_handles.append(handle)
def remove_gconf_handle(self, handle):
self.config.remove_notifier(handle)
self._gconf_handles.remove(handle)
def add_gobject_handle(self, handle):
self._gobject_handles.append(handle)
def remove_gobject_handle(self, handle):
self.disconnect(handle)
self._gobject_handles.remove(handle)
def add_gobject_timeout(self, handle):
self._gobject_timeouts.append(handle)
def remove_gobject_timeout(self, handle):
@ -101,6 +104,7 @@ class vmmGObjectUI(vmmGObject):
self.window = None
self.topwin = None
self.gladefile = None
self.err = None
if filename:
self.gladefile = os.path.join(self.config.get_glade_dir(),
@ -111,4 +115,11 @@ class vmmGObjectUI(vmmGObject):
self.topwin = self.window.get_widget(self.windowname)
self.topwin.hide()
self.err = vmmErrorDialog(self.topwin)
self.err = vmmErrorDialog(self.topwin)
def cleanup(self):
vmmGObject.cleanup(self)
self.window = None
self.topwin = None
self.gladefile = None
self.err = None

View File

@ -306,7 +306,7 @@ class vmmConnection(vmmGObject):
self.hostinfo[6] * self.hostinfo[7])
def connect(self, name, callback, *args):
handle_id = gobject.GObject.connect(self, name, callback, *args)
handle_id = vmmGObject.connect(self, name, callback, *args)
if name == "vm-added":
for uuid in self.vms.keys():
@ -1642,4 +1642,4 @@ class vmmConnection(vmmGObject):
return self.config.get_perhost(self.get_uri(),
self.config.get_iso_paths)
gobject.type_register(vmmConnection)
vmmGObject.type_register(vmmConnection)

View File

@ -996,10 +996,8 @@ class vmmDomain(vmmDomainBase):
self.config.on_stats_enable_disk_poll_changed(
self.toggle_sample_disk_io))
self.add_gobject_handle(
self.connect("status-changed", self._update_start_vcpus))
self.add_gobject_handle(
self.connect("config-changed", self._reparse_xml))
self.connect("status-changed", self._update_start_vcpus)
self.connect("config-changed", self._reparse_xml)
##########################
# Internal virDomain API #

View File

@ -517,12 +517,13 @@ class vmmEngine(vmmGObject):
del self.connections[uri]
self.config.remove_connection(conn.get_uri())
def connect(self, name, callback):
handle_id = gobject.GObject.connect(self, name, callback)
def connect(self, name, callback, *args):
handle_id = vmmGObject.connect(self, name, callback, *args)
if name == "connection-added":
for uri in self.connections.keys():
self.emit("connection-added", self.connections[uri]["connection"])
self.emit("connection-added",
self.connections[uri]["connection"])
return handle_id