summaryrefslogtreecommitdiff
path: root/ytstenut/yts-error.c
blob: b5adaa481c0a3a0b0352ea92ecddc5cc3e4cc3d6 (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
96
97
98
99
100
101
102
103
104
/*
 * Copyright © 2011 Intel Corp.
 *
 * 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, see
 * <http://www.gnu.org/licenses/>.
 *
 * Authored by: Tomas Frydrych <tf@linux.intel.com>
 */
#include "config.h"

#include "yts-error.h"

/**
 * yts_error_get_code:
 * @error: #YtsError
 *
 * Retrives error code from #YtsError.
 *
 * Returns: the error code represented by this #YtsError.
 */
guint
yts_error_get_code (YtsError error)
{
  return (error & _YTS_ERROR_CODE_MASK);
}

/**
 * yts_error_get_atom:
 * @error: #YtsError
 *
 * Retrieves the atom identifying the origin of this error from #YtsError.
 *
 * Returns: the atom identifying the operation represented by this
 * #YtsError.
 */
guint
yts_error_get_atom (YtsError error)
{
  /* g_debug ("error %d, atom %d", */
  /*          (guint32)(error & _YTS_ERROR_CODE_MASK), */
  /*          ((guint32)error & _YTS_ERROR_ATOM_MASK) >> 16); */

  return ((guint32)error & _YTS_ERROR_ATOM_MASK) >> 16;
}

/**
 * yts_error_new_atom:
 *
 * Obtains a new atom for #YtsError; this function is intended for use by code
 * that generates #YtsError<!-- -->s. NB: the atom is in its canonical shape
 * and will have to be shifted left by 16 bits before it can be ored with an
 * error code.
 *
 * Returns: a new atom for use with #YtsError.
 */
guint32
yts_error_new_atom ()
{
  static guint32 atom = 0;

  if (++atom > _YTS_ERROR_CODE_MASK)
    {
      g_warning ("Atom operation overflow, starting from beginning");
      atom = 1;
    }

  return atom;
}

/**
 * yts_error_make:
 * @atom: the error atom
 * @code: the error code
 *
 * Creates #YtsError from the provided values
 */
YtsError
yts_error_make (guint32 atom, guint32 code)
{
  return ((atom << 16) | code);
}

/**
 * yts_error_new:
 * @code: the error code
 *
 * Creates #YtsError with a new atom from the provide error code
 */
YtsError
yts_error_new (guint32 code)
{
  return ((yts_error_new_atom () << 16) | code);
}