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