Enable resource manager commonization 74/314774/7
authorYoungHun Kim <yh8004.kim@samsung.com>
Fri, 19 Jul 2024 01:12:28 +0000 (10:12 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Tue, 23 Jul 2024 07:46:41 +0000 (16:46 +0900)
[Version] 0.3.1
[Issue Type] Update

Change-Id: I19c56664b0c6ec1409d80504a19394731e30ed9a

configure.ac
packaging/libmm-radio.spec
src/Makefile.am
src/include/mm_radio_priv_emul.h
src/include/mm_radio_priv_hal.h
src/include/mm_radio_rm.h [new file with mode: 0644]
src/mm_radio_priv_emulator.c
src/mm_radio_priv_hal.c
src/mm_radio_rm.c [new file with mode: 0644]
unittest/Makefile.am

index 7a792b3ad4e010bc827ec56c37fc60e4a57f6d6c..95ce7cdd4a4819ef31a17a0f539a3b2ffdfa82ec 100755 (executable)
@@ -31,17 +31,17 @@ AC_PROG_GCC_TRADITIONAL
 AC_FUNC_MALLOC
 AC_CHECK_FUNCS([memset strstr])
 
-PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
-AC_SUBST(GTHREAD_CFLAGS)
-AC_SUBST(GTHREAD_LIBS)
-
 PKG_CHECK_MODULES(MMCOMMON, mm-common)
 AC_SUBST(MMCOMMON_CFLAGS)
 AC_SUBST(MMCOMMON_LIBS)
 
-PKG_CHECK_MODULES(MM_RESOURCE_MANAGER, mm-resource-manager)
-AC_SUBST(MM_RESOURCE_MANAGER_CFLAGS)
-AC_SUBST(MM_RESOURCE_MANAGER_LIBS)
+PKG_CHECK_MODULES(RM, resource-manager)
+AC_SUBST(RM_CFLAGS)
+AC_SUBST(RM_LIBS)
+
+PKG_CHECK_MODULES(RC, resource-center-api)
+AC_SUBST(RC_CFLAGS)
+AC_SUBST(RC_LIBS)
 
 PKG_CHECK_MODULES(DLOG, dlog)
 AC_SUBST(DLOG_CFLAGS)
index 90d68b3f81e83d649240318c8aa3a08f36152acb..3f212b89ff4fc879e9f0a4b4124a91783c472617 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-radio
 Summary:    Multimedia Framework Radio Library
-Version:    0.2.51
+Version:    0.3.1
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
@@ -13,7 +13,9 @@ BuildRequires:  pkgconfig(capi-media-sound-manager)
 BuildRequires:  pkgconfig(gstreamer-1.0)
 BuildRequires:  pkgconfig(gstreamer-plugins-base-1.0)
 %endif
-BuildRequires:  pkgconfig(mm-resource-manager)
+BuildRequires:  pkgconfig(resource-manager)
+BuildRequires:  pkgconfig(resource-information)
+BuildRequires:  pkgconfig(resource-center-api)
 %if 0%{?gtests:1}
 BuildRequires:  pkgconfig(gmock)
 %endif
index 026133f0ce97fa04684906f0689a4b7f1a46d8f8..24c8c06743e0ea9cb7301ff66dca77e4dffb2d67 100755 (executable)
@@ -6,29 +6,29 @@ includelibmmfradio_HEADERS = include/mm_radio.h
 libmmfradio_la_SOURCES = mm_radio.c
 
 libmmfradio_la_CFLAGS = -I. -I./include \
-                       $(GTHREAD_CFLAGS) \
-                       $(MMCOMMON_CFLAGS) \
-                       $(MM_RESOURCE_MANAGER_CFLAGS) \
-                       $(SOUNDMGR_CFLAGS) \
-                       $(DLOG_CFLAGS)
-
-libmmfradio_la_LIBADD = $(GTHREAD_LIBS) \
-                       $(MMCOMMON_LIBS) \
-                       $(MM_RESOURCE_MANAGER_LIBS) \
-                       $(SOUNDMGR_LIBS) \
-                       $(DLOG_LIBS)
-
+            $(MMCOMMON_CFLAGS) \
+            $(SOUNDMGR_CFLAGS) \
+            $(DLOG_CFLAGS) \
+            $(GSTAPP_CFLAGS) \
+            $(RM_CFLAGS) \
+            $(RC_CFLAGS)
+
+libmmfradio_la_LIBADD = $(MMCOMMON_LIBS) \
+            $(SOUNDMGR_LIBS) \
+            $(DLOG_LIBS) \
+            $(RM_LIBS) \
+            $(RC_LIBS)
 
 if ENABLE_EMULATOR
-libmmfradio_la_SOURCES += mm_radio_priv_emulator.c
+libmmfradio_la_SOURCES += mm_radio_priv_emulator.c mm_radio_rm.c
 
 libmmfradio_la_CFLAGS += $(GST_CFLAGS) \
                          $(GSTAPP_CFLAGS)
 
-libmmfradio_la_LIBADD += $(GST_LIBS)  \
-                        $(GSTAPP_LIBS)
+libmmfradio_la_LIBADD += $(GST_LIBS) \
+                         $(GSTAPP_LIBS)
 else
-libmmfradio_la_SOURCES += mm_radio_priv_hal.c
+libmmfradio_la_SOURCES += mm_radio_priv_hal.c mm_radio_rm.c
 
 libmmfradio_la_CFLAGS += $(HAL_API_RADIO_CFLAGS)
 
index 75bf62184924c655f2fc3c5c5facee95fea40082..717742332e96c04b3c036beff3b09a0db5f936f9 100644 (file)
 
 #include <mm_types.h>
 #include <mm_message.h>
-#include <media/mm_resource_manager.h>
 
 #include "mm_radio.h"
 #include "mm_radio_utils.h"
+#include "mm_radio_rm.h"
+
 #include <linux/videodev2.h>
 
 #include <gst/gst.h>
@@ -201,8 +202,9 @@ typedef struct {
 
        int freq;
        mm_radio_gstreamer_s *pipeline;
-       mm_resource_manager_h resource_manager;
-       mm_resource_manager_res_h radio_resource;
+
+       radio_resource_s resource;
+
        int interrupted_by_resource_conflict;
 
        float local_volume;
index b8185c472f70f082769cde3a7d9591b86b9cd6a5..8887d09cfc9fdc98732160a924e5e7a89d05444b 100644 (file)
 
 #include <mm_types.h>
 #include <mm_message.h>
-#include <media/mm_resource_manager.h>
 #include <media/sound_manager.h>
 #include <media/sound_manager_internal.h>
 
 #include "mm_radio.h"
 #include "mm_radio_utils.h"
+#include "mm_radio_rm.h"
 #include <linux/videodev2.h>
 
 #include <glib.h>
@@ -205,8 +205,8 @@ typedef struct {
 
        void *hal_radio;
 
-       mm_resource_manager_h resource_manager;
-       mm_resource_manager_res_h radio_resource;
+       radio_resource_s resource;
+
        int interrupted_by_resource_conflict;
 
 } mm_radio_t;
diff --git a/src/include/mm_radio_rm.h b/src/include/mm_radio_rm.h
new file mode 100644 (file)
index 0000000..a3f6510
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * mm_radio_rm.h
+ *
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MM_RADIO_RM_H__
+#define        __MM_RADIO_RM_H__
+
+#ifdef __cplusplus
+       extern "C" {
+#endif
+
+#include <glib.h>
+#include <mm_types.h>
+#include <rm_api.h>
+#include <rm_type.h>
+#include "mm_radio_utils.h"
+
+typedef enum {
+       MM_RADIO_RES_TYPE_RADIO,     /**< ID of radio resource type */
+       MM_RADIO_RES_TYPE_MAX,        /**< Used to iterate on resource types only */
+} MMRadioResourceTypes;
+
+typedef struct _radio_resource_s {
+       int rm_h;
+       rm_device_return_s returned_devices[MM_RADIO_RES_TYPE_MAX];
+       rm_consumer_info rci;
+       gboolean need_to_acquire[MM_RADIO_RES_TYPE_MAX];
+       GMutex rm_callback_lock;
+       GMutex rm_control_lock;
+} radio_resource_s;
+
+int mm_radio_rm_register(MMHandleType hradio);
+int mm_radio_rm_acquire(MMHandleType hradio, MMRadioResourceTypes type);
+int mm_radio_rm_release(MMHandleType hradio, MMRadioResourceTypes type);
+int mm_radio_rm_unregister(MMHandleType hradio);
+
+
+#ifdef __cplusplus
+       }
+#endif
+
+#endif /* __MM_RADIO_RM_H__ */
index 8d899ba3d1ed28e83a66e2ba65a506ea6849d819..6dbb69598a85d6401436f1986a638e73fb9530f3 100644 (file)
@@ -133,8 +133,6 @@ static void __mmradio_destroy_thread_type(mm_radio_t *radio, MMRadioThreadTypes
 static int __mmradio_set_deemphasis(mm_radio_t * radio);
 static int __mmradio_set_band_range(mm_radio_t * radio);
 static int __mmradio_get_wave_num(mm_radio_t * radio);
-static int __resource_release_cb(mm_resource_manager_h rm,
-       mm_resource_manager_res_h res, void *user_data);
 static void __mmradio_msg_thread(mm_radio_t *radio);
 static void __mmradio_msg_push(mm_radio_t *radio, MMRadioMsgTypes msg_type, int msg_data);
 
@@ -246,8 +244,7 @@ int _mmradio_create_radio(mm_radio_t * radio)
        MMRADIO_SET_STATE(radio, MM_RADIO_STATE_NULL);
 
        /* initialize resource manager */
-       ret = mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
-                       __resource_release_cb, radio, &radio->resource_manager);
+       ret = mm_radio_rm_register((MMHandleType)radio);
        if (ret) {
                MMRADIO_LOG_ERROR("failed to create resource manager");
                ret = MM_ERROR_RADIO_INTERNAL;
@@ -370,7 +367,7 @@ int _mmradio_destroy(mm_radio_t * radio)
        if (radio->msg_queue)
                g_async_queue_unref(radio->msg_queue);
 
-       ret = mm_resource_manager_destroy(radio->resource_manager);
+       ret = mm_radio_rm_unregister((MMHandleType)radio);
        if (ret) {
                MMRADIO_LOG_ERROR("failed to destroy resource manager");
                return MM_ERROR_RADIO_INTERNAL;
@@ -583,22 +580,11 @@ int _mmradio_start(mm_radio_t * radio)
 
        MMRADIO_SLOG_DEBUG("now tune to frequency : %d", radio->freq);
 
-       ret = mm_resource_manager_mark_for_acquire(radio->resource_manager,
-               MM_RESOURCE_MANAGER_RES_TYPE_RADIO,
-               MM_RESOURCE_MANAGER_RES_VOLUME_FULL, &radio->radio_resource);
-       if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
-               MMRADIO_LOG_ERROR("resource manager mark for acquire fail");
-               return MM_ERROR_RADIO_INTERNAL;
-       }
-
        radio->interrupted_by_resource_conflict = FALSE;
-       ret = mm_resource_manager_commit(radio->resource_manager);
-       if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
-               MMRADIO_LOG_ERROR("failed to commit resource manager");
-               mm_resource_manager_mark_for_release(radio->resource_manager,
-                       radio->radio_resource);
-               radio->radio_resource = NULL;
-               return ret;
+       ret = mm_radio_rm_acquire((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+       if (ret != MM_ERROR_NONE) {
+               MMRADIO_LOG_ERROR("resource manager acquire fail");
+               return MM_ERROR_RADIO_INTERNAL;
        }
 
        /* set stored frequency */
@@ -631,19 +617,10 @@ int _mmradio_stop(mm_radio_t * radio)
        /*  if( _mmradio_mute(radio) != MM_ERROR_NONE) */
        /*      return MM_ERROR_RADIO_NOT_INITIALIZED; */
 
-       if (!radio->interrupted_by_resource_conflict && /* is being released */
-                       radio->radio_resource != NULL) {
-               ret = mm_resource_manager_mark_for_release(radio->resource_manager,
-                               radio->radio_resource);
-               radio->radio_resource = NULL;
-               if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
-                       MMRADIO_LOG_ERROR("failed to mark resource for release, ret(0x%x)", ret);
-                       return ret;
-               }
-
-               ret = mm_resource_manager_commit(radio->resource_manager);
-               if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
-                       MMRADIO_LOG_ERROR("resource manager commit fail");
+       if (!radio->interrupted_by_resource_conflict) {
+               ret = mm_radio_rm_release((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+               if (ret != MM_ERROR_NONE)
+                       MMRADIO_LOG_ERROR("resource manager release fail");
        }
 
        MMRADIO_SET_STATE(radio, MM_RADIO_STATE_READY);
@@ -1385,35 +1362,6 @@ static int __mmradio_get_wave_num(mm_radio_t * radio)
        return val;
 }
 
-static int __resource_release_cb(mm_resource_manager_h rm,
-       mm_resource_manager_res_h res, void *user_data)
-{
-       mm_radio_t *radio = NULL;
-
-       MMRADIO_LOG_FENTER();
-
-       if (!user_data) {
-               MMRADIO_LOG_ERROR("user_data is null");
-               return FALSE;
-       }
-
-       radio = (mm_radio_t *)user_data;
-       radio->radio_resource = NULL;
-
-       MMRADIO_LOG_DEBUG("radio resource conflict so, resource will be freed by _mmradio_stop");
-
-       radio->interrupted_by_resource_conflict = TRUE;
-
-       MMRADIO_CMD_LOCK(radio);
-       if (_mmradio_stop(radio) != MM_ERROR_NONE)
-               MMRADIO_LOG_ERROR("failed to stop radio");
-       MMRADIO_CMD_UNLOCK(radio);
-
-       MMRADIO_LOG_FLEAVE();
-
-       return FALSE;
-}
-
 int _mmradio_set_volume(mm_radio_t *radio, float volume)
 {
        MMRADIO_LOG_FENTER();
index c83627fd9782b4c15e045b8ebb15c66cc6edb082..7f57aa7d2e1cfee4a66e0ccaaba2e78dbf304410 100644 (file)
@@ -127,8 +127,6 @@ static void __mmradio_destroy_threads(mm_radio_t *radio);
 static int __mmradio_create_thread_type(mm_radio_t *radio, MMRadioThreadTypes type);
 static void __mmradio_destroy_thread_type(mm_radio_t *radio, MMRadioThreadTypes type);
 
-static int __resource_release_cb(mm_resource_manager_h rm,
-       mm_resource_manager_res_h res, void *user_data);
 static void __mmradio_msg_thread(mm_radio_t *radio);
 static void __mmradio_msg_push(mm_radio_t *radio, MMRadioMsgTypes msg_type, int msg_data);
 static int __mmradio_prepare_radio_device(mm_radio_t *radio);
@@ -268,10 +266,9 @@ int _mmradio_create_radio(mm_radio_t *radio)
        MMRADIO_SET_STATE(radio, MM_RADIO_STATE_NULL);
 
        /* initialize resource manager */
-       ret = mm_resource_manager_create(MM_RESOURCE_MANAGER_APP_CLASS_MEDIA,
-                       __resource_release_cb, radio, &radio->resource_manager);
-       if (ret) {
-               MMRADIO_LOG_ERROR("failed to create resource manager");
+       ret = mm_radio_rm_register((MMHandleType)radio);
+       if (ret != MM_ERROR_NONE) {
+               MMRADIO_LOG_ERROR("failed to register resource manager");
                ret = MM_ERROR_RADIO_INTERNAL;
                goto ERROR_RESOURCE;
        }
@@ -296,7 +293,9 @@ int _mmradio_create_radio(mm_radio_t *radio)
        return MM_ERROR_NONE;
 
 ERROR_HAL_INIT:
-       mm_resource_manager_destroy(radio->resource_manager);
+       ret = mm_radio_rm_unregister((MMHandleType)radio);
+       if (ret != MM_ERROR_NONE)
+               MMRADIO_LOG_ERROR("failed to unregister resource manager");
 ERROR_RESOURCE:
        __mmradio_destroy_threads(radio);
 ERROR_THREAD:
@@ -414,7 +413,7 @@ int _mmradio_destroy(mm_radio_t *radio)
        if (ret)
                MMRADIO_LOG_ERROR("failed to put radio hal backend");
 
-       ret = mm_resource_manager_destroy(radio->resource_manager);
+       ret = mm_radio_rm_unregister((MMHandleType)radio);
        if (ret) {
                MMRADIO_LOG_ERROR("failed to destroy resource manager");
                return MM_ERROR_RADIO_INTERNAL;
@@ -560,11 +559,8 @@ int _mmradio_start(mm_radio_t *radio)
 
        MMRADIO_LOG_INFO("now tune to frequency : %d", radio->freq);
 
-       if (!radio->is_ready) {
-
-       } else {
+       if (radio->is_ready)
                MMRADIO_LOG_DEBUG("radio prepared and opened");
-       }
 
        ret = __mmradio_prepare_radio_device(radio);
        if (ret != MM_ERROR_NONE)
@@ -613,17 +609,11 @@ error:
        hal_radio_close(radio->hal_radio);
        hal_radio_unprepare(radio->hal_radio);
 
-       if (!radio->interrupted_by_resource_conflict && /* is being released */
-               radio->radio_resource != NULL) {
-               if (mm_resource_manager_mark_for_release(radio->resource_manager,
-                       radio->radio_resource) != MM_RESOURCE_MANAGER_ERROR_NONE)
-                       MMRADIO_LOG_ERROR("failed to mark resource for release, ret(0x%x)", ret);
-               radio->radio_resource = NULL;
-
+       if (!radio->interrupted_by_resource_conflict) {
+               ret = mm_radio_rm_release((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+               if (ret != MM_ERROR_NONE)
+                       MMRADIO_LOG_ERROR("resource manager release fail");
        }
-       if (mm_resource_manager_commit(radio->resource_manager)
-               != MM_RESOURCE_MANAGER_ERROR_NONE)
-               MMRADIO_LOG_ERROR("resource manager commit fail");
 
        radio->is_ready = false;
        return ret;
@@ -682,19 +672,10 @@ int _mmradio_stop(mm_radio_t *radio)
                        }
                }
 
-               if (!radio->interrupted_by_resource_conflict && /* is being released */
-                               radio->radio_resource != NULL) {
-                       ret = mm_resource_manager_mark_for_release(radio->resource_manager,
-                                       radio->radio_resource);
-                       radio->radio_resource = NULL;
-                       if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
-                               MMRADIO_LOG_ERROR("failed to mark resource for release, ret(0x%x)", ret);
-                               return ret;
-                       }
-
-                       ret = mm_resource_manager_commit(radio->resource_manager);
-                       if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
-                               MMRADIO_LOG_ERROR("resource manager commit fail");
+               if (!radio->interrupted_by_resource_conflict) {
+                       ret = mm_radio_rm_release((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+                       if (ret != MM_ERROR_NONE)
+                               MMRADIO_LOG_ERROR("resource manager release fail");
                }
                radio->is_ready = false;
        }
@@ -1423,35 +1404,6 @@ int _mmradio_get_volume(mm_radio_t *radio, float *pVolume)
        return ret;
 }
 
-static int __resource_release_cb(mm_resource_manager_h rm,
-       mm_resource_manager_res_h res, void *user_data)
-{
-       mm_radio_t *radio = NULL;
-
-       MMRADIO_LOG_FENTER();
-
-       if (!user_data) {
-               MMRADIO_LOG_ERROR("user_data is null");
-               return FALSE;
-       }
-
-       radio = (mm_radio_t *)user_data;
-       radio->radio_resource = NULL;
-
-       MMRADIO_LOG_DEBUG("radio resource conflict so, resource will be freed by _mmradio_stop");
-
-       radio->interrupted_by_resource_conflict = TRUE;
-
-       MMRADIO_CMD_LOCK(radio);
-       if (_mmradio_stop(radio) != MM_ERROR_NONE)
-               MMRADIO_LOG_ERROR("failed to stop radio");
-       MMRADIO_CMD_UNLOCK(radio);
-
-       MMRADIO_LOG_FLEAVE();
-
-       return FALSE;
-}
-
 static int __mmradio_create_thread_type(mm_radio_t *radio, MMRadioThreadTypes type)
 {
        MMRadioThread_t *p_thread = NULL;
@@ -1696,19 +1648,10 @@ static int __mmradio_prepare_radio_device(mm_radio_t *radio)
                return ret;
        }
 
-       ret = mm_resource_manager_mark_for_acquire(radio->resource_manager,
-               MM_RESOURCE_MANAGER_RES_TYPE_RADIO,
-               MM_RESOURCE_MANAGER_RES_VOLUME_FULL, &radio->radio_resource);
-       if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
-               MMRADIO_LOG_ERROR("resource manager mark for acquire fail");
-               return MM_ERROR_RADIO_INTERNAL;
-       }
-
        radio->interrupted_by_resource_conflict = FALSE;
-       ret = mm_resource_manager_commit(radio->resource_manager);
-       if (ret != MM_RESOURCE_MANAGER_ERROR_NONE) {
-               MMRADIO_LOG_ERROR("failed to commit resource manager");
-               radio->radio_resource = NULL;
+       ret = mm_radio_rm_acquire((MMHandleType)radio. MM_RADIO_RES_TYPE_RADIO);
+       if (ret != MM_ERROR_NONE) {
+               MMRADIO_LOG_ERROR("failed to acquire resource manager");
                return ret;
        }
 
@@ -1752,18 +1695,9 @@ error1:
 error2:
        hal_radio_unprepare(radio->hal_radio);
 
-       if (!radio->interrupted_by_resource_conflict && /* is being released */
-               radio->radio_resource != NULL) {
-               if (mm_resource_manager_mark_for_release(radio->resource_manager,
-                       radio->radio_resource) != MM_RESOURCE_MANAGER_ERROR_NONE)
-                       MMRADIO_LOG_ERROR("failed to mark resource for release, ret(0x%x)", ret);
-               radio->radio_resource = NULL;
-
-       }
-
-       if (mm_resource_manager_commit(radio->resource_manager)
-               != MM_RESOURCE_MANAGER_ERROR_NONE)
-               MMRADIO_LOG_ERROR("resource manager commit fail");
+       ret = mm_radio_rm_release((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+       if (ret != MM_ERROR_NONE)
+               MMRADIO_LOG_ERROR("resource manager release fail");
 
        radio->is_ready = false;
        return ret;
@@ -1789,18 +1723,9 @@ static void __mmradio_close_radio_device(mm_radio_t *radio)
        if (ret)
                __convert_error_code(ret, (char *)__FUNCTION__);
 
-       if (!radio->interrupted_by_resource_conflict && /* is being released */
-               radio->radio_resource != NULL) {
-               ret = mm_resource_manager_mark_for_release(radio->resource_manager,
-                       radio->radio_resource);
-               radio->radio_resource = NULL;
-               if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
-                       MMRADIO_LOG_ERROR("failed to mark resource for release, ret(0x%x)", ret);
-       }
-
-       ret = mm_resource_manager_commit(radio->resource_manager);
-       if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
-               MMRADIO_LOG_ERROR("resource manager commit fail");
+       ret = mm_radio_rm_release((MMHandleType)radio, MM_RADIO_RES_TYPE_RADIO);
+       if (ret != MM_ERROR_NONE)
+               MMRADIO_LOG_ERROR("resource manager release fail");
 
        radio->is_ready = false;
 }
diff --git a/src/mm_radio_rm.c b/src/mm_radio_rm.c
new file mode 100644 (file)
index 0000000..092055a
--- /dev/null
@@ -0,0 +1,277 @@
+/*
+ * mm_radio.c
+ *
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "mm_radio_rm.h"
+#include "mm_radio_priv_emul.h"
+#include "mm_radio_priv_hal.h"
+#include <mm_error.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <resource_center.h>
+
+static int
+__mmradio_get_appid_by_pid(int pid, char *name, size_t size)
+{
+       g_autofree gchar *cmdline = NULL;
+       g_autofree gchar *contents = NULL;
+       g_autofree gchar *base = NULL;
+       g_autoptr(GError) error = NULL;
+
+       MMRADIO_RETURN_VAL_IF_FAIL(name, MM_ERROR_INVALID_ARGUMENT);
+       MMRADIO_RETURN_VAL_IF_FAIL(size != 0, MM_ERROR_INVALID_ARGUMENT);
+
+       cmdline = g_strdup_printf("/proc/%d/cmdline", (int)pid);
+
+       if (!g_file_get_contents(cmdline, &contents, NULL, &error)) {
+               MMRADIO_LOG_ERROR("error : %s", error->message);
+               return MM_ERROR_RADIO_INTERNAL;
+       }
+
+       base = g_path_get_basename(contents);
+
+       if (g_strlcpy(name, base, size) >= size)
+               MMRADIO_LOG_ERROR("string truncated");
+
+       return MM_ERROR_NONE;
+}
+
+static void _mmradio_execute_resource_release(mm_radio_t *radio)
+{
+       MMRADIO_LOG_FENTER();
+
+       if (!radio) {
+               MMRADIO_LOG_ERROR("radio is null");
+               return;
+       }
+
+       MMRADIO_LOG_INFO("radio resource conflict so, resource will be freed by _mmradio_stop");
+
+       radio->interrupted_by_resource_conflict = TRUE;
+
+       MMRADIO_CMD_LOCK(radio);
+       if (_mmradio_stop(radio) != MM_ERROR_NONE)
+               MMRADIO_LOG_ERROR("failed to stop radio");
+       MMRADIO_CMD_UNLOCK(radio);
+
+       MMRADIO_LOG_FLEAVE();
+}
+
+
+static rm_cb_result
+__mmradio_rm_callback(int handle, rm_callback_type event_src, rm_device_request_s *info, void *cb_data)
+{
+       mm_radio_t *radio = (mm_radio_t *)cb_data;
+       g_autoptr(GMutexLocker) locker = NULL;
+
+       MMRADIO_RETURN_VAL_IF_FAIL(radio, MM_ERROR_RADIO_NOT_INITIALIZED);
+
+       MMRADIO_LOG_INFO("rm callback info mm_radio_t [%p] handle : %d event_src : %d", radio, handle, event_src);
+
+       locker = g_mutex_locker_new(&radio->resource.rm_callback_lock);
+
+       switch (event_src) {
+       case RM_CALLBACK_TYPE_RESOURCE_CONFLICT:
+       case RM_CALLBACK_TYPE_RESOURCE_CONFLICT_UD:
+               _mmradio_execute_resource_release(radio);
+               break;
+       default:
+               break;
+       }
+
+       MMRADIO_LOG_FLEAVE();
+
+       return RM_CB_RESULT_OK;
+}
+
+int mm_radio_rm_register(MMHandleType hradio)
+{
+       int ret;
+       mm_radio_t *radio = (mm_radio_t *)hradio;
+
+       MMRADIO_LOG_FENTER();
+
+       MMRADIO_RETURN_VAL_IF_FAIL(radio, MM_ERROR_RADIO_NOT_INITIALIZED);
+
+       if (radio->resource.rm_h) {
+               MMRADIO_LOG_INFO("[%d] resource manager handle is already registered", radio->resource.rm_h);
+               return MM_ERROR_NONE;
+       }
+
+       memset(&radio->resource.rci, 0x00, sizeof(rm_consumer_info));
+
+       radio->resource.rci.app_pid = (int)getpid();
+
+       if (__mmradio_get_appid_by_pid(radio->resource.rci.app_pid, radio->resource.rci.app_id, sizeof(radio->resource.rci.app_id)) != MM_ERROR_NONE) {
+               MMRADIO_LOG_ERROR("__mmradio_get_appid_by_pid is failed");
+               return MM_ERROR_RADIO_INTERNAL;
+       }
+
+       MMRADIO_LOG_INFO("app pid %d app id %s", radio->resource.rci.app_pid, radio->resource.rci.app_id);
+
+       ret = rm_register((rm_resource_cb)__mmradio_rm_callback,
+                                               (void *)radio,
+                                               &(radio->resource.rm_h),
+                                               (radio->resource.rci.app_id[0] != '\0') ? &radio->resource.rci : NULL);
+       if (ret != RM_OK) {
+               MMRADIO_LOG_ERROR("rm_register fail %d", ret);
+               return MM_ERROR_RADIO_INTERNAL;
+       }
+
+       MMRADIO_LOG_FLEAVE();
+
+       return MM_ERROR_NONE;
+
+}
+
+int mm_radio_rm_acquire(MMHandleType hradio, MMRadioResourceTypes type)
+{
+       int ret = RM_OK;
+       int idx = 0;
+       int category_option = 0;
+       rm_rsc_category_e category_id = RM_CATEGORY_NONE;
+       rm_requests_resource_state_e state;
+       rm_category_request_s request_resources;
+       rm_device_return_s *returned_device;
+       g_autoptr(GMutexLocker) locker = NULL;
+       mm_radio_t *radio = (mm_radio_t *)hradio;
+
+       MMRADIO_LOG_FENTER();
+
+       MMRADIO_RETURN_VAL_IF_FAIL(radio, MM_ERROR_RADIO_NOT_INITIALIZED);
+
+       locker = g_mutex_locker_new(&radio->resource.rm_control_lock);
+
+       MMRADIO_LOG_INFO("app id : %s type %d", radio->resource.rci.app_id, type);
+       memset(&request_resources, 0x0, sizeof(rm_category_request_s));
+
+       returned_device = &radio->resource.returned_devices[type];
+       memset(returned_device, 0x0, sizeof(rm_device_return_s));
+
+       switch (type) {
+       case MM_RADIO_RES_TYPE_RADIO:
+               state = RM_STATE_EXCLUSIVE;
+               category_id = RM_CATEGORY_RADIO;
+               break;
+       default:
+               MMRADIO_LOG_ERROR("category id can't set");
+               return MM_ERROR_RADIO_INTERNAL;
+       }
+
+       category_option = rc_get_capable_category_id(radio->resource.rm_h, radio->resource.rci.app_id, category_id);
+
+       request_resources.request_num = 1;
+       request_resources.state[0] = state;
+       request_resources.category_id[0] = category_id;
+       request_resources.category_option[0] = category_option;
+       MMRADIO_LOG_INFO("state %d category id 0x%x category option %d", state, category_id, category_option);
+
+       ret = rm_allocate_resources(radio->resource.rm_h, &request_resources, returned_device);
+       if (ret != RM_OK) {
+               MMRADIO_LOG_WARNING("Resource allocation request failed ret %d [error type %d]", ret, returned_device->error_type);
+               return MM_ERROR_RADIO_INTERNAL;
+       }
+
+       for (idx = 0; idx < returned_device->allocated_num; idx++)
+               MMRADIO_LOG_INFO("#%d / %d [%p] device %d %s %s", idx, returned_device->allocated_num, returned_device,
+                       returned_device->device_id[idx], returned_device->device_node[idx],
+                       returned_device->device_name[idx]);
+
+       MMRADIO_LOG_FLEAVE();
+
+       return MM_ERROR_NONE;
+}
+
+int mm_radio_rm_release(MMHandleType hradio, MMRadioResourceTypes type)
+{
+       int rm_ret = RM_OK;
+       int idx = 0;
+       rm_device_request_s requested;
+       rm_device_return_s *r_devices;
+       g_autoptr(GMutexLocker) locker = NULL;
+       mm_radio_t *radio = (mm_radio_t *)hradio;
+
+       MMRADIO_LOG_FENTER();
+
+       MMRADIO_RETURN_VAL_IF_FAIL(radio, MM_ERROR_RADIO_NOT_INITIALIZED);
+       MMRADIO_RETURN_VAL_IF_FAIL(radio->resource.rm_h, MM_ERROR_RADIO_NOT_INITIALIZED);
+
+       locker = g_mutex_locker_new(&radio->resource.rm_control_lock);
+
+       r_devices = &radio->resource.returned_devices[type];
+
+       MMRADIO_LOG_INFO("[%p] #%d (type %d) alloc num %d", r_devices, idx, type, r_devices->allocated_num);
+
+       if (r_devices->allocated_num > 0) {
+               memset(&requested, 0x0, sizeof(rm_device_request_s));
+               requested.request_num = r_devices->allocated_num;
+               for (idx = 0; idx < requested.request_num; idx++) {
+                       requested.device_id[idx] = r_devices->device_id[idx];
+                       MMRADIO_LOG_INFO("[device id %d] [device name %s]", r_devices->device_id[idx], r_devices->device_name[idx]);
+               }
+
+               rm_ret = rm_deallocate_resources(radio->resource.rm_h, &requested);
+               if (rm_ret != RM_OK) {
+                       MMRADIO_LOG_ERROR("Resource deallocation request failed [%d] [request num %d]", rm_ret, requested.request_num);
+                       return MM_ERROR_RADIO_INTERNAL;
+               }
+       }
+
+       for (idx = 0; idx < r_devices->allocated_num; idx++) {
+               if (r_devices->device_node[idx]) {
+                       free(r_devices->device_node[idx]);
+                       r_devices->device_node[idx] = NULL;
+               }
+
+               if (r_devices->omx_comp_name[idx]) {
+                       free(r_devices->omx_comp_name[idx]);
+                       r_devices->omx_comp_name[idx] = NULL;
+               }
+       }
+
+       MMRADIO_LOG_FLEAVE();
+
+       return MM_ERROR_NONE;
+}
+
+int mm_radio_rm_unregister(MMHandleType hradio)
+{
+       int ret;
+       mm_radio_t *radio = (mm_radio_t *)hradio;
+
+       MMRADIO_LOG_FENTER();
+
+       MMRADIO_RETURN_VAL_IF_FAIL(radio, MM_ERROR_RADIO_NOT_INITIALIZED);
+
+       if (!radio->resource.rm_h) {
+               MMRADIO_LOG_INFO("resource manager handle is not registered");
+               return MM_ERROR_NONE;
+       }
+
+       ret = rm_unregister(radio->resource.rm_h);
+       if (ret != RM_OK) {
+               MMRADIO_LOG_ERROR("rm_unregister fail %d", ret);
+               return MM_ERROR_RADIO_INTERNAL;
+       }
+
+       LOGD("rm_unregister[%d]", ret);
+
+       MMRADIO_LOG_FLEAVE();
+
+       return MM_ERROR_NONE;
+}
index d7e451a218b8297c199523530083d1ace4b63a2d..efaf7e8e4a8289ff1a813c1e314fd659a476d0b4 100644 (file)
@@ -6,7 +6,9 @@ gtest_libmm_radio_SOURCES = gtest_libmm-radio.cpp
 gtest_libmm_radio_CXXFLAGS = -I$(top_srcdir)/src/include \
                        $(GTHREAD_CFLAGS) \
                        $(MMCOMMON_CFLAGS) \
-                       $(MM_RESOURCE_MANAGER_CFLAGS) \
+                       $(RM_CFLAGS) \
+                       $(RI_CFLAGS) \
+                       $(RC_CFLAGS) \
                        $(DLOG_CFLAGS) \
                        $(GTESTS_CFLAGS) \
                        $(SOUNDMGR_CFLAGS) \
@@ -16,7 +18,9 @@ gtest_libmm_radio_DEPENDENCIES = $(top_srcdir)/src/.libs/libmmfradio.la
 
 gtest_libmm_radio_LDADD = $(GTHREAD_LIBS) \
                        $(MMCOMMON_LIBS) \
-                       $(MM_RESOURCE_MANAGER_LIBS) \
+                       $(RM_LIBS) \
+                       $(RI_LIBS) \
+                       $(RC_LIBS) \
                        $(DLOG_LIBS) \
                        $(GTESTS_LIBS) \
                        $(SOUNDMGR_LIBS) \