First tlm release
[platform/core/system/tlm.git] / src / common / tlm-error.c
1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /*
4  * This file is part of tlm (Tizen Login Manager)
5  *
6  * Copyright (C) 2014 Intel Corporation.
7  *
8  * Contact: Imran Zaman <imran.zaman@intel.com>
9  *
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.
14  *
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.
19  *
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
23  * 02110-1301 USA
24  */
25
26 #include <string.h>
27 #include <gio/gio.h>
28
29 #include "tlm-error.h"
30
31 /**
32  * SECTION:tlm-error
33  * @short_description: error definitions and utilities
34  * @title: Errors
35  *
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.
39  *
40  * |[
41  *     GError* err = g_error_new(TLM_ERROR, TLM_ERROR_INVALID_INPUT,
42  *     "Invalid input");
43  * ]|
44  */
45
46 /**
47  * TLM_ERROR:
48  *
49  * This macro should be used when creating a #GError (for example with
50  * g_error_new()).
51  */
52
53 /**
54  * TlmError:
55  * @TLM_ERROR_NONE: No error
56  * @TLM_ERROR_UNKNOWN: Catch-all for errors not distinguished by another error
57  * code
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_DBUS_SERVER_START_FAILURE: dbus-server startup failed
66  * @TLM_ERROR_DBUS_REQ_ABORTED: Dbus request aborted
67  * @TLM_ERROR_DBUS_REQ_NOT_SUPPORTED: Dbus request not supported
68  * @TLM_ERROR_DBUS_REQ_UNKNOWN: Dbus request failed with unknown error
69  * @TLM_ERROR_LAST_ERR: Placeholder to rearrange enumeration
70  *
71  * This enumeration provides a list of errors
72  */
73
74 /**
75  * TLM_ERROR_DOMAIN:
76  *
77  * This macro defines the error domain for tlm.
78  */
79 #define TLM_ERROR_DOMAIN "tlm"
80
81 /**
82  * TLM_GET_ERROR_FOR_ID:
83  * @code: A #TlmError specifying the error
84  * @message: Format string for the error message
85  * @...: parameters for the error string
86  *
87  * A helper macro that creates a #GError with the proper tlm domain
88  */
89
90 #define _ERROR_PREFIX "org.tizen.Tlm.Error"
91
92 GDBusErrorEntry _tlm_errors[] =
93 {
94     {TLM_ERROR_UNKNOWN, _ERROR_PREFIX".Unknown"},
95     {TLM_ERROR_INTERNAL_SERVER, _ERROR_PREFIX".InternalServerError"},
96     {TLM_ERROR_PERMISSION_DENIED, _ERROR_PREFIX".PermissionDenied"},
97
98     {TLM_ERROR_INVALID_INPUT, _ERROR_PREFIX".InvalidInput"},
99     {TLM_ERROR_SEAT_NOT_FOUND, _ERROR_PREFIX".SeatNotFound"},
100     {TLM_ERROR_SESSION_CREATION_FAILURE,
101             _ERROR_PREFIX".SessionCreationFailure"},
102     {TLM_ERROR_SESSION_ALREADY_EXISTS, _ERROR_PREFIX".SessionAlreadyExists"},
103     {TLM_ERROR_SESSION_NOT_VALID, _ERROR_PREFIX".SessionNotValid"},
104     {TLM_ERROR_DBUS_SERVER_START_FAILURE,
105             _ERROR_PREFIX".DBusServerStartFailure"},
106     {TLM_ERROR_DBUS_REQ_ABORTED, _ERROR_PREFIX".DBusRequestAborted"},
107     {TLM_ERROR_DBUS_REQ_NOT_SUPPORTED, _ERROR_PREFIX".DBusRequestNotSupported"},
108     {TLM_ERROR_DBUS_REQ_UNKNOWN, _ERROR_PREFIX".DBusRequestUknown"},
109 } ;
110
111  /**
112   * tlm_error_quark:
113   *
114   * Creates and returns a domain for Tlm errors.
115   *
116   * Returns: #GQuark for Tlm errors
117   */
118 GQuark
119 tlm_error_quark (void)
120 {
121     static volatile gsize quark_volatile = 0;
122
123     g_dbus_error_register_error_domain (TLM_ERROR_DOMAIN,
124                                         &quark_volatile,
125                                         _tlm_errors,
126                                         G_N_ELEMENTS (_tlm_errors));
127
128     return (GQuark) quark_volatile;
129 }