• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <errno.h>
20 #include <stdint.h>
21 #include <sys/types.h>
22 #include <string>
23 
24 namespace android {
25 
26 /**
27  * The type used to return success/failure from frameworks APIs.
28  * See the anonymous enum below for valid values.
29  */
30 typedef int32_t status_t;
31 
32 /*
33  * Error codes.
34  * All error codes are negative values.
35  */
36 
37 // Win32 #defines NO_ERROR as well.  It has the same value, so there's no
38 // real conflict, though it's a bit awkward.
39 #ifdef _WIN32
40 # undef NO_ERROR
41 #endif
42 
43 enum {
44     OK                = 0,    // Preferred constant for checking success.
45     NO_ERROR          = OK,   // Deprecated synonym for `OK`. Prefer `OK` because it doesn't conflict with Windows.
46 
47     UNKNOWN_ERROR       = (-2147483647-1), // INT32_MIN value
48 
49     NO_MEMORY           = -ENOMEM,
50     INVALID_OPERATION   = -ENOSYS,
51     BAD_VALUE           = -EINVAL,
52     BAD_TYPE            = (UNKNOWN_ERROR + 1),
53     NAME_NOT_FOUND      = -ENOENT,
54     PERMISSION_DENIED   = -EPERM,
55     NO_INIT             = -ENODEV,
56     ALREADY_EXISTS      = -EEXIST,
57     DEAD_OBJECT         = -EPIPE,
58     FAILED_TRANSACTION  = (UNKNOWN_ERROR + 2),
59 #if !defined(_WIN32)
60     BAD_INDEX           = -EOVERFLOW,
61     NOT_ENOUGH_DATA     = -ENODATA,
62     WOULD_BLOCK         = -EWOULDBLOCK,
63     TIMED_OUT           = -ETIMEDOUT,
64     UNKNOWN_TRANSACTION = -EBADMSG,
65 #else
66     BAD_INDEX           = -E2BIG,
67     NOT_ENOUGH_DATA     = (UNKNOWN_ERROR + 3),
68     WOULD_BLOCK         = (UNKNOWN_ERROR + 4),
69     TIMED_OUT           = (UNKNOWN_ERROR + 5),
70     UNKNOWN_TRANSACTION = (UNKNOWN_ERROR + 6),
71 #endif
72     FDS_NOT_ALLOWED     = (UNKNOWN_ERROR + 7),
73     UNEXPECTED_NULL     = (UNKNOWN_ERROR + 8),
74 };
75 
76 // Human readable name of error
77 std::string statusToString(status_t status);
78 
79 // Restore define; enumeration is in "android" namespace, so the value defined
80 // there won't work for Win32 code in a different namespace.
81 #ifdef _WIN32
82 # define NO_ERROR 0L
83 #endif
84 
85 }  // namespace android
86