~elementary-os/ubuntu-package-imports/mutter-bionic

« back to all changes in this revision

Viewing changes to cogl/cogl/cogl-error.h

  • Committer: RabbitBot
  • Date: 2018-04-11 14:49:36 UTC
  • Revision ID: rabbitbot@elementary.io-20180411144936-hgymqa9d8d1xfpbh
Initial import, version 3.28.0-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Cogl
 
3
 *
 
4
 * A Low Level GPU Graphics and Utilities API
 
5
 *
 
6
 * Copyright (C) 2012 Intel Corporation.
 
7
 *
 
8
 * Permission is hereby granted, free of charge, to any person
 
9
 * obtaining a copy of this software and associated documentation
 
10
 * files (the "Software"), to deal in the Software without
 
11
 * restriction, including without limitation the rights to use, copy,
 
12
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 
13
 * of the Software, and to permit persons to whom the Software is
 
14
 * furnished to do so, subject to the following conditions:
 
15
 *
 
16
 * The above copyright notice and this permission notice shall be
 
17
 * included in all copies or substantial portions of the Software.
 
18
 *
 
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
20
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
21
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
22
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
23
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
24
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
25
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
26
 * SOFTWARE.
 
27
 */
 
28
 
 
29
#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
 
30
#error "Only <cogl/cogl.h> can be included directly."
 
31
#endif
 
32
 
 
33
#ifndef __COGL_ERROR_H__
 
34
#define __COGL_ERROR_H__
 
35
 
 
36
#include "cogl-types.h"
 
37
 
 
38
COGL_BEGIN_DECLS
 
39
 
 
40
/**
 
41
 * SECTION:cogl-error
 
42
 * @short_description: A way for Cogl to throw exceptions
 
43
 *
 
44
 * As a general rule Cogl shields non-recoverable errors from
 
45
 * developers, such as most heap allocation failures (unless for
 
46
 * exceptionally large resources which we might reasonably expect to
 
47
 * fail) and this reduces the burden on developers.
 
48
 *
 
49
 * There are some Cogl apis though that can fail for exceptional
 
50
 * reasons that can also potentially be recovered from at runtime
 
51
 * and for these apis we use a standard convention for reporting
 
52
 * runtime recoverable errors.
 
53
 *
 
54
 * As an example if we look at the cogl_context_new() api which
 
55
 * takes an error argument:
 
56
 * |[
 
57
 *   CoglContext *
 
58
 *   cogl_context_new (CoglDisplay *display, CoglError **error);
 
59
 * ]|
 
60
 *
 
61
 * A caller interested in catching any runtime error when creating a
 
62
 * new #CoglContext would pass the address of a #CoglError pointer
 
63
 * that has first been initialized to %NULL as follows:
 
64
 *
 
65
 * |[
 
66
 *   CoglError *error = NULL;
 
67
 *   CoglContext *context;
 
68
 *
 
69
 *   context = cogl_context_new (NULL, &error);
 
70
 * ]|
 
71
 *
 
72
 * The return status should usually be enough to determine if there
 
73
 * was an error set (in this example we can check if context == %NULL)
 
74
 * but if it's not possible to tell from the function's return status
 
75
 * you can instead look directly at the error pointer which you
 
76
 * initialized to %NULL. In this example we now check the error,
 
77
 * report any error to the user, free the error and then simply
 
78
 * abort without attempting to recover.
 
79
 *
 
80
 * |[
 
81
 *   if (context == NULL)
 
82
 *     {
 
83
 *       fprintf (stderr, "Failed to create a Cogl context: %s\n",
 
84
 *                error->message);
 
85
 *       cogl_error_free (error);
 
86
 *       abort ();
 
87
 *     }
 
88
 * ]|
 
89
 *
 
90
 * All Cogl APIs that accept an error argument can also be passed a
 
91
 * %NULL pointer. In this case if an exceptional error condition is hit
 
92
 * then Cogl will simply log the error message and abort the
 
93
 * application. This can be compared to language execeptions where the
 
94
 * developer has not attempted to catch the exception. This means the
 
95
 * above example is essentially redundant because it's what Cogl would
 
96
 * have done automatically and so, similarly, if your application has
 
97
 * no way to recover from a particular error you might just as well
 
98
 * pass a %NULL #CoglError pointer to save a bit of typing.
 
99
 *
 
100
 * <note>If you are used to using the GLib API you will probably
 
101
 * recognize that #CoglError is just like a #GError. In fact if Cogl
 
102
 * has been built with --enable-glib then it is safe to cast a
 
103
 * #CoglError to a #GError.</note>
 
104
 *
 
105
 * <note>An important detail to be aware of if you are used to using
 
106
 * GLib's GError API is that Cogl deviates from the GLib GError
 
107
 * conventions in one noteable way which is that a %NULL error pointer
 
108
 * does not mean you want to ignore the details of an error, it means
 
109
 * you are not trying to catch any exceptional errors the function might
 
110
 * throw which will result in the program aborting with a log message
 
111
 * if an error is thrown.</note>
 
112
 */
 
113
 
 
114
#define CoglError GError
 
115
 
 
116
/**
 
117
 * cogl_error_free:
 
118
 * @error: A #CoglError thrown by the Cogl api
 
119
 *
 
120
 * Frees a #CoglError and associated resources.
 
121
 */
 
122
void
 
123
cogl_error_free (CoglError *error);
 
124
 
 
125
/**
 
126
 * cogl_error_copy:
 
127
 * @error: A #CoglError thrown by the Cogl api
 
128
 *
 
129
 * Makes a copy of @error which can later be freed using
 
130
 * cogl_error_free().
 
131
 *
 
132
 * Return value: A newly allocated #CoglError initialized to match the
 
133
 *               contents of @error.
 
134
 */
 
135
CoglError *
 
136
cogl_error_copy (CoglError *error);
 
137
 
 
138
/**
 
139
 * cogl_error_matches:
 
140
 * @error: A #CoglError thrown by the Cogl api or %NULL
 
141
 * @domain: The error domain
 
142
 * @code: The error code
 
143
 *
 
144
 * Returns %TRUE if error matches @domain and @code, %FALSE otherwise.
 
145
 * In particular, when error is %NULL, FALSE will be returned.
 
146
 *
 
147
 * Return value: whether the @error corresponds to the given @domain
 
148
 *               and @code.
 
149
 */
 
150
CoglBool
 
151
cogl_error_matches (CoglError *error,
 
152
                    uint32_t domain,
 
153
                    int code);
 
154
 
 
155
/**
 
156
 * COGL_GLIB_ERROR:
 
157
 * @COGL_ERROR: A #CoglError thrown by the Cogl api or %NULL
 
158
 *
 
159
 * Simply casts a #CoglError to a #CoglError
 
160
 *
 
161
 * If Cogl is built with GLib support then it can safely be assumed
 
162
 * that a CoglError is a GError and can be used directly with the
 
163
 * GError api.
 
164
 */
 
165
#define COGL_GLIB_ERROR(COGL_ERROR) ((CoglError *)COGL_ERROR)
 
166
 
 
167
COGL_END_DECLS
 
168
 
 
169
#endif /* __COGL_ERROR_H__ */