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 #include "common/mm_resource_manager_utils.h"
18 #include "lib/mm_resource_manager_priv.h"
20 #include "lib/mm_resource_manager.h"
23 int mm_resource_manager_create(mm_resource_manager_app_class_e app_class,
24 mm_resource_manager_release_cb release_cb, void *cb_user_data,
25 mm_resource_manager_h *rm)
27 MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
29 MM_RM_RETVM_IF(app_class < 0 ||
30 app_class >= MM_RESOURCE_MANAGER_APP_CLASS_MAX,
31 MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER, "Wrong app class");
32 MM_RM_RETVM_IF(NULL == release_cb, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
34 MM_RM_RETVM_IF(access(MM_RESOURCE_MANAGER_READY, F_OK) != 0,
35 MM_RESOURCE_MANAGER_ERROR_LAUNCH_FAILURE, "Resource Manager Launch Failure");
37 return _mm_resource_manager_create(app_class, release_cb, cb_user_data, rm);
40 int mm_resource_manager_destroy(mm_resource_manager_h rm)
42 MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
45 return _mm_resource_manager_destroy(rm);
48 int mm_resource_manager_mark_for_acquire(
49 mm_resource_manager_h rm, mm_resource_manager_res_type_e type,
50 mm_resource_manager_res_volume volume,
51 mm_resource_manager_res_h *resource_h)
53 MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
55 MM_RM_RETVM_IF(type < 0 || type >= MM_RESOURCE_MANAGER_RES_TYPE_MAX,
56 MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
57 "Wrong resource type");
58 MM_RM_RETVM_IF(volume <= 0 && volume != MM_RESOURCE_MANAGER_RES_VOLUME_FULL,
59 MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
60 "Wrong resource part volume");
61 MM_RM_RETVM_IF(resource_h == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
62 "Resource handle is NULL");
64 return _mm_resource_manager_mark_for_acquire(rm, type, volume, resource_h);
67 int mm_resource_manager_resize_marked(mm_resource_manager_h rm,
68 mm_resource_manager_res_h resource_h,
69 mm_resource_manager_res_volume new_volume)
71 MM_RM_RETVM_IF(rm == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
72 "Resource manager handle is NULL");
73 MM_RM_RETVM_IF(resource_h == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
74 "Resource handle is NULL");
75 MM_RM_RETVM_IF(new_volume <= 0 &&
76 new_volume != MM_RESOURCE_MANAGER_RES_VOLUME_FULL,
77 MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
78 "Wrong resource part volume");
80 return _mm_resource_manager_resize_marked(rm, resource_h, new_volume);
83 int mm_resource_manager_mark_for_release(mm_resource_manager_h rm,
84 mm_resource_manager_res_h resource_h)
86 MM_RM_RETVM_IF(rm == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
87 "Resource manager handle is NULL");
88 MM_RM_RETVM_IF(resource_h == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
89 "Resource handle is NULL");
91 return _mm_resource_manager_mark_for_release(rm, resource_h);
94 int mm_resource_manager_mark_all_for_release(mm_resource_manager_h rm)
96 MM_RM_RETVM_IF(rm == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
99 return _mm_resource_manager_mark_all_for_release(rm);
102 int mm_resource_manager_get_resource_info(mm_resource_manager_h rm,
103 mm_resource_manager_res_h resource_h,
104 mm_resource_manager_res_info_s *info)
106 MM_RM_RETVM_IF(rm == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
107 "Resource manager handle is NULL");
108 MM_RM_RETVM_IF(resource_h == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
109 "Resource handle is NULL");
110 MM_RM_RETVM_IF(info == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
111 "Info structure is NULL");
113 return _mm_resource_manager_get_resource_info(rm, resource_h, info);
116 int mm_resource_manager_commit(mm_resource_manager_h rm)
118 MM_RM_RETVM_IF(rm == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
121 return _mm_resource_manager_commit(rm);
124 int mm_resource_manager_set_status_cb(mm_resource_manager_h rm,
125 mm_resource_manager_status_cb cb, void *user_data)
127 MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
130 return _mm_resource_manager_set_status_cb(rm, cb, user_data);
133 int mm_resource_manager_get_res_type_max_volume(mm_resource_manager_h rm,
134 mm_resource_manager_res_type_e type,
135 mm_resource_manager_res_volume *max_volume)
137 MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
139 MM_RM_RETVM_IF(type < 0 || type >= MM_RESOURCE_MANAGER_RES_TYPE_MAX,
140 MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
141 "Wrong resource type");
142 MM_RM_RETVM_IF(max_volume == NULL,
143 MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
144 "Max volume var is NULL");
146 return _mm_resource_manager_get_res_type_max_volume(rm, type, max_volume);
149 int mm_resource_manager_get_res_type_volume(mm_resource_manager_h rm,
150 mm_resource_manager_res_type_e type,
151 mm_resource_manager_res_type_cond_e condition,
152 mm_resource_manager_res_volume *volume)
154 MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
156 MM_RM_RETVM_IF(type < 0 || type >= MM_RESOURCE_MANAGER_RES_TYPE_MAX,
157 MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
158 "Wrong resource type");
159 MM_RM_RETVM_IF(condition < 0 || condition >= MM_RESOURCE_MANAGER_RES_TYPE_COND_MAX,
160 MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
161 "Wrong resource condition");
162 MM_RM_RETVM_IF(volume == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
163 "Volume var is NULL");
165 return _mm_resource_manager_get_res_type_volume(rm, type, condition, volume);