• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2021 Huawei Device Co., Ltd.
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 HISTREAMER_FOUNDATION_ERROR_CODE_H
17 #define HISTREAMER_FOUNDATION_ERROR_CODE_H
18 
19 #include <cstdint>
20 
21 #ifdef WIN32
22 // Fix compile error: expected identifier before numeric constant
23 // also can add in plugin_loader.cpp before include log.h
24 #undef ERROR_INVALID_OPERATION
25 #undef ERROR_INVALID_STATE
26 #endif
27 
28 namespace OHOS {
29 namespace Media {
30 enum struct ErrorCode : int32_t {
31     END_OF_STREAM = 1,
32     SUCCESS = 0,
33     ERROR_UNKNOWN = INT32_MIN + 0,
34     ERROR_UNIMPLEMENTED = ERROR_UNKNOWN + 1,
35     ERROR_AGAIN = ERROR_UNKNOWN + 2,
36     ERROR_INVALID_PARAMETER_VALUE = ERROR_UNKNOWN + 3,
37     ERROR_INVALID_PARAMETER_TYPE = ERROR_UNKNOWN + 4,
38     ERROR_INVALID_OPERATION = ERROR_UNKNOWN + 5,
39     ERROR_UNSUPPORTED_FORMAT = ERROR_UNKNOWN + 6,
40     ERROR_NOT_EXISTED = ERROR_UNKNOWN + 7,
41     ERROR_TIMED_OUT = ERROR_UNKNOWN + 8,
42     ERROR_NO_MEMORY = ERROR_UNKNOWN + 9,
43     ERROR_INVALID_STATE = ERROR_UNKNOWN + 10,
44     ERROR_PERMISSION_DENIED = ERROR_UNKNOWN + 11,
45     ERROR_NO_NOTIFY = ERROR_UNKNOWN + 12,
46 };
47 
48 const char* GetErrorName(ErrorCode code);
49 
50 #ifndef FAIL_RETURN
51 #define FAIL_RETURN(exec)                                                                                              \
52     do {                                                                                                               \
53         ErrorCode returnValue = (exec);                                                                                \
54         if (returnValue != ErrorCode::SUCCESS) {                                                                       \
55             MEDIA_LOG_E("FAIL_RETURN on ErrorCode(" PUBLIC_LOG_S ").", GetErrorName(returnValue));                     \
56             return returnValue;                                                                                        \
57         }                                                                                                              \
58     } while (0)
59 #endif
60 
61 #ifndef FAIL_RETURN_MSG_IMPL
62 #define FAIL_RETURN_MSG_IMPL(loglevel, exec, fmt, args...)                                                             \
63     do {                                                                                                               \
64         ErrorCode returnValue = (exec);                                                                                \
65         if (returnValue != ErrorCode::SUCCESS) {                                                                       \
66             loglevel(fmt, ##args);                                                                                     \
67             return returnValue;                                                                                        \
68         }                                                                                                              \
69     } while (0)
70 #endif
71 
72 #ifndef FAIL_RETURN_MSG
73 #define FAIL_RETURN_MSG(exec, fmt, args...) FAIL_RETURN_MSG_IMPL(MEDIA_LOG_E, exec, fmt, ##args)
74 #endif
75 
76 #ifndef FAIL_RETURN_MSG_W
77 #define FAIL_RETURN_MSG_W(exec, fmt, args...) FAIL_RETURN_MSG_IMPL(MEDIA_LOG_W, exec, fmt, ##args)
78 #endif
79 
80 #ifndef FAIL_LOG
81 #define FAIL_LOG(exec)                                                                                                 \
82     do {                                                                                                               \
83         ErrorCode returnValue = (exec);                                                                                \
84         if (returnValue != ErrorCode::SUCCESS) {                                                                       \
85             MEDIA_LOG_E("FAIL_LOG on ErrorCode(" PUBLIC_LOG_S ").", GetErrorName(returnValue));                        \
86         }                                                                                                              \
87     } while (0)
88 #endif
89 
90 #ifndef FAIL_LOG_MSG_IMPL
91 #define FAIL_LOG_MSG_IMPL(loglevel, exec, fmt, args...)                                                                \
92     do {                                                                                                               \
93         ErrorCode returnValue = (exec);                                                                                \
94         if (returnValue != ErrorCode::SUCCESS) {                                                                       \
95             loglevel(fmt, ##args);                                                                                     \
96         }                                                                                                              \
97     } while (0)
98 #endif
99 
100 #ifndef FAIL_LOG_MSG
101 #define FAIL_LOG_MSG(exec, fmt, args...) FAIL_LOG_MSG_IMPL(MEDIA_LOG_E, exec, fmt, ##args)
102 #endif
103 
104 #ifndef FAIL_LOG_MSG_W
105 #define FAIL_LOG_MSG_W(exec, fmt, args...) FAIL_LOG_MSG_IMPL(MEDIA_LOG_W, exec, fmt, ##args)
106 #endif
107 }  // namespace Media
108 }  // namespace OHOS
109 #endif  // HISTREAMER_FOUNDATION_ERROR_CODE_H
110