summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/main/java/org/mozilla/gecko/util/XPCOMError.jinja
blob: f704bbc77500c90c61327eb6d91afb962de200ed (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
/* -*- Mode: Java; c-basic-offset: 2; tab-width: 4; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko.util;

public final class XPCOMError {
  /** Check if the error code corresponds to a failure */
  public static boolean failed(long err) {
    return (err & 0x80000000L) != 0;
  }

  /** Check if the error code corresponds to a failure */
  public static boolean succeeded(long err) {
    return !failed(err);
  }

  /** Extract the error code part of the error message */
  public static int getErrorCode(long err) {
    return (int)(err & 0xffffL);
  }

  /** Extract the error module part of the error message */
  public static int getErrorModule(long err) {
    return (int)(((err >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fffL);
  }

  public static final int NS_ERROR_MODULE_BASE_OFFSET = {{ MODULE_BASE_OFFSET }};

{% for mod, val in modules %}
  public static final int NS_ERROR_MODULE_{{ mod }} = {{ val }};
{% endfor %}

{% for error, val in errors %}
  public static final long {{ error }} = 0x{{ "%X" % val }}L;
{% endfor %}
}