]> git.meshlink.io Git - catta/commitdiff
add base class for resolvers, and add some missing events there
authorJames Willcox <snopr@snorp.net>
Mon, 26 Sep 2005 06:57:41 +0000 (06:57 +0000)
committerJames Willcox <snopr@snorp.net>
Mon, 26 Sep 2005 06:57:41 +0000 (06:57 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@636 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-sharp/AddressResolver.cs
avahi-sharp/HostNameResolver.cs
avahi-sharp/Makefile.am
avahi-sharp/ResolverBase.cs [new file with mode: 0644]
avahi-sharp/ServiceResolver.cs

index 038b0c9aef591cdafdba0183d9f90cb6115025bd..01211aecd9cb6e20676c5efe260decfcda3369a9 100644 (file)
@@ -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;
             }
         }
     }
index fad5d77498c604dfe013e50174d3030f60561822..44febcdf4d1a8f4d2bc4703978bdb936deb4f501 100644 (file)
@@ -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;
             }
         }
     }
index d3e7ffb3f9d873b9a858d135ad8240786c86aed6..80fd06e9a8ab657b26c8e461b8b266cfa99a14e9 100644 (file)
@@ -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 (file)
index 0000000..0fdd4a1
--- /dev/null
@@ -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;
+            }
+        }
+    }
+}
index e94bd13bba53d85d49399c5212778d2729542ac6..7527652d6ac485f20346dbeb710331354ca3151c 100644 (file)
@@ -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;
             }
         }