]> git.meshlink.io Git - catta/commitdiff
add some missing events to the resolver classes, and make them
authorJames Willcox <snopr@snorp.net>
Mon, 26 Sep 2005 03:57:30 +0000 (03:57 +0000)
committerJames Willcox <snopr@snorp.net>
Mon, 26 Sep 2005 03:57:30 +0000 (03:57 +0000)
inherit from a base class which contains these events

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@635 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-sharp/AvahiTest.cs
avahi-sharp/BrowserBase.cs [new file with mode: 0644]
avahi-sharp/Client.cs
avahi-sharp/DomainBrowser.cs
avahi-sharp/Makefile.am
avahi-sharp/ServiceBrowser.cs
avahi-sharp/ServiceTypeBrowser.cs

index 0f8e1c0d9362b01f42f93c93d684327f0b4b3f5d..395d5cb104d6acc67068195fd4483193fc6882ed 100644 (file)
@@ -62,9 +62,15 @@ public class AvahiTest {
        private static void BrowseServiceTypes (string domain)
        {
                ServiceTypeBrowser stb = new ServiceTypeBrowser (client, domain);
+               stb.CacheExhausted += OnCacheExhausted;
                stb.ServiceTypeAdded += OnServiceTypeAdded;
        }
 
+       private static void OnCacheExhausted (object o, EventArgs args)
+       {
+               Console.WriteLine ("Cache is exhausted");
+       }
+
        private static void OnServiceTypeAdded (object o, ServiceTypeInfo info)
        {
                Console.WriteLine ("Got service type: " + info.ServiceType);
diff --git a/avahi-sharp/BrowserBase.cs b/avahi-sharp/BrowserBase.cs
new file mode 100644 (file)
index 0000000..2968114
--- /dev/null
@@ -0,0 +1,57 @@
+/* $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 BrowserBase
+    {
+        public event EventHandler CacheExhausted;
+        public event EventHandler AllForNow;
+        public event EventHandler NotFound;
+        public event EventHandler Failed;
+
+        internal void EmitBrowserEvent (BrowserEvent bevent)
+        {
+            switch (bevent) {
+            case BrowserEvent.CacheExhausted:
+                if (CacheExhausted != null)
+                    CacheExhausted (this, new EventArgs ());
+                break;
+            case BrowserEvent.AllForNow:
+                if (AllForNow != null)
+                    AllForNow (this, new EventArgs ());
+                break;
+            case BrowserEvent.NotFound:
+                if (NotFound != null)
+                    NotFound (this, new EventArgs ());
+                break;
+            case BrowserEvent.Failure:
+                if (Failed != null)
+                    Failed (this, new EventArgs ());
+                break;
+            default:
+                break;
+            }
+        }
+    }
+}
index f5ba0693779a78722f5f0a43dd7206fc30d7f09e..e148ff30ba8f379e04b76a00ec49614d097b34ec 100644 (file)
@@ -29,12 +29,18 @@ namespace Avahi
 {
     internal enum ResolverEvent {
         Found,
-        Timeout
+        Timeout,
+        NotFound,
+        Failure
     }
     
     internal enum BrowserEvent {
         Added,
-        Removed
+        Removed,
+        CacheExhausted,
+        AllForNow,
+        NotFound,
+        Failure
     }
 
     internal delegate int PollCallback (IntPtr ufds, uint nfds, int timeout);
index fb32e774e19865693b7d3bffb03b3c375ea4c54d..3ce9e4d83ef237c16ee8ba54b03a7ca1abb213fb 100644 (file)
@@ -46,7 +46,7 @@ namespace Avahi
 
     public delegate void DomainInfoHandler (object o, DomainInfo info);
     
-    public class DomainBrowser : IDisposable
+    public class DomainBrowser : BrowserBase, IDisposable
     {
         private IntPtr handle;
         private ArrayList infos = new ArrayList ();
@@ -161,17 +161,23 @@ namespace Avahi
             info.Flags = flags;
 
             infos.Add (info);
-            
-            if (bevent == BrowserEvent.Added) {
+
+            switch (bevent) {
+            case BrowserEvent.Added:
                 infos.Add (info);
 
                 foreach (DomainInfoHandler handler in addListeners)
                     handler (this, info);
-            } else {
+                break;
+            case BrowserEvent.Removed:
                 infos.Remove (info);
 
                 foreach (DomainInfoHandler handler in removeListeners)
                     handler (this, info);
+                break;
+            default:
+                EmitBrowserEvent (bevent);
+                break;
             }
         }
     }
index 5e8de1fe47627977eb97b47c745483f60c1d46b4..d3e7ffb3f9d873b9a858d135ad8240786c86aed6 100644 (file)
@@ -24,6 +24,7 @@ CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb $(ASSEMBLY).config
 AVAHISOURCES =                                 \
        $(srcdir)/AddressResolver.cs    \
        $(srcdir)/AssemblyInfo.cs       \
+       $(srcdir)/BrowserBase.cs        \
        $(srcdir)/Client.cs             \
        $(srcdir)/ClientException.cs    \
        $(srcdir)/DomainBrowser.cs      \
index 92b8011c92b128625f05a24e4a1b19f6aba13e8f..a9c1726c20fa6565f343a38c0c70e51d1d41912b 100644 (file)
@@ -49,7 +49,7 @@ namespace Avahi
 
     public delegate void ServiceInfoHandler (object o, ServiceInfo info);
     
-    public class ServiceBrowser : IDisposable
+    public class ServiceBrowser : BrowserBase, IDisposable
     {
         private IntPtr handle;
         private ArrayList infos = new ArrayList ();
@@ -179,17 +179,25 @@ namespace Avahi
             info.Flags = flags;
 
             infos.Add (info);
-            
-            if (bevent == BrowserEvent.Added) {
+
+            switch (bevent) {
+            case BrowserEvent.Added:
                 infos.Add (info);
 
                 foreach (ServiceInfoHandler handler in addListeners)
                     handler (this, info);
-            } else {
+
+                break;
+            case BrowserEvent.Removed:
                 infos.Remove (info);
 
                 foreach (ServiceInfoHandler handler in removeListeners)
                     handler (this, info);
+
+                break;
+            default:
+                EmitBrowserEvent (bevent);
+                break;
             }
         }
     }
index 4d996d6410811712860d1a79af9033afe7d6f9a5..754b9b151066e7769711583a7805e95b9949fd26 100644 (file)
@@ -40,7 +40,7 @@ namespace Avahi
 
     public delegate void ServiceTypeInfoHandler (object o, ServiceTypeInfo info);
     
-    public class ServiceTypeBrowser : IDisposable
+    public class ServiceTypeBrowser : BrowserBase, IDisposable
     {
         private IntPtr handle;
         private ArrayList infos = new ArrayList ();
@@ -160,17 +160,23 @@ namespace Avahi
             info.Flags = flags;
 
             infos.Add (info);
-            
-            if (bevent == BrowserEvent.Added) {
+
+            switch (bevent) {
+            case BrowserEvent.Added:
                 infos.Add (info);
 
                 foreach (ServiceTypeInfoHandler handler in addListeners)
                     handler (this, info);
-            } else {
+                break;
+            case BrowserEvent.Removed:
                 infos.Remove (info);
 
                 foreach (ServiceTypeInfoHandler handler in removeListeners)
                     handler (this, info);
+                break;
+            default:
+                EmitBrowserEvent (bevent);
+                break;
             }
         }
     }