2 This file is part of avahi.
4 avahi is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 avahi is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12 Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with avahi; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 using System.Collections;
23 using System.Runtime.InteropServices;
27 internal enum ResolverEvent {
32 internal enum BrowserEvent {
37 internal delegate void ClientHandler (IntPtr client, ClientState state, IntPtr userData);
39 public enum Protocol {
45 public enum ClientState {
53 public class Client : IDisposable
55 private IntPtr handle;
57 [DllImport ("avahi-client")]
58 private static extern IntPtr avahi_client_new (IntPtr poll, ClientHandler handler,
59 IntPtr userData, out int error);
61 [DllImport ("avahi-client")]
62 private static extern void avahi_client_free (IntPtr handle);
64 [DllImport ("avahi-client")]
65 private static extern IntPtr avahi_client_get_version_string (IntPtr handle);
67 [DllImport ("avahi-client")]
68 private static extern IntPtr avahi_client_get_host_name (IntPtr handle);
70 [DllImport ("avahi-client")]
71 private static extern IntPtr avahi_client_get_domain_name (IntPtr handle);
73 [DllImport ("avahi-client")]
74 private static extern IntPtr avahi_client_get_host_name_fqdn (IntPtr handle);
76 [DllImport ("avahi-client")]
77 private static extern ClientState avahi_client_get_state (IntPtr handle);
79 [DllImport ("avahi-client")]
80 private static extern int avahi_client_errno (IntPtr handle);
82 [DllImport ("avahi-glib")]
83 private static extern IntPtr avahi_glib_poll_new (IntPtr context, int priority);
85 [DllImport ("avahi-glib")]
86 private static extern IntPtr avahi_glib_poll_get (IntPtr gpoll);
88 internal IntPtr Handle
90 get { return handle; }
95 get { return Utility.PtrToString (avahi_client_get_version_string (handle)); }
98 public string HostName
100 get { return Utility.PtrToString (avahi_client_get_host_name (handle)); }
103 public string DomainName
105 get { return Utility.PtrToString (avahi_client_get_domain_name (handle)); }
108 public string HostNameFqdn
110 get { return Utility.PtrToString (avahi_client_get_host_name_fqdn (handle)); }
113 public ClientState State
115 get { return (ClientState) avahi_client_get_state (handle); }
118 internal int LastError
120 get { return avahi_client_errno (handle); }
125 IntPtr gpoll = avahi_glib_poll_new (IntPtr.Zero, 0);
126 IntPtr poll = avahi_glib_poll_get (gpoll);
129 handle = avahi_client_new (poll, OnClientCallback, IntPtr.Zero, out error);
131 throw new ClientException (error);
139 public void Dispose ()
141 if (handle != IntPtr.Zero) {
142 avahi_client_free (handle);
143 handle = IntPtr.Zero;
147 internal void CheckError ()
149 int error = LastError;
152 throw new ClientException (error);
155 private void OnClientCallback (IntPtr client, ClientState state, IntPtr userData)
157 Console.WriteLine ("Got new state: " + state);