• 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 enum {
38     OK                = 0,    // Preferred constant for checking success.
39 #ifndef NO_ERROR
40     // Win32 #defines NO_ERROR as well.  It has the same value, so there's no
41     // real conflict, though it's a bit awkward.
42     NO_ERROR          = OK,   // Deprecated synonym for `OK`. Prefer `OK` because it doesn't conflict with Windows.
43 #endif
44 
45     UNKNOWN_ERROR       = (-2147483647-1), // INT32_MIN value
46 
47     NO_MEMORY           = -ENOMEM,
48     INVALID_OPERATION   = -ENOSYS,
49     BAD_VALUE           = -EINVAL,
50     BAD_TYPE            = (UNKNOWN_ERROR + 1),
51     NAME_NOT_FOUND      = -ENOENT,
52     PERMISSION_DENIED   = -EPERM,
53     NO_INIT             = -ENODEV,
54     ALREADY_EXISTS      = -EEXIST,
55     DEAD_OBJECT         = -EPIPE,
56     FAILED_TRANSACTION  = (UNKNOWN_ERROR + 2),
57 #if !defined(_WIN32)
58     BAD_INDEX           = -EOVERFLOW,
59     NOT_ENOUGH_DATA     = -ENODATA,
60     WOULD_BLOCK         = -EWOULDBLOCK,
61     TIMED_OUT           = -ETIMEDOUT,
62     UNKNOWN_TRANSACTION = -EBADMSG,
63 #else
64     BAD_INDEX           = -E2BIG,
65     NOT_ENOUGH_DATA     = (UNKNOWN_ERROR + 3),
66     WOULD_BLOCK         = (UNKNOWN_ERROR + 4),
67     TIMED_OUT           = (UNKNOWN_ERROR + 5),
68     UNKNOWN_TRANSACTION = (UNKNOWN_ERROR + 6),
69 #endif
70     FDS_NOT_ALLOWED     = (UNKNOWN_ERROR + 7),
71     UNEXPECTED_NULL     = (UNKNOWN_ERROR + 8),
72 };
73 
74 // Human readable name of error
75 std::string statusToString(status_t status);
76 
77 }  // namespace android
78