1/* $Id$ */
2
3/***
4  This file is part of avahi.
5
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.
10
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.
15
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
19  USA.
20***/
21
22
23using System;
24using System.Runtime.InteropServices;
25
26namespace Avahi
27{
28    public enum ErrorCode {
29        Ok = 0,
30        Failure = -1,
31        BadState = -2,
32        InvalidHostName = - 3,
33        InvalidDomainName = -4,
34        NoNetwork = -5,
35        InvalidTTL = -6,
36        IsPattern = -7,
37        Collision = -8,
38        InvalidRecord = -9,
39        InvalidServiceName = -10,
40        InvalidServiceType = -11,
41        InvalidPort = -12,
42        InvalidKey = -13,
43        InvalidAddress = -14,
44        Timeout = -15,
45        TooManyClients = -16,
46        TooManyObjects = -17,
47        TooManyEntries = -18,
48        OS = -19,
49        AccessDenied = -20,
50        InvalidOperation = -21,
51        DBusError = -22,
52        Disconnected = -23,
53        NoMemory = -24,
54        InvalidObject = -25,
55        NoDaemon = -26,
56        InvalidInterface = -27,
57        InvalidProtocol = -28,
58        InvalidFlags = -29,
59        NotFound = -30,
60        InvalidConfig = -31,
61        VersionMismatch = -32,
62        InvalidServiceSubtype = -33,
63        InvalidPacket = -34,
64        InvalidDnsError = -35,
65        DnsFormErr = -36,
66        DnsServFail = -37,
67        DnsNxDomain = -38,
68        DnsNoTimp = -39,
69        DnsRefused = -40,
70        DnsYxDomain = -41,
71        DnsYxRrSet = -42,
72        DnsNxRrSet = -43,
73        DnsNotAuth = -44,
74        DnsNotZone = -45,
75        InvalidRData = -46,
76        InvalidDnsClass = -47,
77        InvalidDnsType = -48,
78        NotSupported = -49,
79        NotPermitted = -50
80    }
81
82    public delegate void ErrorCodeHandler (object o, ErrorCodeArgs args);
83
84    public class ErrorCodeArgs : EventArgs
85    {
86        private ErrorCode code;
87
88        public ErrorCode ErrorCode
89        {
90            get { return code; }
91        }
92
93        public ErrorCodeArgs (ErrorCode code)
94        {
95            this.code = code;
96        }
97    }
98
99    public class ClientException : ApplicationException
100    {
101        private ErrorCode code;
102
103        [DllImport ("avahi-common")]
104        private static extern IntPtr avahi_strerror (ErrorCode code);
105
106        public ErrorCode ErrorCode
107        {
108            get { return code; }
109        }
110
111        internal ClientException (int code) : this ((ErrorCode) code) {
112        }
113
114        internal ClientException (ErrorCode code) : base (GetErrorString (code))
115        {
116            this.code = code;
117        }
118
119        private static string GetErrorString (ErrorCode code)
120        {
121            IntPtr str = avahi_strerror (code);
122            return Utility.PtrToString (str);
123        }
124    }
125}
126