From a9566d5dcac080d7fa91546823277c57a5d09a5f Mon Sep 17 00:00:00 2001 From: James Willcox Date: Fri, 9 Sep 2005 23:48:54 +0000 Subject: [PATCH] s/Host/HostName/ in a couple places, and keep references to callbacks to avoid crashing git-svn-id: file:///home/lennart/svn/public/avahi/trunk@554 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-sharp/AddressResolver.cs | 4 +++- avahi-sharp/AvahiTest.cs | 2 +- avahi-sharp/Client.cs | 11 ++++++++--- avahi-sharp/DomainBrowser.cs | 4 +++- avahi-sharp/HostNameResolver.cs | 2 ++ avahi-sharp/ServiceBrowser.cs | 10 +++++----- avahi-sharp/ServiceResolver.cs | 8 ++++---- avahi-sharp/ServiceTypeBrowser.cs | 4 +++- 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/avahi-sharp/AddressResolver.cs b/avahi-sharp/AddressResolver.cs index 8a0b66b..6b0d030 100644 --- a/avahi-sharp/AddressResolver.cs +++ b/avahi-sharp/AddressResolver.cs @@ -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); } diff --git a/avahi-sharp/AvahiTest.cs b/avahi-sharp/AvahiTest.cs index 7be4b06..042bc28 100644 --- a/avahi-sharp/AvahiTest.cs +++ b/avahi-sharp/AvahiTest.cs @@ -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)); } diff --git a/avahi-sharp/Client.cs b/avahi-sharp/Client.cs index 3e4e617..84069fc 100644 --- a/avahi-sharp/Client.cs +++ b/avahi-sharp/Client.cs @@ -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); } } } diff --git a/avahi-sharp/DomainBrowser.cs b/avahi-sharp/DomainBrowser.cs index db42265..cc93641 100644 --- a/avahi-sharp/DomainBrowser.cs +++ b/avahi-sharp/DomainBrowser.cs @@ -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); } diff --git a/avahi-sharp/HostNameResolver.cs b/avahi-sharp/HostNameResolver.cs index d5e4bf3..8b529c7 100644 --- a/avahi-sharp/HostNameResolver.cs +++ b/avahi-sharp/HostNameResolver.cs @@ -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 () diff --git a/avahi-sharp/ServiceBrowser.cs b/avahi-sharp/ServiceBrowser.cs index 3ed50bc..a96040c 100644 --- a/avahi-sharp/ServiceBrowser.cs +++ b/avahi-sharp/ServiceBrowser.cs @@ -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; diff --git a/avahi-sharp/ServiceResolver.cs b/avahi-sharp/ServiceResolver.cs index 1b5d51a..ef1f303 100644 --- a/avahi-sharp/ServiceResolver.cs +++ b/avahi-sharp/ServiceResolver.cs @@ -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; diff --git a/avahi-sharp/ServiceTypeBrowser.cs b/avahi-sharp/ServiceTypeBrowser.cs index c3b8159..e436da9 100644 --- a/avahi-sharp/ServiceTypeBrowser.cs +++ b/avahi-sharp/ServiceTypeBrowser.cs @@ -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); } -- 2.39.5