/**
* @brief Retrieves all actions.
+ * @remarks You must clone the action handle using action_clone() if you want to use it after returning from the callback.
* @param[in] client The action client handle.
* @param[in] cb The callback function to get each action.
* @param[in] user_data The user data to be passed to the callback function.
* @retval #ACTION_ERROR_NONE Successful
* @retval #ACTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see action_clone()
*/
int action_client_foreach_action(action_client_h client, action_foreach_action_cb cb, void *user_data);
*/
int action_client_execute(action_client_h client, const char *param, action_result_cb cb, void *user_data, int *execution_id);
+/**
+ * @brief Clones the action handle.
+ * @param[in] action The action handle.
+ * @param[out] clone The cloned action handle.
+ * @retval #ACTION_ERROR_NONE Successful
+ * @retval #ACTION_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #ACTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see action_destroy()
+ */
+int action_clone(action_h action, action_h *clone);
+
/**
* @brief Gets the name of the action.
* @remarks If you no longer use @name, you must release it using free().
return ACTION_ERROR_NONE;
}
+API int action_clone(action_h action, action_h* clone) {
+ if (action == nullptr || clone == nullptr) {
+ LOG(ERROR) << "Invalid Parameter";
+ return ACTION_ERROR_INVALID_PARAMETER;
+ }
+
+ auto src = static_cast<common::ActionSchema*>(action);
+ *clone = new (std::nothrow) common::ActionSchema(src->GetJsonString());
+ if (*clone == nullptr) {
+ LOG(ERROR) << "Out-of-memory";
+ return ACTION_ERROR_OUT_OF_MEMORY;
+ }
+
+ return ACTION_ERROR_NONE;
+}
+
API int action_get_name(action_h action, const char** name) {
if (action == nullptr || name == nullptr) {
LOG(WARNING) << "Invalid Parameter";