X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FServiceTypeBrowser.cs;h=754b9b151066e7769711583a7805e95b9949fd26;hb=57c2beeef0ae8e84dc790f023867da5dfc9aac7f;hp=cd6bfbb0db978947e1cf95b289e6679d8af84f86;hpb=a21074b9ea4b11b74d114e2669248f979caf0d3a;p=catta diff --git a/avahi-sharp/ServiceTypeBrowser.cs b/avahi-sharp/ServiceTypeBrowser.cs index cd6bfbb..754b9b1 100644 --- a/avahi-sharp/ServiceTypeBrowser.cs +++ b/avahi-sharp/ServiceTypeBrowser.cs @@ -1,3 +1,5 @@ +/* $Id$ */ + /*** This file is part of avahi. @@ -24,7 +26,8 @@ using System.Runtime.InteropServices; namespace Avahi { internal delegate void ServiceTypeBrowserCallback (IntPtr browser, int iface, Protocol proto, BrowserEvent bevent, - IntPtr type, IntPtr domain, IntPtr userdata); + IntPtr type, IntPtr domain, LookupResultFlags flags, + IntPtr userdata); public struct ServiceTypeInfo { @@ -32,11 +35,12 @@ namespace Avahi public Protocol Protocol; public string Domain; public string ServiceType; + public LookupResultFlags Flags; } 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 (); @@ -44,13 +48,16 @@ namespace Avahi private int iface; private Protocol proto; private string domain; + private LookupFlags flags; + private ServiceTypeBrowserCallback cb; private ArrayList addListeners = new ArrayList (); private ArrayList removeListeners = new ArrayList (); [DllImport ("avahi-client")] private static extern IntPtr avahi_service_type_browser_new (IntPtr client, int iface, int proto, - IntPtr domain, ServiceTypeBrowserCallback cb, + IntPtr domain, LookupFlags flags, + ServiceTypeBrowserCallback cb, IntPtr userdata); [DllImport ("avahi-client")] @@ -89,16 +96,19 @@ namespace Avahi { } - public ServiceTypeBrowser (Client client, string domain) : this (client, -1, Protocol.Unspecified, domain) + public ServiceTypeBrowser (Client client, string domain) : this (client, -1, Protocol.Unspecified, + domain, LookupFlags.None) { } - - public ServiceTypeBrowser (Client client, int iface, Protocol proto, string domain) + + public ServiceTypeBrowser (Client client, int iface, Protocol proto, string domain, LookupFlags flags) { this.client = client; this.iface = iface; this.proto = proto; this.domain = domain; + this.flags = flags; + cb = OnServiceTypeBrowserCallback; } ~ServiceTypeBrowser () @@ -113,25 +123,33 @@ namespace Avahi private void Start () { - if (handle != IntPtr.Zero || (addListeners.Count == 0 && removeListeners.Count == 0)) + if (client.Handle == IntPtr.Zero || handle != IntPtr.Zero || + (addListeners.Count == 0 && removeListeners.Count == 0)) return; - IntPtr domainPtr = Utility.StringToPtr (domain); - handle = avahi_service_type_browser_new (client.Handle, iface, (int) proto, domainPtr, - OnServiceTypeBrowserCallback, IntPtr.Zero); - Utility.Free (domainPtr); + lock (client) { + IntPtr domainPtr = Utility.StringToPtr (domain); + handle = avahi_service_type_browser_new (client.Handle, iface, (int) proto, domainPtr, flags, + cb, IntPtr.Zero); + Utility.Free (domainPtr); + } } private void Stop (bool force) { - if (handle != IntPtr.Zero && (force || (addListeners.Count == 0 && removeListeners.Count == 0))) { - avahi_service_type_browser_free (handle); - handle = IntPtr.Zero; + if (client.Handle != IntPtr.Zero && handle != IntPtr.Zero && + (force || (addListeners.Count == 0 && removeListeners.Count == 0))) { + + lock (client) { + avahi_service_type_browser_free (handle); + handle = IntPtr.Zero; + } } } private void OnServiceTypeBrowserCallback (IntPtr browser, int iface, Protocol proto, BrowserEvent bevent, - IntPtr type, IntPtr domain, IntPtr userdata) + IntPtr type, IntPtr domain, LookupResultFlags flags, + IntPtr userdata) { ServiceTypeInfo info; @@ -139,19 +157,26 @@ namespace Avahi info.Protocol = proto; info.Domain = Utility.PtrToString (domain); info.ServiceType = Utility.PtrToString (type); + 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; } } }