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;
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;
}
}
}
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;
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;
}
}
}
$(srcdir)/DomainBrowser.cs \
$(srcdir)/EntryGroup.cs \
$(srcdir)/HostNameResolver.cs \
+ $(srcdir)/ResolverBase.cs \
$(srcdir)/ServiceBrowser.cs \
$(srcdir)/ServiceResolver.cs \
$(srcdir)/ServiceTypeBrowser.cs \
--- /dev/null
+/* $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;
+ }
+ }
+ }
+}
UInt16 port, IntPtr txt, LookupResultFlags flags,
IntPtr userdata);
- public class ServiceResolver : IDisposable
+ public class ServiceResolver : ResolverBase, IDisposable
{
private IntPtr handle;
private ServiceInfo currentInfo;
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;
}
}