]> git.meshlink.io Git - catta/commitdiff
s/Host/HostName/ in a couple places, and keep references to callbacks to
authorJames Willcox <snopr@snorp.net>
Fri, 9 Sep 2005 23:48:54 +0000 (23:48 +0000)
committerJames Willcox <snopr@snorp.net>
Fri, 9 Sep 2005 23:48:54 +0000 (23:48 +0000)
avoid crashing

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@554 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-sharp/AddressResolver.cs
avahi-sharp/AvahiTest.cs
avahi-sharp/Client.cs
avahi-sharp/DomainBrowser.cs
avahi-sharp/HostNameResolver.cs
avahi-sharp/ServiceBrowser.cs
avahi-sharp/ServiceResolver.cs
avahi-sharp/ServiceTypeBrowser.cs

index 8a0b66ba6e3d63ce2f6b280af0b40e423f53394a..6b0d0309f0a7c1ac92780d293521577589d3f7c0 100644 (file)
@@ -41,6 +41,7 @@ namespace Avahi
         private int iface;
         private Protocol proto;
         private IPAddress address;
+        private AddressResolverCallback cb;
 
         private IPAddress currentAddress;
         private string currentHost;
@@ -100,6 +101,7 @@ namespace Avahi
             this.iface = iface;
             this.proto = proto;
             this.address = address;
+            cb = OnAddressResolverCallback;
         }
 
         ~AddressResolver ()
@@ -119,7 +121,7 @@ namespace Avahi
 
             IntPtr addrPtr = Utility.StringToPtr (address.ToString ());
             handle = avahi_address_resolver_new (client.Handle, iface, proto, addrPtr,
-                                                 OnAddressResolverCallback, IntPtr.Zero);
+                                                 cb, IntPtr.Zero);
             Utility.Free (addrPtr);
         }
 
index 7be4b0650867646caa96b8ba0c85295d87dd011c..042bc28fa5a7f8ff2316a61229c2eef1078232cd 100644 (file)
@@ -73,7 +73,7 @@ public class AvahiTest {
 
        private static void OnServiceResolved (object o, ServiceInfo info)
        {
-               Console.WriteLine ("Service '{0}' at {1}:{2}", info.Name, info.Host, info.Port);
+               Console.WriteLine ("Service '{0}' at {1}:{2}", info.Name, info.HostName, info.Port);
                foreach (byte[] bytes in info.Text) {
                        Console.WriteLine ("Text: " + Encoding.UTF8.GetString (bytes));
                }
index 3e4e617b7742f5baf20d9f8f7a0e157382e5ace7..84069fc571dddefa13a1926a530e3ebb29523ef6 100644 (file)
@@ -36,7 +36,9 @@ namespace Avahi
         Removed
     }
     
-    internal delegate void ClientHandler (IntPtr client, ClientState state, IntPtr userData);
+    internal delegate void ClientCallback (IntPtr client, ClientState state, IntPtr userData);
+
+    public delegate void ClientStateHandler (object o, ClientState state);
 
     public enum Protocol {
         Unspecified = 0,
@@ -57,7 +59,7 @@ namespace Avahi
         private IntPtr handle;
 
         [DllImport ("avahi-client")]
-        private static extern IntPtr avahi_client_new (IntPtr poll, ClientHandler handler,
+        private static extern IntPtr avahi_client_new (IntPtr poll, ClientCallback handler,
                                                        IntPtr userData, out int error);
 
         [DllImport ("avahi-client")]
@@ -87,6 +89,8 @@ namespace Avahi
         [DllImport ("avahi-glib")]
         private static extern IntPtr avahi_glib_poll_get (IntPtr gpoll);
 
+        public event ClientStateHandler StateChanged;
+
         internal IntPtr Handle
         {
             get { return handle; }
@@ -156,7 +160,8 @@ namespace Avahi
         
         private void OnClientCallback (IntPtr client, ClientState state, IntPtr userData)
         {
-            Console.WriteLine ("Got new state: " + state);
+            if (StateChanged != null)
+                StateChanged (this, state);
         }
     }
 }
index db4226596986c118db7ebcf376f5757d04c21c51..cc93641c8cbf9abd927fdac1d7972aefca002056 100644 (file)
@@ -54,6 +54,7 @@ namespace Avahi
         private Protocol proto;
         private string domain;
         private DomainBrowserType btype;
+        private DomainBrowserCallback cb;
 
         private ArrayList addListeners = new ArrayList ();
         private ArrayList removeListeners = new ArrayList ();
@@ -106,6 +107,7 @@ namespace Avahi
             this.proto = proto;
             this.domain = domain;
             this.btype = btype;
+            cb = OnDomainBrowserCallback;
         }
 
         ~DomainBrowser ()
@@ -125,7 +127,7 @@ namespace Avahi
 
             IntPtr domainPtr = Utility.StringToPtr (domain);
             handle = avahi_domain_browser_new (client.Handle, iface, (int) proto, domainPtr, (int) btype,
-                                               OnDomainBrowserCallback, IntPtr.Zero);
+                                               cb, IntPtr.Zero);
             Utility.Free (domainPtr);
         }
 
