char *id;
char *rule;
char *value;
+ bool added;
};
struct mds_mode_handle {
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;
}
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);
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.
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.
/**
* @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
/**
* @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
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);
}
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());