Add new api of stream and instance for multi-instance
[platform/core/multimedia/mm-resource-manager.git] / src / lib / mm_resource_manager.c
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "common/mm_resource_manager_utils.h"
18 #include "lib/mm_resource_manager_priv.h"
19
20 #include "lib/mm_resource_manager.h"
21 #include <unistd.h>
22
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)
26 {
27         MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
28                         "Handle is NULL");
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,
33                         "Callback is NULL");
34         MM_RM_RETVM_IF(access(MM_RESOURCE_MANAGER_READY, F_OK) != 0,
35                         MM_RESOURCE_MANAGER_ERROR_LAUNCH_FAILURE, "Resource Manager Launch Failure");
36
37         return _mm_resource_manager_create(app_class, release_cb, cb_user_data, rm);
38 }
39
40 int mm_resource_manager_destroy(mm_resource_manager_h rm)
41 {
42         MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
43                         "Handle is NULL");
44
45         return _mm_resource_manager_destroy(rm);
46 }
47
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)
52 {
53         MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
54                         "Handle is NULL");
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");
63
64         return _mm_resource_manager_mark_for_acquire(rm, type, volume, resource_h);
65 }
66
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)
70 {
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");
79
80         return _mm_resource_manager_resize_marked(rm, resource_h, new_volume);
81 }
82
83 int mm_resource_manager_mark_for_release(mm_resource_manager_h rm,
84                 mm_resource_manager_res_h resource_h)
85 {
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");
90
91         return _mm_resource_manager_mark_for_release(rm, resource_h);
92 }
93
94 int mm_resource_manager_mark_all_for_release(mm_resource_manager_h rm)
95 {
96         MM_RM_RETVM_IF(rm == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
97                         "Handle is NULL");
98
99         return _mm_resource_manager_mark_all_for_release(rm);
100 }
101
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)
105 {
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");
112
113         return _mm_resource_manager_get_resource_info(rm, resource_h, info);
114 }
115
116 int mm_resource_manager_commit(mm_resource_manager_h rm)
117 {
118         MM_RM_RETVM_IF(rm == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
119                         "Handle is NULL");
120
121         return _mm_resource_manager_commit(rm);
122 }
123
124 int mm_resource_manager_set_status_cb(mm_resource_manager_h rm,
125                 mm_resource_manager_status_cb cb, void *user_data)
126 {
127         MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
128                         "Handle is NULL");
129
130         return _mm_resource_manager_set_status_cb(rm, cb, user_data);
131 }
132
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)
136 {
137         MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
138                         "Handle is NULL");
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");
145
146         return _mm_resource_manager_get_res_type_max_volume(rm, type, max_volume);
147 }
148
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)
153 {
154         MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
155                         "Handle is NULL");
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");
164
165         return _mm_resource_manager_get_res_type_volume(rm, type, condition, volume);
166 }
167
168 int mm_resource_manager_get_type_max_instance(mm_resource_manager_h rm,
169                 mm_resource_manager_res_type_e type, int *max_instance)
170 {
171         MM_RM_RETVM_IF(NULL == rm, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER, "Handle is NULL");
172         MM_RM_RETVM_IF(type < 0 || type >= MM_RESOURCE_MANAGER_RES_TYPE_MAX,
173                                         MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER, "Wrong resource type");
174         MM_RM_RETVM_IF(max_instance == NULL, MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER, "Max instance var is NULL");
175
176         return _mm_resource_manager_get_type_max_instance(rm, type, max_instance);
177 }