• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright 2016 Google Inc.
3   *
4   * Use of this source code is governed by a BSD-style license that can be
5   * found in the LICENSE file.
6   *
7   */
8  
9  //
10  //
11  //
12  
13  #include <stdlib.h>
14  #include <stdio.h>
15  
16  //
17  //
18  //
19  
20  #include "assert_skc.h"
21  
22  //
23  //
24  //
25  
26  #define SKC_ERR_TO_STR(err) case err: return #err
27  
28  //
29  //
30  //
31  
32  char const *
33  skc_get_error_string(skc_err const err)
34  {
35    switch(err)
36      {
37        SKC_ERR_TO_STR(SKC_ERR_SUCCESS);
38        SKC_ERR_TO_STR(SKC_ERR_NOT_IMPLEMENTED);
39        SKC_ERR_TO_STR(SKC_ERR_POOL_EMPTY);
40        SKC_ERR_TO_STR(SKC_ERR_CONDVAR_WAIT);
41        SKC_ERR_TO_STR(SKC_ERR_LAYER_ID_INVALID);
42        SKC_ERR_TO_STR(SKC_ERR_LAYER_NOT_EMPTY);
43        SKC_ERR_TO_STR(SKC_ERR_TRANSFORM_WEAKREF_INVALID);
44        SKC_ERR_TO_STR(SKC_ERR_STROKE_STYLE_WEAKREF_INVALID);
45        SKC_ERR_TO_STR(SKC_ERR_COMMAND_NOT_READY);
46        SKC_ERR_TO_STR(SKC_ERR_COMMAND_NOT_COMPLETED);
47        SKC_ERR_TO_STR(SKC_ERR_COMMAND_NOT_STARTED);
48        SKC_ERR_TO_STR(SKC_ERR_COMMAND_NOT_READY_OR_COMPLETED);
49        SKC_ERR_TO_STR(SKC_ERR_COMPOSITION_SEALED);
50        SKC_ERR_TO_STR(SKC_ERR_STYLING_SEALED);
51        SKC_ERR_TO_STR(SKC_ERR_HANDLE_INVALID);
52        SKC_ERR_TO_STR(SKC_ERR_HANDLE_OVERFLOW);
53  
54      default:
55        return "UNKNOWN SKC ERROR CODE";
56      }
57  }
58  
59  //
60  //
61  //
62  
63  skc_err
64  assert_skc(skc_err const err, char const * const file, int const line, bool const abort)
65  {
66    if (err != SKC_ERR_SUCCESS)
67      {
68        char const * const skc_err_str = skc_get_error_string(err);
69  
70        fprintf(stderr,
71                "\"%s\", line %d: skc_assert (%d) = \"%s\"",
72                file,line,err,skc_err_str);
73  
74        if (abort)
75          {
76            // stop profiling and reset device here if necessary
77            exit(err);
78          }
79      }
80  
81    return err;
82  }
83  
84  //
85  //
86  //
87