2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __MM_RESOURCE_MANAGER_UTILS__
18 #define __MM_RESOURCE_MANAGER_UTILS__
24 #include "lib/mm_resource_manager.h"
32 #define LOG_TAG "MM_RESOURCE_MANAGER"
34 #define FONT_COLOR_RESET "\033[0m"
35 #define FONT_COLOR_RED "\033[31m"
36 #define FONT_COLOR_GREEN "\033[32m"
38 #define MM_RM_DEBUG(fmt, arg...) \
40 LOGD(FONT_COLOR_RESET""fmt""FONT_COLOR_RESET, ##arg); \
43 #define MM_RM_INFO(fmt, arg...) \
45 LOGI(FONT_COLOR_GREEN""fmt""FONT_COLOR_RESET, ##arg); \
48 #define MM_RM_ERROR(fmt, arg...) \
50 LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
53 #define MM_RM_RETM_IF(expr, fmt, arg...) \
56 LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
61 #define MM_RM_RETVM_IF(expr, val, fmt, arg...) \
64 LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
69 #define MM_RM_RET_IF_GERR(gerr, msg) \
72 LOGE(FONT_COLOR_RED""msg""" '%s'"""FONT_COLOR_RESET, \
74 g_error_free(error); \
75 return(MM_RESOURCE_MANAGER_ERROR_INVALID_OPERATION); \
79 #define MM_RM_UNLOCK_RETVM_IF(expr, mtx, val, fmt, arg...) \
82 LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
83 g_mutex_unlock(&mtx); \
88 #define MM_RM_RETM_IF_E(expr, fmt, arg...) \
91 if (err != MM_RESOURCE_MANAGER_ERROR_NONE) { \
92 LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg); \
98 #define MM_RM_G_RAND_NEW g_rand_new()
99 #define MM_RM_RAND64(var) \
101 GRand *rnd = MM_RM_G_RAND_NEW; \
103 mm_resource_manager_id i; \
106 i_d_rnd.d = g_rand_double(rnd); \
111 #define MM_RM_HASH64(var) \
113 var = (var ^ (var >> 30)) * UINT64_C(0xbf58476d1ce4e5b9); \
114 var = (var ^ (var >> 27)) * UINT64_C(0x94d049bb133111eb); \
115 var = var ^ (var >> 31); \
118 #define MM_RESOURCE_MANAGER_NO_RES (-2)
119 #define MM_RESOURCE_MANAGER_NO_APP_CLASS (-1)
120 #define RELEASE_CB_SYNC_PATH "/tmp/.mm-res-mgr.fifo"
122 typedef uint64_t mm_resource_manager_id;
124 const char* _mm_resource_manager_get_res_str(mm_resource_manager_res_type_e type);
125 const char* _mm_resource_manager_get_app_class_str(mm_resource_manager_app_class_e cls);
126 const char* _mm_resource_manager_get_condition_str(mm_resource_manager_res_type_cond_e cond);
127 uint64_t _mm_rm_hash64(uint64_t id);
129 #endif /* __MM_RESOURCE_MANAGER_UTILS__ */