• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_C_TF_STATUS_H_
17 #define TENSORFLOW_C_TF_STATUS_H_
18 
19 #ifdef SWIG
20 #define TF_CAPI_EXPORT
21 #else
22 #if defined(_WIN32)
23 #ifdef TF_COMPILE_LIBRARY
24 #define TF_CAPI_EXPORT __declspec(dllexport)
25 #else
26 #define TF_CAPI_EXPORT __declspec(dllimport)
27 #endif  // TF_COMPILE_LIBRARY
28 #else
29 #define TF_CAPI_EXPORT __attribute__((visibility("default")))
30 #endif  // _WIN32
31 #endif  // SWIG
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 typedef struct TF_Status TF_Status;
38 
39 // --------------------------------------------------------------------------
40 // TF_Code holds an error code.  The enum values here are identical to
41 // corresponding values in error_codes.proto.
42 typedef enum TF_Code {
43   TF_OK = 0,
44   TF_CANCELLED = 1,
45   TF_UNKNOWN = 2,
46   TF_INVALID_ARGUMENT = 3,
47   TF_DEADLINE_EXCEEDED = 4,
48   TF_NOT_FOUND = 5,
49   TF_ALREADY_EXISTS = 6,
50   TF_PERMISSION_DENIED = 7,
51   TF_UNAUTHENTICATED = 16,
52   TF_RESOURCE_EXHAUSTED = 8,
53   TF_FAILED_PRECONDITION = 9,
54   TF_ABORTED = 10,
55   TF_OUT_OF_RANGE = 11,
56   TF_UNIMPLEMENTED = 12,
57   TF_INTERNAL = 13,
58   TF_UNAVAILABLE = 14,
59   TF_DATA_LOSS = 15,
60 } TF_Code;
61 
62 // --------------------------------------------------------------------------
63 
64 // Return a new status object.
65 TF_CAPI_EXPORT extern TF_Status* TF_NewStatus(void);
66 
67 // Delete a previously created status object.
68 TF_CAPI_EXPORT extern void TF_DeleteStatus(TF_Status*);
69 
70 // Record <code, msg> in *s.  Any previous information is lost.
71 // A common use is to clear a status: TF_SetStatus(s, TF_OK, "");
72 TF_CAPI_EXPORT extern void TF_SetStatus(TF_Status* s, TF_Code code,
73                                         const char* msg);
74 
75 // Convert from an I/O error code (e.g., errno) to a TF_Status value.
76 // Any previous information is lost. Prefer to use this instead of TF_SetStatus
77 // when the error comes from I/O operations.
78 TF_CAPI_EXPORT extern void TF_SetStatusFromIOError(TF_Status* s, int error_code,
79                                                    const char* context);
80 
81 // Return the code record in *s.
82 TF_CAPI_EXPORT extern TF_Code TF_GetCode(const TF_Status* s);
83 
84 // Return a pointer to the (null-terminated) error message in *s.  The
85 // return value points to memory that is only usable until the next
86 // mutation to *s.  Always returns an empty string if TF_GetCode(s) is
87 // TF_OK.
88 TF_CAPI_EXPORT extern const char* TF_Message(const TF_Status* s);
89 
90 #ifdef __cplusplus
91 } /* end extern "C" */
92 #endif
93 
94 #endif  // TENSORFLOW_C_TF_STATUS_H_
95