feedback: Add feedback_get_theme_ids_internal() 25/301125/3
authorYunhee Seo <yuni.seo@samsung.com>
Wed, 8 Nov 2023 01:52:54 +0000 (10:52 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Fri, 10 Nov 2023 04:54:59 +0000 (13:54 +0900)
Allows getting feedback theme id array supported.

This function is added to feedback.
- int feedback_get_theme_ids_internal(feedback_type_e feedback_type,
unsigned int *count_of_theme, unsigned int **theme_ids);
    - This function gets count of theme available and theme id array.

Test codes have also been added to check normal operation.

Change-Id: I396452314d9b87907bbc52658f788b8987bf67af
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
include/feedback-internal.h
src/devices.h
src/feedback.c
src/sound-theme-manager.c
src/sound-theme-manager.h
src/sound.c
src/vibrator.c
tests/main.c
tests/test-feedback-internal.c
tests/test-feedback-internal.h

index 2038bf7..690c030 100755 (executable)
@@ -229,6 +229,23 @@ int feedback_set_theme_id_internal(feedback_type_e feedback_type, unsigned int i
 int feedback_stop_type_internal(feedback_type_e feedback_type);
 
 /**
+ * @brief Gets the array of theme id supported.
+ * @details This function gets all theme id as defined in the conf file.
+ *          The theme id is positive value according to conf file.
+ * @since_tizen 7.0
+ * @param[in] type The feedback type
+ * @param[out] count_of_theme This means size of theme id array
+ * @param[out] theme_ids The theme id array
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #FEEDBACK_ERROR_NONE Successful
+ * @retval #FEEDBACK_ERROR_OPERATION_FAILED Operation not permitted
+ * @retval #FEEDBACK_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #FEEDBACK_ERROR_NOT_SUPPORTED Not supported device
+ */
+int feedback_get_theme_ids_internal(feedback_type_e feedback_type, unsigned int *count_of_theme, unsigned int **theme_ids);
+
+/**
  * @}
  */
 
index c8f4394..7e64a44 100644 (file)
@@ -37,6 +37,7 @@ struct device_ops {
        int (*get_count_of_theme) (unsigned int *);
        int (*get_theme_id) (unsigned int *);
        int (*set_theme_id) (unsigned int);
+       int (*get_theme_ids) (unsigned int *, unsigned int **);
 };
 
 void devices_init(void);
index 2abfc30..0e1e59e 100644 (file)
@@ -640,4 +640,38 @@ API int feedback_stop_type_internal(feedback_type_e feedback_type)
                return FEEDBACK_ERROR_OPERATION_FAILED;
 
        return FEEDBACK_ERROR_NONE;
+}
+
+API int feedback_get_theme_ids_internal(feedback_type_e feedback_type, unsigned int *count_of_theme, unsigned int **theme_ids)
+{
+       const struct device_ops *dev = NULL;
+       int ret = 0;
+
+       pthread_mutex_lock(&fmutex);
+       if (!init_cnt) {
+               _E("Not initialized"); //LCOV_EXCL_LINE
+               pthread_mutex_unlock(&fmutex);
+               return FEEDBACK_ERROR_NOT_INITIALIZED;
+       }
+       pthread_mutex_unlock(&fmutex);
+
+       if (feedback_type <= FEEDBACK_TYPE_NONE || feedback_type >= profile->max_type || !count_of_theme || !theme_ids) {
+               _E("Invalid parameter : type(%d)", feedback_type);
+               return FEEDBACK_ERROR_INVALID_PARAMETER;
+       }
+
+       dev = find_device(feedback_type);
+       if (!dev) {
+               _E("Not supported device : type(%s)", profile->str_type[feedback_type]);
+               return FEEDBACK_ERROR_NOT_SUPPORTED;
+       }
+
+       if (!dev->get_theme_ids)
+               return FEEDBACK_ERROR_NOT_SUPPORTED;
+
+       ret = dev->get_theme_ids(count_of_theme, theme_ids);
+       if (ret < 0)
+               return FEEDBACK_ERROR_OPERATION_FAILED;
+
+       return FEEDBACK_ERROR_NONE;
 }
\ No newline at end of file
index dc5db9c..3901f66 100644 (file)
@@ -133,6 +133,33 @@ int sound_thememan_add_sound_theme(unsigned int sound_theme_id, const char* conf
        return 0;
 }
 
+int sound_thememan_get_sound_theme_ids(unsigned int *count_of_theme, unsigned int **sound_theme_ids)
+{
+       GHashTableIter iter;
+       gpointer key, value;
+       int get_id = 0;
+       int index = 0;
+       unsigned int *temp_sound_theme_ids = NULL;
+
+       if (!is_g_sound_theme_list_initialized())
+               return -EPERM;
+
+       g_hash_table_iter_init(&iter, g_sound_theme_list);
+       sound_thememan_get_number_of_theme(count_of_theme);
+
+       temp_sound_theme_ids = calloc(*count_of_theme, sizeof(unsigned int));
+       if (!temp_sound_theme_ids)
+               return -ENOMEM;
+
+       while (g_hash_table_iter_next(&iter, &key, &value)) {
+               get_id = *(unsigned int*)key;
+               temp_sound_theme_ids[index++] = get_id;
+       }
+
+       *sound_theme_ids = g_steal_pointer(&temp_sound_theme_ids);
+       return 0;
+}
+
 int sound_thememan_init(void)
 {
        g_sound_theme_list = g_hash_table_new_full(g_int_hash, g_int_equal, g_free,
index bb2e3cb..b8891a5 100644 (file)
@@ -24,6 +24,7 @@ void sound_thememan_get_default_sound_theme_id(unsigned int *sound_theme_id);
 int sound_thememan_get_sound_theme_info(unsigned int sound_theme_id, void *sound_info);
 int sound_thememan_get_number_of_theme(unsigned int *number_of_theme);
 int sound_thememan_add_sound_theme(unsigned int sound_theme_id, const char* conf_file_path);
+int sound_thememan_get_sound_theme_ids(unsigned int *count_of_theme, unsigned int **sound_theme_ids);
 int sound_thememan_init(void);
 void sound_thememan_exit(void);
 
index 01ccfff..bf31a9f 100644 (file)
@@ -534,6 +534,20 @@ static int sound_set_theme_id(unsigned int id_of_theme)
        return 0;
 }
 
+static int sound_get_theme_ids(unsigned int *count_of_theme, unsigned int **theme_ids)
+{
+       int ret = 0;
+
+       if (!count_of_theme || !theme_ids)
+               return -EINVAL;
+
+       ret = sound_thememan_get_sound_theme_ids(count_of_theme, theme_ids);
+       if (ret < 0)
+               return -EPERM;
+
+       return 0;
+}
+
 static const struct device_ops sound_device_ops = {
        .type = FEEDBACK_TYPE_SOUND,
        .name = "Sound",
@@ -548,6 +562,7 @@ static const struct device_ops sound_device_ops = {
        .get_count_of_theme = sound_get_count_of_theme,
        .get_theme_id = sound_get_theme_id,
        .set_theme_id = sound_set_theme_id,
+       .get_theme_ids = sound_get_theme_ids,
 };
 
 DEVICE_OPS_REGISTER(&sound_device_ops);
index 12a9a94..002bcdc 100644 (file)
@@ -393,6 +393,7 @@ static const struct device_ops vibrator_device_ops = {
        .get_count_of_theme = NULL,
        .set_theme_id = NULL,
        .get_theme_id = NULL,
+       .get_theme_ids = NULL,
 };
 
 DEVICE_OPS_REGISTER(&vibrator_device_ops);
index 85e51f5..95f348e 100644 (file)
@@ -30,6 +30,7 @@ void test_all()
        LOG_RESULT(TEST_FEEDBACK_GET_COUNT_OF_SOUND_THEME_INTERNAL(), "TEST_FEEDBACK_GET_COUNT_OF_SOUND_THEME_INTERNAL");
        LOG_RESULT(TEST_FEEDBACK_GET_SOUND_THEME_ID_INTERNAL(), "TEST_FEEDBACK_GET_SOUND_THEME_ID_INTERNAL");
        LOG_RESULT(TEST_FEEDBACK_SET_SOUND_THEME_ID_INTERNAL(), "TEST_FEEDBACK_SET_SOUND_THEME_ID_INTERNAL");
+       LOG_RESULT(TEST_FEEDBACK_GET_SOUND_THEME_IDS_INTERNAL(), "TEST_FEEDBACK_GET_SOUND_THEME_IDS_INTERNAL");
 }
 
 void show_usage()
index 39a0202..bfb7f05 100644 (file)
@@ -410,6 +410,36 @@ bool TEST_FEEDBACK_SET_SOUND_THEME_ID_INTERNAL(void)
        REPORT_AND_RETURN();
 }
 
+static void test_get_sound_theme_ids_internal(void)
+{
+       unsigned int count_of_theme = 0;
+       unsigned int *sound_theme_ids = NULL;
+       int index = 0;
+
+       feedback_initialize();
+       RESULT(feedback_get_theme_ids_internal(FEEDBACK_TYPE_VIBRATION, &count_of_theme, &sound_theme_ids),
+               FEEDBACK_ERROR_NOT_SUPPORTED, "not supported");
+       RESULT(feedback_get_theme_ids_internal(FEEDBACK_TYPE_SOUND, NULL, NULL),
+               FEEDBACK_ERROR_INVALID_PARAMETER, "invalid parameter");
+
+       feedback_get_theme_ids_internal(FEEDBACK_TYPE_SOUND, &count_of_theme, &sound_theme_ids);
+
+       for (index = 0; index < count_of_theme; index++)
+       {
+               RESULT(feedback_set_theme_id_internal(FEEDBACK_TYPE_SOUND, sound_theme_ids[index]),
+                       FEEDBACK_ERROR_NONE, "error none");
+       }
+
+       feedback_deinitialize();
+}
+
+bool TEST_FEEDBACK_GET_SOUND_THEME_IDS_INTERNAL(void)
+{
+       INIT();
+       test_get_sound_theme_ids_internal();
+       REPORT_AND_RETURN();
+}
+
 void TEST_INTERNAL_INIT()
 {
        init_supported_pattern(FEEDBACK_TYPE_SOUND, pattern_s);
index e317087..7521a18 100644 (file)
@@ -123,6 +123,7 @@ bool TEST_FEEDBACK_PLAY_TYPE_SOUNDPATH_INTERNAL(void);
 bool TEST_FEEDBACK_GET_COUNT_OF_SOUND_THEME_INTERNAL(void);
 bool TEST_FEEDBACK_GET_SOUND_THEME_ID_INTERNAL(void);
 bool TEST_FEEDBACK_SET_SOUND_THEME_ID_INTERNAL(void);
+bool TEST_FEEDBACK_GET_SOUND_THEME_IDS_INTERNAL(void);
 
 void TEST_INTERNAL_INIT(void);