]> git.meshlink.io Git - catta/blobdiff - avahi-sharp/ServiceResolver.cs
oops, forgot some flag bits in ServiceResolver
[catta] / avahi-sharp / ServiceResolver.cs
index ef1f3037155ca927b836304b70ae53ba049f238c..e94bd13bba53d85d49399c5212778d2729542ac6 100644 (file)
@@ -31,7 +31,8 @@ namespace Avahi
     internal delegate void ServiceResolverCallback (IntPtr resolver, int iface, Protocol proto,
                                                     ResolverEvent revent, IntPtr name, IntPtr type,
                                                     IntPtr domain, IntPtr host, IntPtr address,
     internal delegate void ServiceResolverCallback (IntPtr resolver, int iface, Protocol proto,
                                                     ResolverEvent revent, IntPtr name, IntPtr type,
                                                     IntPtr domain, IntPtr host, IntPtr address,
-                                                    UInt16 port, IntPtr txt, IntPtr userdata);
+                                                    UInt16 port, IntPtr txt, LookupResultFlags flags,
+                                                    IntPtr userdata);
 
     public class ServiceResolver : IDisposable
     {
 
     public class ServiceResolver : IDisposable
     {
@@ -44,6 +45,7 @@ namespace Avahi
         private string type;
         private string domain;
         private Protocol aproto;
         private string type;
         private string domain;
         private Protocol aproto;
+        private LookupFlags flags;
         private ServiceResolverCallback cb;
 
         private ArrayList foundListeners = new ArrayList ();
         private ServiceResolverCallback cb;
 
         private ArrayList foundListeners = new ArrayList ();
@@ -52,7 +54,8 @@ namespace Avahi
         [DllImport ("avahi-client")]
         private static extern IntPtr avahi_service_resolver_new (IntPtr client, int iface, Protocol proto,
                                                                  IntPtr name, IntPtr type, IntPtr domain,
         [DllImport ("avahi-client")]
         private static extern IntPtr avahi_service_resolver_new (IntPtr client, int iface, Protocol proto,
                                                                  IntPtr name, IntPtr type, IntPtr domain,
-                                                                 Protocol aproto, ServiceResolverCallback cb,
+                                                                 Protocol aproto, LookupFlags flags,
+                                                                 ServiceResolverCallback cb,
                                                                  IntPtr userdata);
 
         [DllImport ("avahi-common")]
                                                                  IntPtr userdata);
 
         [DllImport ("avahi-common")]
@@ -99,19 +102,21 @@ namespace Avahi
         public ServiceResolver (Client client, string name, string type, string domain) : this (client, -1,
                                                                                                 Protocol.Unspecified,
                                                                                                 name, type, domain,
         public ServiceResolver (Client client, string name, string type, string domain) : this (client, -1,
                                                                                                 Protocol.Unspecified,
                                                                                                 name, type, domain,
-                                                                                                Protocol.Unspecified)
+                                                                                                Protocol.Unspecified,
+                                                                                                LookupFlags.None)
         {
         }
 
         public ServiceResolver (Client client, ServiceInfo service) : this (client, service.NetworkInterface,
                                                                             service.Protocol, service.Name,
                                                                             service.ServiceType, service.Domain,
         {
         }
 
         public ServiceResolver (Client client, ServiceInfo service) : this (client, service.NetworkInterface,
                                                                             service.Protocol, service.Name,
                                                                             service.ServiceType, service.Domain,
-                                                                            Protocol.Unspecified)
+                                                                            Protocol.Unspecified,
+                                                                            GetLookupFlags (service.Flags))
         {
         }
         
         public ServiceResolver (Client client, int iface, Protocol proto, string name,
         {
         }
         
         public ServiceResolver (Client client, int iface, Protocol proto, string name,
-                                string type, string domain, Protocol aproto)
+                                string type, string domain, Protocol aproto, LookupFlags flags)
         {
             this.client = client;
             this.iface = iface;
         {
             this.client = client;
             this.iface = iface;
@@ -120,6 +125,7 @@ namespace Avahi
             this.type = type;
             this.domain = domain;
             this.aproto = aproto;
             this.type = type;
             this.domain = domain;
             this.aproto = aproto;
+            this.flags = flags;
             cb = OnServiceResolverCallback;
         }
 
             cb = OnServiceResolverCallback;
         }
 
@@ -135,14 +141,19 @@ namespace Avahi
 
         private void Start ()
         {
 
         private void Start ()
         {
-            if (handle != IntPtr.Zero || (foundListeners.Count == 0 && timeoutListeners.Count == 0))
+            if (client.Handle == IntPtr.Zero || handle != IntPtr.Zero ||
+                (foundListeners.Count == 0 && timeoutListeners.Count == 0))
                 return;
 
             IntPtr namePtr = Utility.StringToPtr (name);
             IntPtr typePtr = Utility.StringToPtr (type);
             IntPtr domainPtr = Utility.StringToPtr (domain);
                 return;
 
             IntPtr namePtr = Utility.StringToPtr (name);
             IntPtr typePtr = Utility.StringToPtr (type);
             IntPtr domainPtr = Utility.StringToPtr (domain);
-            handle = avahi_service_resolver_new (client.Handle, iface, proto, namePtr, typePtr, domainPtr,
-                                                 aproto, cb, IntPtr.Zero);
+
+            lock (client) {
+                handle = avahi_service_resolver_new (client.Handle, iface, proto, namePtr, typePtr, domainPtr,
+                                                     aproto, flags, cb, IntPtr.Zero);
+            }
+            
             Utility.Free (namePtr);
             Utility.Free (typePtr);
             Utility.Free (domainPtr);
             Utility.Free (namePtr);
             Utility.Free (typePtr);
             Utility.Free (domainPtr);
@@ -150,16 +161,21 @@ namespace Avahi
 
         private void Stop (bool force)
         {
 
         private void Stop (bool force)
         {
-            if (handle != IntPtr.Zero && (force || (foundListeners.Count == 0 && timeoutListeners.Count == 0))) {
-                avahi_service_resolver_free (handle);
-                handle = IntPtr.Zero;
+            if (client.Handle != IntPtr.Zero && handle != IntPtr.Zero &&
+                (force || (foundListeners.Count == 0 && timeoutListeners.Count == 0))) {
+
+                lock (client) {
+                    avahi_service_resolver_free (handle);
+                    handle = IntPtr.Zero;
+                }
             }
         }
 
         private void OnServiceResolverCallback (IntPtr resolver, int iface, Protocol proto,
                                                 ResolverEvent revent, IntPtr name, IntPtr type,
                                                 IntPtr domain, IntPtr host, IntPtr address,
             }
         }
 
         private void OnServiceResolverCallback (IntPtr resolver, int iface, Protocol proto,
                                                 ResolverEvent revent, IntPtr name, IntPtr type,
                                                 IntPtr domain, IntPtr host, IntPtr address,
-                                                UInt16 port, IntPtr txt, IntPtr userdata)
+                                                UInt16 port, IntPtr txt, LookupResultFlags flags,
+                                                IntPtr userdata)
         {
             ServiceInfo info;
             info.NetworkInterface = iface;
         {
             ServiceInfo info;
             info.NetworkInterface = iface;
@@ -182,6 +198,7 @@ namespace Avahi
             }
 
             info.Text = (byte[][]) txtlist.ToArray (typeof (byte[]));
             }
 
             info.Text = (byte[][]) txtlist.ToArray (typeof (byte[]));
+            info.Flags = flags;
             
             if (revent == ResolverEvent.Found) {
                 currentInfo = info;
             
             if (revent == ResolverEvent.Found) {
                 currentInfo = info;
@@ -195,5 +212,16 @@ namespace Avahi
                     handler (this, new EventArgs ());
             }
         }
                     handler (this, new EventArgs ());
             }
         }
+
+        private static LookupFlags GetLookupFlags (LookupResultFlags rflags) {
+            LookupFlags ret = LookupFlags.None;
+
+            if ((rflags & LookupResultFlags.Multicast) > 0)
+                ret |= LookupFlags.UseMulticast;
+            if ((rflags & LookupResultFlags.WideArea) > 0)
+                ret |= LookupFlags.UseWideArea;
+
+            return ret;
+        }
     }
 }
     }
 }