3
* Copyright © 2009 Scott James Remnant <scott@netsplit.com>.
4
* Copyright © 2009 Canonical Ltd.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2, as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
#ifndef NIH_DBUS_ERROR_H
21
#define NIH_DBUS_ERROR_H
24
* Errors in libnih are raised by placing an NihError object in a local
25
* variable that can be retrieved using nih_error_get(). Errors in libdbus
26
* are returned on the stack by passing the address of a DBusError object
27
* when calling functions.
29
* This module allows the two techniques to be bridged.
31
* When calling a libnih function, or writing a handler called by such
32
* a function, you may use nih_dbus_error_raise() or
33
* nih_dbus_error_raise_printf(). This may be retrieved by nih_error_get(),
34
* and the handler poll function will do so and convert this into a D-Bus
35
* error message if appropriate.
39
* nih_dbus_error_raise (DBUS_ERROR_INVALID_ARGS, "Expected Int32");
42
* When calling a libdbus function you should initialise a DBusError with
43
* dbus_error_init() and pass its address to your function call. Should
44
* an error be returned, you can raise that so it can be retrieved by
45
* nih_error_get() by passing the name and message members to
46
* nih_dbus_error_raise().
50
* dbus_error_init (&dbus_err);
51
* if (! dbus_connection_open (address, &dbus_err)) {
52
* nih_dbus_error_raise (dbus_err.name, dbus_err.message);
53
* dbus_error_free (&dbus_err);
58
* In both cases, the error variable returned by nih_error_get() is not
59
* actually NihError but NihDBusError. This extends the original structure
60
* to add a "name" member containing the D-Bus error name. The error
61
* number for all such errors is NIH_DBUS_ERROR.
63
* The nih_dbus_message_error() function defined in nih-dbus/dbus_message.h
64
* allows you to send either type of error as a D-Bus error message.
67
#include <nih/macros.h>
68
#include <nih/error.h>
75
* This structure builds on NihError to include an additional @name field
76
* required for transport across D-Bus.
78
* If you receive a NIH_DBUS_ERROR, the returned NihError structure is
79
* actually this structure and can be cast to get the additional fields.
81
typedef struct nih_dbus_error {
89
void nih_dbus_error_raise (const char *name, const char *message);
91
void nih_dbus_error_raise_printf (const char *name, const char *format, ...)
92
__attribute__ ((format (printf, 2, 3)));
96
#endif /* NIH_DBUS_ERROR_H */