index d5e4bf34e2b9c01282f6f1726aa119deff7bfc09..8b529c702b0bbda9edb0ef02a92cfe603096ef81 100644 (file)
@@ -40,6 +40,7 @@ namespace Avahi
         private Protocol proto;
         private string hostname;
         private Protocol aproto;
+        private HostNameResolverCallback cb;
 
         private IPAddress currentAddress;
         private string currentHost;
@@ -102,6 +103,7 @@ namespace Avahi
             this.proto = proto;
             this.hostname = hostname;
             this.aproto = aproto;
+            cb = OnHostNameResolverCallback;
         }
 
         ~HostNameResolver ()
index 3ed50bc0a81296b2944e3f667cbf938c1a8f7980..a96040cbc822770f377722bb3b580f7c567a9735 100644 (file)
@@ -37,7 +37,7 @@ namespace Avahi
         public string ServiceType;
         public string Name;
 
-        public string Host;
+        public string HostName;
         public IPAddress Address;
         public UInt16 Port;
         public byte[][] Text;
@@ -56,6 +56,7 @@ namespace Avahi
         private Protocol proto;
         private string domain;
         private string type;
+        private ServiceBrowserCallback cb;
 
         private ArrayList addListeners = new ArrayList ();
         private ArrayList removeListeners = new ArrayList ();
@@ -113,8 +114,7 @@ namespace Avahi
             this.proto = proto;
             this.domain = domain;
             this.type = type;
-            
-            
+            cb = OnServiceBrowserCallback;
         }
 
         ~ServiceBrowser ()
@@ -135,7 +135,7 @@ namespace Avahi
             IntPtr domainPtr = Utility.StringToPtr (domain);
             IntPtr typePtr = Utility.StringToPtr (type);
             handle = avahi_service_browser_new (client.Handle, iface, (int) proto, typePtr, domainPtr,
-                                                OnServiceBrowserCallback, IntPtr.Zero);
+                                                cb, IntPtr.Zero);
             Utility.Free (domainPtr);
             Utility.Free (typePtr);
         }
@@ -158,7 +158,7 @@ namespace Avahi
             info.Domain = Utility.PtrToString (domain);
             info.ServiceType = Utility.PtrToString (type);
             info.Name = Utility.PtrToString (name);
-            info.Host = null;
+            info.HostName = null;
             info.Address = null;
             info.Port = 0;
             info.Text = null;
index 1b5d51a93a3907c4939e9b69a4ffe59900cb0ce2..ef1f3037155ca927b836304b70ae53ba049f238c 100644 (file)
@@ -44,6 +44,7 @@ namespace Avahi
         private string type;
         private string domain;
         private Protocol aproto;
+        private ServiceResolverCallback cb;
 
         private ArrayList foundListeners = new ArrayList ();
         private ArrayList timeoutListeners = new ArrayList ();
@@ -119,8 +120,7 @@ namespace Avahi
             this.type = type;
             this.domain = domain;
             this.aproto = aproto;
-            
-            
+            cb = OnServiceResolverCallback;
         }
 
         ~ServiceResolver ()
@@ -142,7 +142,7 @@ namespace Avahi
             IntPtr typePtr = Utility.StringToPtr (type);
             IntPtr domainPtr = Utility.StringToPtr (domain);
             handle = avahi_service_resolver_new (client.Handle, iface, proto, namePtr, typePtr, domainPtr,
-                                                 aproto, OnServiceResolverCallback, IntPtr.Zero);
+                                                 aproto, cb, IntPtr.Zero);
             Utility.Free (namePtr);
             Utility.Free (typePtr);
             Utility.Free (domainPtr);
@@ -167,7 +167,7 @@ namespace Avahi
             info.Domain = Utility.PtrToString (domain);
             info.ServiceType = Utility.PtrToString (type);
             info.Name = Utility.PtrToString (name);
-            info.Host = Utility.PtrToString (host);
+            info.HostName = Utility.PtrToString (host);
             info.Address = Utility.PtrToAddress (address);
             info.Port = port;
 
index c3b8159dcfd5b930092f57385b6418db38e8dea2..e436da9a834555e341b5a1546cd5b26db22692c5 100644 (file)
@@ -46,6 +46,7 @@ namespace Avahi
         private int iface;
         private Protocol proto;
         private string domain;
+        private ServiceTypeBrowserCallback cb;
 
         private ArrayList addListeners = new ArrayList ();
         private ArrayList removeListeners = new ArrayList ();
@@ -101,6 +102,7 @@ namespace Avahi
             this.iface = iface;
             this.proto = proto;
             this.domain = domain;
+            cb = OnServiceTypeBrowserCallback;
         }
 
         ~ServiceTypeBrowser ()
@@ -120,7 +122,7 @@ namespace Avahi
 
             IntPtr domainPtr = Utility.StringToPtr (domain);
             handle = avahi_service_type_browser_new (client.Handle, iface, (int) proto, domainPtr,
-                                                     OnServiceTypeBrowserCallback, IntPtr.Zero);
+                                                     cb, IntPtr.Zero);
             Utility.Free (domainPtr);
         }