• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 COMMON_UTILS_H
17 #define COMMON_UTILS_H
18 
19 #include <string>
20 #include "napi/native_api.h"
21 
22 #include "logging.h"
23 #include <multimedia/image_effect/image_effect_filter.h>
24 
25 #define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...)  \
26     do {                                               \
27         if (!(cond)) {                                 \
28             LOG_E(fmt, ##__VA_ARGS__);                 \
29             return ret;                                \
30         }                                              \
31     } while (0)
32 
33 #define CHECK_AND_RETURN_LOG(cond, fmt, ...)           \
34     do {                                               \
35         if (!(cond)) {                                 \
36             LOG_E(fmt, ##__VA_ARGS__);                 \
37             return;                                    \
38         }                                              \
39     } while (0)
40 
41 #define CHECK_AND_NO_RETURN_LOG(cond, fmt, ...)        \
42     do {                                               \
43         if (!(cond)) {                                 \
44             LOG_E(fmt, ##__VA_ARGS__);                 \
45         }                                              \
46     } while (0)
47 
48 #define CHECK_AND_RETURN_NO_RET(cond, fmt, ...)        \
49     do {                                               \
50         if (!(cond)) {                                 \
51             LOG_E(fmt, ##__VA_ARGS__);                 \
52             return;                                    \
53         }                                              \
54     } while (0)
55 
56 class CommonUtils {
57 public:
58     static const char *GetStringArgument(napi_env env, napi_value value);
59 
60     static std::string EffectInfoToString(OH_EffectFilterInfo *info);
61 };
62 
63 #endif // COMMON_UTILS_H