diff options
author | James Willcox <snopr@snorp.net> | 2005-09-26 06:57:41 +0000 |
---|---|---|
committer | James Willcox <snopr@snorp.net> | 2005-09-26 06:57:41 +0000 |
commit | 6d952319b1a15b439150e7f5911b12e7fc204b69 (patch) | |
tree | 9b09aa181c45e416ca54f93a92ca87afb6d64a12 | |
parent | a4c2edcece605452c4d72da36b8c39da5e514314 (diff) |
add base class for resolvers, and add some missing events there
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@636 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r-- | avahi-sharp/AddressResolver.cs | 12 | ||||
-rw-r--r-- | avahi-sharp/HostNameResolver.cs | 12 | ||||
-rw-r--r-- | avahi-sharp/Makefile.am | 1 | ||||
-rw-r--r-- | avahi-sharp/ResolverBase.cs | 47 | ||||
-rw-r--r-- | avahi-sharp/ServiceResolver.cs | 14 |
5 files changed, 76 insertions, 10 deletions
diff --git a/avahi-sharp/AddressResolver.cs b/avahi-sharp/AddressResolver.cs index 038b0c9..01211ae 100644 --- a/avahi-sharp/AddressResolver.cs +++ b/avahi-sharp/AddressResolver.cs @@ -34,7 +34,7 @@ namespace Avahi public delegate void HostAddressHandler (object o, string host, IPAddress address); - public class AddressResolver : IDisposable + public class AddressResolver : ResolverBase, IDisposable { private IntPtr handle; private Client client; @@ -150,18 +150,24 @@ namespace Avahi ResolverEvent revent, Protocol aproto, IntPtr address, IntPtr hostname, LookupResultFlags flags, IntPtr userdata) { - if (revent == ResolverEvent.Found) { + switch (revent) { + case ResolverEvent.Found: currentAddress = Utility.PtrToAddress (address); currentHost = Utility.PtrToString (hostname); foreach (HostAddressHandler handler in foundListeners) handler (this, currentHost, currentAddress); - } else { + break; + case ResolverEvent.Timeout: currentAddress = null; currentHost = null; foreach (EventHandler handler in timeoutListeners) handler (this, new EventArgs ()); + break; + default: + EmitResolverEvent (revent); + break; } } } diff --git a/avahi-sharp/HostNameResolver.cs b/avahi-sharp/HostNameResolver.cs index fad5d77..44febcd 100644 --- a/avahi-sharp/HostNameResolver.cs +++ b/avahi-sharp/HostNameResolver.cs @@ -32,7 +32,7 @@ namespace Avahi ResolverEvent revent, IntPtr hostname, IntPtr address, LookupResultFlags flags, IntPtr userdata); - public class HostNameResolver : IDisposable + public class HostNameResolver : ResolverBase, IDisposable { private IntPtr handle; private Client client; @@ -151,18 +151,24 @@ namespace Avahi ResolverEvent revent, IntPtr hostname, IntPtr address, LookupResultFlags flags, IntPtr userdata) { - if (revent == ResolverEvent.Found) { + switch (revent) { + case ResolverEvent.Found: currentAddress = Utility.PtrToAddress (address); currentHost = Utility.PtrToString (hostname); foreach (HostAddressHandler handler in foundListeners) handler (this, currentHost, currentAddress); - } else { + break; + case ResolverEvent.Timeout: currentAddress = null; currentHost = null; foreach (EventHandler handler in timeoutListeners) handler (this, new EventArgs ()); + break; + default: + EmitResolverEvent (revent); + break; } } } diff --git a/avahi-sharp/Makefile.am b/avahi-sharp/Makefile.am index d3e7ffb..80fd06e 100644 --- a/avahi-sharp/Makefile.am +++ b/avahi-sharp/Makefile.am @@ -30,6 +30,7 @@ AVAHISOURCES = \ $(srcdir)/DomainBrowser.cs \ $(srcdir)/EntryGroup.cs \ $(srcdir)/HostNameResolver.cs \ + $(srcdir)/ResolverBase.cs \ $(srcdir)/ServiceBrowser.cs \ $(srcdir)/ServiceResolver.cs \ $(srcdir)/ServiceTypeBrowser.cs \ diff --git a/avahi-sharp/ResolverBase.cs b/avahi-sharp/ResolverBase.cs new file mode 100644 index 0000000..0fdd4a1 --- /dev/null +++ b/avahi-sharp/ResolverBase.cs @@ -0,0 +1,47 @@ +/* $Id$ */ + +/*** + This file is part of avahi. + + avahi is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + avahi is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with avahi; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA. +***/ + +using System; + +namespace Avahi +{ + public abstract class ResolverBase + { + public event EventHandler NotFound; + public event EventHandler Failed; + + internal void EmitResolverEvent (ResolverEvent revent) + { + switch (revent) { + case ResolverEvent.NotFound: + if (NotFound != null) + NotFound (this, new EventArgs ()); + break; + case ResolverEvent.Failure: + if (Failed != null) + Failed (this, new EventArgs ()); + break; + default: + break; + } + } + } +} diff --git a/avahi-sharp/ServiceResolver.cs b/avahi-sharp/ServiceResolver.cs index e94bd13..7527652 100644 --- a/avahi-sharp/ServiceResolver.cs +++ b/avahi-sharp/ServiceResolver.cs @@ -34,7 +34,7 @@ namespace Avahi UInt16 port, IntPtr txt, LookupResultFlags flags, IntPtr userdata); - public class ServiceResolver : IDisposable + public class ServiceResolver : ResolverBase, IDisposable { private IntPtr handle; private ServiceInfo currentInfo; @@ -199,17 +199,23 @@ namespace Avahi info.Text = (byte[][]) txtlist.ToArray (typeof (byte[])); info.Flags = flags; - - if (revent == ResolverEvent.Found) { + + switch (revent) { + case ResolverEvent.Found: currentInfo = info; foreach (ServiceInfoHandler handler in foundListeners) handler (this, info); - } else { + break; + case ResolverEvent.Timeout: currentInfo = ServiceInfo.Zero; foreach (EventHandler handler in timeoutListeners) handler (this, new EventArgs ()); + break; + default: + EmitResolverEvent (revent); + break; } } |