4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 using System.Collections;
25 using System.Runtime.InteropServices;
29 internal enum ResolverEvent {
34 internal enum BrowserEvent {
39 internal delegate void ClientCallback (IntPtr client, ClientState state, IntPtr userData);
41 public delegate void ClientStateHandler (object o, ClientState state);
43 public enum Protocol {
49 public enum ClientState {
57 public class Client : IDisposable
59 private IntPtr handle;
61 [DllImport ("avahi-client")]
62 private static extern IntPtr avahi_client_new (IntPtr poll, ClientCallback handler,
63 IntPtr userData, out int error);
65 [DllImport ("avahi-client")]
66 private static extern void avahi_client_free (IntPtr handle);
68 [DllImport ("avahi-client")]
69 private static extern IntPtr avahi_client_get_version_string (IntPtr handle);
71 [DllImport ("avahi-client")]
72 private static extern IntPtr avahi_client_get_host_name (IntPtr handle);
74 [DllImport ("avahi-client")]
75 private static extern IntPtr avahi_client_get_domain_name (IntPtr handle);
77 [DllImport ("avahi-client")]
78 private static extern IntPtr avahi_client_get_host_name_fqdn (IntPtr handle);
80 [DllImport ("avahi-client")]
81 private static extern ClientState avahi_client_get_state (IntPtr handle);
83 [DllImport ("avahi-client")]
84 private static extern int avahi_client_errno (IntPtr handle);
86 [DllImport ("avahi-glib")]
87 private static extern IntPtr avahi_glib_poll_new (IntPtr context, int priority);
89 [DllImport ("avahi-glib")]
90 private static extern IntPtr avahi_glib_poll_get (IntPtr gpoll);
92 public event ClientStateHandler StateChanged;
94 internal IntPtr Handle
96 get { return handle; }
101 get { return Utility.PtrToString (avahi_client_get_version_string (handle)); }
104 public string HostName
106 get { return Utility.PtrToString (avahi_client_get_host_name (handle)); }
109 public string DomainName
111 get { return Utility.PtrToString (avahi_client_get_domain_name (handle)); }
114 public string HostNameFqdn
116 get { return Utility.PtrToString (avahi_client_get_host_name_fqdn (handle)); }
119 public ClientState State
121 get { return (ClientState) avahi_client_get_state (handle); }
124 internal int LastError
126 get { return avahi_client_errno (handle); }
131 IntPtr gpoll = avahi_glib_poll_new (IntPtr.Zero, 0);
132 IntPtr poll = avahi_glib_poll_get (gpoll);
135 handle = avahi_client_new (poll, OnClientCallback, IntPtr.Zero, out error);
137 throw new ClientException (error);
145 public void Dispose ()
147 if (handle != IntPtr.Zero) {
148 avahi_client_free (handle);
149 handle = IntPtr.Zero;
153 internal void CheckError ()
155 int error = LastError;
158 throw new ClientException (error);
161 private void OnClientCallback (IntPtr client, ClientState state, IntPtr userData)
163 if (StateChanged != null)
164 StateChanged (this, state);