glib: Have SourceProxy implement the Dispose pattern

Its 2 subclasses, IdleProxy and TimeoutProxy, were already implementing
it, so we factor this implementation into the base class.
This commit is contained in:
Bertrand Lorentz 2014-07-05 15:44:21 +02:00
parent 813f56e00a
commit f5211acb74
3 changed files with 25 additions and 49 deletions

View file

@ -44,30 +44,6 @@ namespace GLib {
proxy_handler = new IdleHandlerInternal (Handler);
}
~IdleProxy ()
{
Dispose (false);
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
// Both branches remove our delegate from the
// managed list of handlers, but only
// Source.Remove will remove it from the
// unmanaged list also.
if (disposing)
Remove ();
else
Source.Remove (ID);
}
public bool Handler ()
{
try {

View file

@ -31,11 +31,35 @@ namespace GLib {
//
// Base class for IdleProxy and TimeoutProxy
//
internal class SourceProxy {
internal class SourceProxy : IDisposable {
internal Delegate real_handler;
internal Delegate proxy_handler;
internal uint ID;
~SourceProxy ()
{
Dispose (false);
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
// Both branches remove our delegate from the
// managed list of handlers, but only
// Source.Remove will remove it from the
// unmanaged list also.
if (disposing)
Remove ();
else
Source.Remove (ID);
}
internal void Remove ()
{
Source.RemoveSourceHandler (ID);

View file

@ -42,30 +42,6 @@ namespace GLib {
proxy_handler = new TimeoutHandlerInternal (Handler);
}
~TimeoutProxy ()
{
Dispose (false);
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
protected virtual void Dispose (bool disposing)
{
// Both branches remove our delegate from the
// managed list of handlers, but only
// Source.Remove will remove it from the
// unmanaged list also.
if (disposing)
Remove ();
else
Source.Remove (ID);
}
public bool Handler ()
{
try {