From: Youngjae Shin Date: Wed, 26 Aug 2020 00:34:18 +0000 (+0900) Subject: revise create_mode APIs X-Git-Tag: submit/tizen/20200826.004335^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Faccepted%2Ftizen_6.0_unified;p=platform%2Fcore%2Fsystem%2Fmodes.git revise create_mode APIs modes_mode_add_action() => modes_mode_insert_action() modes_destroy_mode() => modes_free_mode() add modes_free_action() Change-Id: I8afdf18ae3ac2f1142b844f1588a715b81b24456 --- diff --git a/client/mdsc_add_remove.c b/client/mdsc_add_remove.c index 731bd58..cf85309 100644 --- a/client/mdsc_add_remove.c +++ b/client/mdsc_add_remove.c @@ -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); diff --git a/include/modes.h b/include/modes.h index f221993..d189e34 100644 --- a/include/modes.h +++ b/include/modes.h @@ -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 diff --git a/tests/modes_test_client.cpp b/tests/modes_test_client.cpp index bcb4227..3bca797 100644 --- a/tests/modes_test_client.cpp +++ b/tests/modes_test_client.cpp @@ -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());