X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-sharp%2FServiceTypeBrowser.cs;h=e1356d00a4623cf1a2ddae808972273e6bebcafb;hb=fe8f5ec6f8e86c6eea88dd196fbcb60deeef0795;hp=ab6a8668183d852a84ab0aa7997c084d09f350b5;hpb=264700bf97de2e4430494cb41201950162fba020;p=catta diff --git a/avahi-sharp/ServiceTypeBrowser.cs b/avahi-sharp/ServiceTypeBrowser.cs index ab6a866..e1356d0 100644 --- a/avahi-sharp/ServiceTypeBrowser.cs +++ b/avahi-sharp/ServiceTypeBrowser.cs @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of avahi. @@ -22,23 +20,41 @@ using System; using System.Collections; using System.Runtime.InteropServices; +using System.Text; 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 { public int NetworkInterface; public Protocol Protocol; public string Domain; public string ServiceType; + public LookupResultFlags Flags; + } + + public class ServiceTypeInfoArgs : EventArgs + { + private ServiceTypeInfo type; + + public ServiceTypeInfo ServiceType + { + get { return type; } + } + + public ServiceTypeInfoArgs (ServiceTypeInfo type) + { + this.type = type; + } } - public delegate void ServiceTypeInfoHandler (object o, ServiceTypeInfo info); - - public class ServiceTypeBrowser : IDisposable + public delegate void ServiceTypeInfoHandler (object o, ServiceTypeInfoArgs args); + + public class ServiceTypeBrowser : BrowserBase, IDisposable { private IntPtr handle; private ArrayList infos = new ArrayList (); @@ -46,14 +62,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, + byte[] domain, LookupFlags flags, + ServiceTypeBrowserCallback cb, IntPtr userdata); [DllImport ("avahi-client")] @@ -70,7 +88,7 @@ namespace Avahi Stop (false); } } - + public event ServiceTypeInfoHandler ServiceTypeRemoved { add { @@ -92,16 +110,18 @@ 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; } @@ -122,10 +142,12 @@ namespace Avahi return; lock (client) { - IntPtr domainPtr = Utility.StringToPtr (domain); - handle = avahi_service_type_browser_new (client.Handle, iface, (int) proto, domainPtr, + handle = avahi_service_type_browser_new (client.Handle, iface, (int) proto, + Utility.StringToBytes (domain), flags, cb, IntPtr.Zero); - Utility.Free (domainPtr); + + if (handle == IntPtr.Zero) + client.ThrowError (); } } @@ -142,7 +164,8 @@ namespace Avahi } 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; @@ -150,19 +173,24 @@ 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 { + handler (this, new ServiceTypeInfoArgs (info)); + break; + case BrowserEvent.Removed: infos.Remove (info); foreach (ServiceTypeInfoHandler handler in removeListeners) - handler (this, info); + handler (this, new ServiceTypeInfoArgs (info)); + break; + default: + EmitBrowserEvent (bevent); + break; } } }