dbus-errors.c revision 4a85d321b4516c6a663e8bdd530ba59018c974df
1/* -*- mode: C; c-file-style: "gnu" -*- */
2/* dbus-errors.c Error reporting
3 *
4 * Copyright (C) 2002  Red Hat Inc.
5 *
6 * Licensed under the Academic Free License version 1.2
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 *
22 */
23#include "dbus-errors.h"
24
25/**
26 * @defgroup DBusErrors Error reporting
27 * @ingroup  DBus
28 * @brief Error reporting
29 *
30 * Types and functions related to reporting errors.
31 *
32 *
33 * In essence D-BUS error reporting works as follows:
34 *
35 * @code
36 * DBusResultCode result = DBUS_RESULT_SUCCESS;
37 * dbus_some_function (arg1, arg2, &result);
38 * if (result != DBUS_RESULT_SUCCESS)
39 *   printf ("an error occurred\n");
40 * @endcode
41 *
42 * @{
43 */
44
45/**
46 * Set a result code at a result code location,
47 * if code_address is not #NULL.
48 *
49 * @param code_address place to store the result code.
50 * @param code the result code itself.
51 */
52void
53dbus_set_result (DBusResultCode *code_address,
54                 DBusResultCode  code)
55{
56  if (code_address)
57    *code_address = code;
58}
59
60/**
61 * Returns a string describing the given result code.
62 *
63 * @param code the result code to describe.
64 * @returns a constant string describing the code.
65 */
66const char*
67dbus_result_to_string (DBusResultCode code)
68{
69  /* This is a switch to the compiler will complain if we
70   * aren't handling some codes
71   */
72  switch (code)
73    {
74    case DBUS_RESULT_SUCCESS:
75      return "Success";
76    case DBUS_RESULT_FAILED:
77      return "Unknown error";
78    case DBUS_RESULT_NO_MEMORY:
79      return "Not enough memory available";
80    case DBUS_RESULT_IO_ERROR:
81      return "Error reading or writing data";
82    case DBUS_RESULT_BAD_ADDRESS:
83      return "Could not parse address";
84    case DBUS_RESULT_NOT_SUPPORTED:
85      return "Feature not supported";
86    case DBUS_RESULT_LIMITS_EXCEEDED:
87      return "Resource limits exceeded";
88    case DBUS_RESULT_ACCESS_DENIED:
89      return "Permission denied";
90    case DBUS_RESULT_AUTH_FAILED:
91      return "Could not authenticate to server";
92    case DBUS_RESULT_NO_SERVER:
93      return "No server";
94    case DBUS_RESULT_TIMEOUT:
95      return "Connection timed out";
96    case DBUS_RESULT_NO_NETWORK:
97      return "Network unavailable";
98    case DBUS_RESULT_ADDRESS_IN_USE:
99      return "Address already in use";
100    case DBUS_RESULT_DISCONNECTED:
101      return "Disconnected.";
102    case DBUS_RESULT_INVALID_FIELDS:
103      return "Invalid fields.";
104    case DBUS_RESULT_NO_REPLY:
105      return "Did not get a reply message.";
106
107      /* no default, it would break our compiler warnings */
108    }
109
110  return "Invalid error code";
111}
112
113/** @} */
114