]> git.meshlink.io Git - catta/blob - avahi-sharp/AvahiTest.cs
integrate mono bindings into the build
[catta] / avahi-sharp / AvahiTest.cs
1 /***
2   This file is part of avahi.
3
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.
8
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.
13
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
17   USA.
18 ***/
19
20 using System;
21 using System.Net;
22 using Gtk;
23 using Avahi;
24
25 public class AvahiTest {
26         private static Client client;
27
28         public static void Main () {
29                 client = new Client ();
30
31                 EntryGroup eg = new EntryGroup (client);
32                 eg.StateChanged += OnEntryGroupChanged;
33                 eg.AddService ("foobar2", "_daap._tcp", client.DomainName,
34                                444, new string[] { "foo", "bar", "baz" });
35                 eg.Commit ();
36
37                 Application.Run ();
38         }
39
40         private static void OnEntryGroupChanged (object o, EntryGroupState state)
41         {
42                 Console.WriteLine ("Entry group status: " + state);
43
44                 if (state == EntryGroupState.Established) {
45                         DomainBrowser browser = new DomainBrowser (client);
46                         browser.DomainAdded += OnDomainAdded;
47                 }
48         }
49
50         private static void OnDomainAdded (object o, DomainInfo info)
51         {
52                 Console.WriteLine ("Got domain added: " + info.Domain);
53                 ServiceTypeBrowser stb = new ServiceTypeBrowser (client, info.Domain);
54                 stb.ServiceTypeAdded += OnServiceTypeAdded;
55         }
56
57         private static void OnServiceTypeAdded (object o, ServiceTypeInfo info)
58         {
59                 Console.WriteLine ("Got service type: " + info.ServiceType);
60                 ServiceBrowser sb = new ServiceBrowser (client, info.ServiceType, info.Domain);
61                 sb.ServiceAdded += OnServiceAdded;
62         }
63
64         private static void OnServiceAdded (object o, ServiceInfo info)
65         {
66                 // Console.WriteLine ("Got service: " + info.Name);
67                 ServiceResolver resolver = new ServiceResolver (client, info);
68                 resolver.Found += OnServiceResolved;
69         }
70
71         private static void OnServiceResolved (object o, ServiceInfo info)
72         {
73                 Console.WriteLine ("Service '{0}' at {1}:{2}", info.Name, info.Host, info.Port);
74                 AddressResolver ar = new AddressResolver (client, info.Address);
75                 ar.Found += OnAddressResolved;
76         }
77
78         private static void OnAddressResolved (object o, string host, IPAddress address)
79         {
80                 Console.WriteLine ("Resolved {0} to {1}", address, host);
81                 HostNameResolver hr = new HostNameResolver (client, host);
82                 hr.Found += OnHostNameResolved;
83         }
84
85         private static void OnHostNameResolved (object o, string host, IPAddress address)
86         {
87                 Console.WriteLine ("Resolved {0} to {1}", host, address);
88         }
89 }