From a4c2edcece605452c4d72da36b8c39da5e514314 Mon Sep 17 00:00:00 2001 From: James Willcox Date: Mon, 26 Sep 2005 03:57:30 +0000 Subject: [PATCH] add some missing events to the resolver classes, and make them 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 | 6 ++++ avahi-sharp/BrowserBase.cs | 57 +++++++++++++++++++++++++++++++ avahi-sharp/Client.cs | 10 ++++-- avahi-sharp/DomainBrowser.cs | 14 +++++--- avahi-sharp/Makefile.am | 1 + avahi-sharp/ServiceBrowser.cs | 16 ++++++--- avahi-sharp/ServiceTypeBrowser.cs | 14 +++++--- 7 files changed, 104 insertions(+), 14 deletions(-) create mode 100644 avahi-sharp/BrowserBase.cs diff --git a/avahi-sharp/AvahiTest.cs b/avahi-sharp/AvahiTest.cs index 0f8e1c0..395d5cb 100644 --- a/avahi-sharp/AvahiTest.cs +++ b/avahi-sharp/AvahiTest.cs @@ -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 index 0000000..2968114 --- /dev/null +++ b/avahi-sharp/BrowserBase.cs @@ -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; + } + } + } +} diff --git a/avahi-sharp/Client.cs b/avahi-sharp/Client.cs index f5ba069..e148ff3 100644 --- a/avahi-sharp/Client.cs +++ b/avahi-sharp/Client.cs @@ -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); diff --git a/avahi-sharp/DomainBrowser.cs b/avahi-sharp/DomainBrowser.cs index fb32e77..3ce9e4d 100644 --- a/avahi-sharp/DomainBrowser.cs +++ b/avahi-sharp/DomainBrowser.cs @@ -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; } } } diff --git a/avahi-sharp/Makefile.am b/avahi-sharp/Makefile.am index 5e8de1f..d3e7ffb 100644 --- a/avahi-sharp/Makefile.am +++ b/avahi-sharp/Makefile.am @@ -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 \ diff --git a/avahi-sharp/ServiceBrowser.cs b/avahi-sharp/ServiceBrowser.cs index 92b8011..a9c1726 100644 --- a/avahi-sharp/ServiceBrowser.cs +++ b/avahi-sharp/ServiceBrowser.cs @@ -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; } } } diff --git a/avahi-sharp/ServiceTypeBrowser.cs b/avahi-sharp/ServiceTypeBrowser.cs index 4d996d6..754b9b1 100644 --- a/avahi-sharp/ServiceTypeBrowser.cs +++ b/avahi-sharp/ServiceTypeBrowser.cs @@ -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; } } } -- 2.39.5