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 ClientHandler (IntPtr client, ClientState state, IntPtr userData);
41 public enum Protocol {
47 public enum ClientState {
55 public class Client : IDisposable
57 private IntPtr handle;
59 [DllImport ("avahi-client")]
60 private static extern IntPtr avahi_client_new (IntPtr poll, ClientHandler handler,
61 IntPtr userData, out int error);
63 [DllImport ("avahi-client")]
64 private static extern void avahi_client_free (IntPtr handle);
66 [DllImport ("avahi-client")]
67 private static extern IntPtr avahi_client_get_version_string (IntPtr handle);
69 [DllImport ("avahi-client")]
70 private static extern IntPtr avahi_client_get_host_name (IntPtr handle);
72 [DllImport ("avahi-client")]
73 private static extern IntPtr avahi_client_get_domain_name (IntPtr handle);
75 [DllImport ("avahi-client")]
76 private static extern IntPtr avahi_client_get_host_name_fqdn (IntPtr handle);
78 [DllImport ("avahi-client")]
79 private static extern ClientState avahi_client_get_state (IntPtr handle);
81 [DllImport ("avahi-client")]
82 private static extern int avahi_client_errno (IntPtr handle);
84 [DllImport ("avahi-glib")]
85 private static extern IntPtr avahi_glib_poll_new (IntPtr context, int priority);
87 [DllImport ("avahi-glib")]
88 private static extern IntPtr avahi_glib_poll_get (IntPtr gpoll);
90 internal IntPtr Handle
92 get { return handle; }
97 get { return Utility.PtrToString (avahi_client_get_version_string (handle)); }
100 public string HostName
102 get { return Utility.PtrToString (avahi_client_get_host_name (handle)); }
105 public string DomainName
107 get { return Utility.PtrToString (avahi_client_get_domain_name (handle)); }
110 public string HostNameFqdn
112 get { return Utility.PtrToString (avahi_client_get_host_name_fqdn (handle)); }
115 public ClientState State
117 get { return (ClientState) avahi_client_get_state (handle); }
120 internal int LastError
122 get { return avahi_client_errno (handle); }
127 IntPtr gpoll = avahi_glib_poll_new (IntPtr.Zero, 0);
128 IntPtr poll = avahi_glib_poll_get (gpoll);
131 handle = avahi_client_new (poll, OnClientCallback, IntPtr.Zero, out error);
133 throw new ClientException (error);
141 public void Dispose ()
143 if (handle != IntPtr.Zero) {
144 avahi_client_free (handle);
145 handle = IntPtr.Zero;
149 internal void CheckError ()
151 int error = LastError;
154 throw new ClientException (error);
157 private void OnClientCallback (IntPtr client, ClientState state, IntPtr userData)
159 Console.WriteLine ("Got new state: " + state);