revise create_mode APIs accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix tizen_6.0 tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.115658 accepted/tizen/6.0/unified/hotfix/20201103.002217 accepted/tizen/unified/20200826.231618 submit/tizen/20200826.004335 submit/tizen_6.0/20201029.205104 submit/tizen_6.0_hotfix/20201102.192505 submit/tizen_6.0_hotfix/20201103.114805 tizen_6.0.m2_release
authorYoungjae Shin <yj99.shin@samsung.com>
Wed, 26 Aug 2020 00:34:18 +0000 (09:34 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 26 Aug 2020 00:41:50 +0000 (09:41 +0900)
modes_mode_add_action() => modes_mode_insert_action()
modes_destroy_mode() => modes_free_mode()
add modes_free_action()

Change-Id: I8afdf18ae3ac2f1142b844f1588a715b81b24456

client/mdsc_add_remove.c
include/modes.h
tests/modes_test_client.cpp

index 731bd58c956598a202678db0e295ad500380ace7..cf853096d61906b842a0283665ab0c2c4cf1ff41 100644 (file)
@@ -25,6 +25,7 @@ struct mds_action_handle {
        char *id;
        char *rule;
        char *value;
+       bool added;
 };
 
 struct mds_mode_handle {
@@ -144,16 +145,28 @@ API modes_action_h modes_create_action(const char *name, const char *value)
        action->rule = strdup(name);
        action->value = strdup(value);
        action->id = NULL;
+       action->added = false;
 
        return action;
 }
 
-API int modes_mode_add_action(modes_mode_h mode, modes_action_h action)
+API void modes_free_action(modes_action_h action)
+{
+       RET_IF(NULL == action);
+
+       if (action->added)
+               return;
+
+       _mdsc_free_action(action);
+}
+
+API int modes_mode_insert_action(modes_mode_h mode, modes_action_h action)
 {
        RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == action, MODES_ERROR_INVALID_PARAMETER);
 
        mode->action_list = g_list_append(mode->action_list, action);
+       action->added = true;
 
        return MODES_ERROR_NONE;
 }
@@ -192,7 +205,7 @@ API int modes_remove_mode(modes_h handle, const char *id)
        return MODES_ERROR_NONE;
 }
 
-API void modes_destroy_mode(modes_mode_h mode)
+API void modes_free_mode(modes_mode_h mode)
 {
        RET_IF(NULL == mode);
 
index f221993f357d5f3ba43335c461318e5d60768131..d189e34dced5b36559206e7b6f7f21dfb9cc0c63 100644 (file)
@@ -156,18 +156,27 @@ int modes_set_hidden(modes_mode_h mode, bool hidden);
 modes_action_h modes_create_action(const char *rule, const char *value);
 
 /**
- * @brief Add Action to Mode.
- * @details Calls this function to add action to mode.
+ * @brief Inserts a action handle into a mode handle.
+ * @remarks Should NOT release @a action. It is released when the @a mode is destroyed.
  * @since_tizen 6.0
  * @privlevel public
- * @param[in] Mode handle
- * @param[in] Action handle to add
+ * @param[in] mode a mode handle
+ * @param[in] action a action handle to insert
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #MODES_ERROR_NONE Successful
  * @retval #MODES_ERROR_INVALID_PARAMETER Invalid parameter
  */
-int modes_mode_add_action(modes_mode_h mode, modes_action_h action);
+int modes_mode_insert_action(modes_mode_h mode, modes_action_h action);
+
+/**
+ * @brief Frees all of the memory used by a @c modes_action_h
+ * @remarks If the acton was inserted into a mode, it is ignored.
+ * @since_tizen 6.0
+ * @privlevel public
+ * @param[in] action The action handle to destroy
+ */
+void modes_free_action(modes_action_h action);
 
 /**
  * @brief Add Mode.
@@ -186,14 +195,12 @@ int modes_mode_add_action(modes_mode_h mode, modes_action_h action);
 int modes_add_mode(modes_h handle, modes_mode_h mode);
 
 /**
- * @brief Destroy Mode handle
- * @details Calls this function to destroy mode handle
+ * @brief Frees A Mode handle
  * @since_tizen 6.0
  * @privlevel public
- * @param[in] Mode handle to destroy
- * @return void
+ * @param[in] mode The mode handle to destroy
  */
-void modes_destroy_mode(modes_mode_h mode);
+void modes_free_mode(modes_mode_h mode);
 
 /**
  * @brief Remove Mode.
@@ -267,6 +274,7 @@ void modes_free_modes(GList *list);
 /**
  * @brief Get ID of mode from GList data
  * @details Calls this function to get mode list
+ * @remarks The returned mode ID should not be modified or freed.
  * @since_tizen 6.0
  * @privlevel public
  * @param[in] GList for mode list
@@ -277,6 +285,7 @@ const char* modes_get_mode_id(mode_list_data_h data);
 /**
  * @brief Get name of mode from GList data
  * @details Calls this function to get mode list
+ * @remarks The returned mode name should not be modified or freed.
  * @since_tizen 6.0
  * @privlevel public
  * @param[in] GList for mode list to free
index bcb42276ac160b6990847771df07ffc409da958a..3bca7976be4b0c7d0fa78902fc145c561a09938b 100644 (file)
@@ -64,7 +64,8 @@ protected:
                action_handle[1] = modes_create_action("test.printBool", "off");
 
                for (int i = 0; i < 2; i++) {
-                       result = modes_mode_add_action(created_mode, action_handle[i]);
+                       result = modes_mode_insert_action(created_mode, action_handle[i]);
+                       modes_free_action(action_handle[i]); //For abnormal case
                        EXPECT_EQ(MODES_ERROR_NONE, result);
                }
 
@@ -72,7 +73,7 @@ protected:
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
                result = modes_add_mode(handle, created_mode);
-               modes_destroy_mode(created_mode);
+               modes_free_mode(created_mode);
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
                result = modes_apply_mode(handle, id.c_str());