summaryrefslogtreecommitdiff
path: root/girepository/gierrordomaininfo.c
blob: 86e40c59b6f1c7c86db0c9eb785b6c311d63b2bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* GObject introspection: ErrorDomain implementation
 *
 * Copyright (C) 2005 Matthias Clasen
 * Copyright (C) 2008,2009 Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <glib.h>

#include <girepository.h>
#include "girepository-private.h"
#include "gitypelib-internal.h"

/**
 * SECTION:gierrordomaininfo
 * @Short_description: Struct representing an error domain
 * @Title: GIErrorDomainInfo
 *
 * A GIErrorDomainInfo struct represents a domain of a #GError.
 * An error domain is associated with a #GQuark and contains a pointer
 * to an enum with all the error codes.
 *
 * <refsect1 id="gi-gierrordomaininfo.struct-hierarchy" role="struct_hierarchy">
 * <title role="struct_hierarchy.title">Struct hierarchy</title>
 * <synopsis>
 *   <link linkend="gi-GIBaseInfo">GIBaseInfo</link>
 *    +----GIErrorDomainInfo
 * </synopsis>
 * </refsect1>
 */

/**
 * g_error_domain_info_get_quark:
 * @info: a #GIErrorDomainInfo
 *
 * Obtain a string representing the quark for this error domain.
 * %NULL will be returned if the type tag is wrong or if a quark is
 * missing in the typelib.
 *
 * Returns: the quark represented as a string or %NULL
 */
const gchar *
g_error_domain_info_get_quark (GIErrorDomainInfo *info)
{
  GIRealInfo *rinfo = (GIRealInfo *)info;
  ErrorDomainBlob *blob;

  g_return_val_if_fail (info != NULL, NULL);
  g_return_val_if_fail (GI_IS_ERROR_DOMAIN_INFO (info), NULL);

  blob = (ErrorDomainBlob *)&rinfo->typelib->data[rinfo->offset];

  return g_typelib_get_string (rinfo->typelib, blob->get_quark);
}

/**
 * g_error_domain_info_get_codes:
 * @info: a #GIErrorDomainInfo
 *
 * Obtain the enum containing all the error codes for this error domain.
 * The return value will have a #GIInfoType of %GI_INFO_TYPE_ERROR_DOMAIN
 *
 * Returns: (transfer full): the error domain or %NULL if type tag is wrong,
 * free the struct with g_base_info_unref() when done.
 */
GIInterfaceInfo *
g_error_domain_info_get_codes (GIErrorDomainInfo *info)
{
  GIRealInfo *rinfo = (GIRealInfo *)info;
  ErrorDomainBlob *blob;

  g_return_val_if_fail (info != NULL, NULL);
  g_return_val_if_fail (GI_IS_ERROR_DOMAIN_INFO (info), NULL);

  blob = (ErrorDomainBlob *)&rinfo->typelib->data[rinfo->offset];

  return (GIInterfaceInfo *) _g_info_from_entry (rinfo->repository,
                                                 rinfo->typelib, blob->error_codes);
}