1 // Copyright 2020 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://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, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #include "pw_status/status.h" 16 17 #define PW_CASE_RETURN_ENUM_STRING(value) \ 18 case PW_STATUS_##value: \ 19 return #value 20 pw_StatusString(pw_Status status)21extern "C" const char* pw_StatusString(pw_Status status) { 22 switch (status) { 23 PW_CASE_RETURN_ENUM_STRING(OK); 24 PW_CASE_RETURN_ENUM_STRING(CANCELLED); 25 PW_CASE_RETURN_ENUM_STRING(UNKNOWN); 26 PW_CASE_RETURN_ENUM_STRING(INVALID_ARGUMENT); 27 PW_CASE_RETURN_ENUM_STRING(DEADLINE_EXCEEDED); 28 PW_CASE_RETURN_ENUM_STRING(NOT_FOUND); 29 PW_CASE_RETURN_ENUM_STRING(ALREADY_EXISTS); 30 PW_CASE_RETURN_ENUM_STRING(PERMISSION_DENIED); 31 PW_CASE_RETURN_ENUM_STRING(RESOURCE_EXHAUSTED); 32 PW_CASE_RETURN_ENUM_STRING(FAILED_PRECONDITION); 33 PW_CASE_RETURN_ENUM_STRING(ABORTED); 34 PW_CASE_RETURN_ENUM_STRING(OUT_OF_RANGE); 35 PW_CASE_RETURN_ENUM_STRING(UNIMPLEMENTED); 36 PW_CASE_RETURN_ENUM_STRING(INTERNAL); 37 PW_CASE_RETURN_ENUM_STRING(UNAVAILABLE); 38 PW_CASE_RETURN_ENUM_STRING(DATA_LOSS); 39 PW_CASE_RETURN_ENUM_STRING(UNAUTHENTICATED); 40 case PW_STATUS_DO_NOT_USE_RESERVED_FOR_FUTURE_EXPANSION_USE_DEFAULT_IN_SWITCH_INSTEAD_: 41 default: 42 return "INVALID STATUS"; 43 } 44 } 45 46 #undef PW_CASE_RETURN_ENUM_STRING 47