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 | #include "tensorflow/c/tf_status.h" |
17 | |
18 | #include "tensorflow/c/tf_status_internal.h" |
19 | #include "tensorflow/core/platform/errors.h" |
20 | #include "tensorflow/core/platform/status.h" |
21 | |
22 | using ::tensorflow::Status; |
23 | using ::tensorflow::error::Code; |
24 | using ::tensorflow::errors::IOError; |
25 | |
26 | TF_Status* TF_NewStatus() { return new TF_Status; } |
27 | |
28 | void TF_DeleteStatus(TF_Status* s) { delete s; } |
29 | |
30 | void TF_SetStatus(TF_Status* s, TF_Code code, const char* msg) { |
31 | if (code == TF_OK) { |
32 | s->status = ::tensorflow::OkStatus(); |
33 | return; |
34 | } |
35 | s->status = Status(static_cast<Code>(code), tensorflow::StringPiece(msg)); |
36 | } |
37 | |
38 | void TF_SetPayload(TF_Status* s, const char* key, const char* value) { |
39 | s->status.SetPayload(key, value); |
40 | } |
41 | |
42 | void TF_SetStatusFromIOError(TF_Status* s, int error_code, |
43 | const char* context) { |
44 | // TODO(b/139060984): Handle windows when changing its filesystem |
45 | s->status = IOError(context, error_code); |
46 | } |
47 | |
48 | TF_Code TF_GetCode(const TF_Status* s) { |
49 | return static_cast<TF_Code>(s->status.code()); |
50 | } |
51 | |
52 | const char* TF_Message(const TF_Status* s) { |
53 | return s->status.error_message().c_str(); |
54 | } |
55 | |