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);
--- /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 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;
+ }
+ }
+ }
+}
{
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);
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 ();
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;
}
}
}
AVAHISOURCES = \
$(srcdir)/AddressResolver.cs \
$(srcdir)/AssemblyInfo.cs \
+ $(srcdir)/BrowserBase.cs \
$(srcdir)/Client.cs \
$(srcdir)/ClientException.cs \
$(srcdir)/DomainBrowser.cs \
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 ();
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;
}
}
}
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 ();
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;
}
}
}