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_PLUGIN_CORE_UTILS_H
17 #define HISTREAMER_PLUGIN_CORE_UTILS_H
18 
19 #include "plugin/common/plugin_types.h"
20 
21 namespace OHOS {
22 namespace Media {
23 namespace Plugin {
24 #define LOG_WARN_IF_NOT_OK(plugin, status) \
25 do { \
26     if ((status) != Status::OK) { \
27         MEDIA_LOG_W("plugin " PUBLIC_LOG_S " " PUBLIC_LOG_S " failed with status " PUBLIC_LOG_D32, \
28             (plugin)->GetName().c_str(), __FUNCTION__, status); \
29     } \
30 } while (0)
31 
32 #define RETURN_WRONG_STATE_IF_CON_TRUE(condition, plugin, state) \
33 do { \
34     if (condition) { \
35         MEDIA_LOG_E("plugin " PUBLIC_LOG_S " cannot " PUBLIC_LOG_S " in state " PUBLIC_LOG_S, \
36             (plugin)->GetName().c_str(), __FUNCTION__, \
37             GetStateString(state)); \
38         return Status::ERROR_WRONG_STATE; \
39     } \
40 } while (0)
41 
42 #define RETURN_WRONG_STATE_IF_CON_FALSE(condition, plugin, state) \
43 do { \
44     if (!(condition)) { \
45         MEDIA_LOG_E("plugin " PUBLIC_LOG_S " cannot " PUBLIC_LOG_S " in state " PUBLIC_LOG_S, \
46                     (plugin)->GetName().c_str(), __FUNCTION__, \
47         GetStateString(state)); \
48         return Status::ERROR_WRONG_STATE; \
49     } \
50 } while (0)
51 
52 const char* GetStateString(State state);
53 } // Plugin
54 } // Media
55 } // OHOS
56 #endif // HISTREAMER_PLUGIN_CORE_UTILS_H
57