1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of tlm (Tiny Login Manager)
6 * Copyright (C) 2014 Intel Corporation.
8 * Contact: Imran Zaman <imran.zaman@intel.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29 #include "tlm-error.h"
33 * @short_description: error definitions and utilities
36 * This file provides Tlm error definitions and utilities.
37 * When creating an error, use #TLM_ERROR for the error domain and errors
38 * from #TlmError for the error code.
41 * GError* err = g_error_new(TLM_ERROR, TLM_ERROR_INVALID_INPUT,
49 * This macro should be used when creating a #GError (for example with
55 * @TLM_ERROR_NONE: No error
56 * @TLM_ERROR_UNKNOWN: Catch-all for errors not distinguished by another error
58 * @TLM_ERROR_INTERNAL_SERVER: Server internal error
59 * @TLM_ERROR_PERMISSION_DENIED: Permission denied
60 * @TLM_ERROR_INVALID_INPUT: Invalid input
61 * @TLM_ERROR_SEAT_NOT_FOUND: Seat not found
62 * @TLM_ERROR_SESSION_CREATION_FAILURE: Session creation failed
63 * @TLM_ERROR_SESSION_ALREADY_EXISTS: Session already exists
64 * @TLM_ERROR_SESSION_NOT_VALID: session is not valid anymore
65 * @TLM_ERROR_SESSION_TERMINATION_FAILURE: Session termination failed
66 * @TLM_ERROR_DBUS_SERVER_START_FAILURE: dbus-server startup failed
67 * @TLM_ERROR_PAM_AUTH_FAILURE: PAM authentication failed
68 * @TLM_ERROR_DBUS_REQ_ABORTED: Dbus request aborted
69 * @TLM_ERROR_DBUS_REQ_NOT_SUPPORTED: Dbus request not supported
70 * @TLM_ERROR_DBUS_REQ_UNKNOWN: Dbus request failed with unknown error
71 * @TLM_ERROR_LAST_ERR: Placeholder to rearrange enumeration
73 * This enumeration provides a list of errors
79 * This macro defines the error domain for tlm.
81 #define TLM_ERROR_DOMAIN "tlm"
84 * TLM_GET_ERROR_FOR_ID:
85 * @code: A #TlmError specifying the error
86 * @message: Format string for the error message
87 * @...: parameters for the error string
89 * A helper macro that creates a #GError with the proper tlm domain
92 #define _ERROR_PREFIX "org.O1.Tlm.Error"
94 GDBusErrorEntry _tlm_errors[] =
96 {TLM_ERROR_UNKNOWN, _ERROR_PREFIX".Unknown"},
97 {TLM_ERROR_INTERNAL_SERVER, _ERROR_PREFIX".InternalServerError"},
98 {TLM_ERROR_PERMISSION_DENIED, _ERROR_PREFIX".PermissionDenied"},
100 {TLM_ERROR_INVALID_INPUT, _ERROR_PREFIX".InvalidInput"},
101 {TLM_ERROR_SEAT_NOT_FOUND, _ERROR_PREFIX".SeatNotFound"},
102 {TLM_ERROR_SESSION_CREATION_FAILURE,
103 _ERROR_PREFIX".SessionCreationFailure"},
104 {TLM_ERROR_SESSION_TERMINATION_FAILURE,
105 _ERROR_PREFIX".SessionTerminationFailure"},
106 {TLM_ERROR_SESSION_ALREADY_EXISTS, _ERROR_PREFIX".SessionAlreadyExists"},
107 {TLM_ERROR_SESSION_NOT_VALID, _ERROR_PREFIX".SessionNotValid"},
108 {TLM_ERROR_DBUS_SERVER_START_FAILURE,
109 _ERROR_PREFIX".DBusServerStartFailure"},
110 {TLM_ERROR_PAM_AUTH_FAILURE,
111 _ERROR_PREFIX".PamAuthFailure"},
112 {TLM_ERROR_DBUS_REQ_ABORTED, _ERROR_PREFIX".DBusRequestAborted"},
113 {TLM_ERROR_DBUS_REQ_NOT_SUPPORTED, _ERROR_PREFIX".DBusRequestNotSupported"},
114 {TLM_ERROR_DBUS_REQ_UNKNOWN, _ERROR_PREFIX".DBusRequestUknown"},
120 * Creates and returns a domain for Tlm errors.
122 * Returns: #GQuark for Tlm errors
125 tlm_error_quark (void)
127 static volatile gsize quark_volatile = 0;
129 g_dbus_error_register_error_domain (TLM_ERROR_DOMAIN,
132 G_N_ELEMENTS (_tlm_errors));
134 return (GQuark) quark_volatile;
138 * tlm_error_new_from_variant:
139 * @var: (transfer none): instance of #GVariant
141 * Converts the GVariant to GError.
143 * Returns: (transfer full): #GError object if successful, NULL otherwise.
146 tlm_error_new_from_variant (
149 GError *error = NULL;
158 g_variant_get (var, "(uis)", &domain, &code, &message);
159 error = g_error_new_literal (domain, code, message);
165 * tlm_error_to_variant:
166 * @error: (transfer none): instance of #GError
168 * Converts the GError to GVariant.
170 * Returns: (transfer full) #GVariant object if successful, NULL otherwise.
173 tlm_error_to_variant (
180 return g_variant_new ("(uis)", error->domain, error->code, error->message);