Add implementation of new APIs for cache support 68/291268/2 accepted/tizen/unified/20230420.041538
authorJaehyun Kim <jeik01.kim@samsung.com>
Wed, 12 Apr 2023 11:58:55 +0000 (20:58 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Wed, 12 Apr 2023 12:20:20 +0000 (21:20 +0900)
Change-Id: I51241fa3aac70f910303be71763880f3c6e45622
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
CMakeLists.txt
include/download_extension.h [new file with mode: 0644]
packaging/capi-web-url-download.spec
src/download-wrapping.c

index 5917c64..7c139fc 100755 (executable)
@@ -48,6 +48,7 @@ INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
 INSTALL(FILES ${INC_DIR}/download.h DESTINATION include/web/)
 INSTALL(FILES ${INC_DIR}/download_product.h DESTINATION include/web/)
 INSTALL(FILES ${INC_DIR}/download_private.h DESTINATION include/web/)
+INSTALL(FILES ${INC_DIR}/download_extension.h DESTINATION include/web/)
 INSTALL(FILES ${DOC_DIR}/download_doc.h DESTINATION include/web/)
 
 SET(PC_NAME ${fw_name})
diff --git a/include/download_extension.h b/include/download_extension.h
new file mode 100644 (file)
index 0000000..50909fb
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_WEB_DOWNLOAD_EXTENSION_H__
+#define __TIZEN_WEB_DOWNLOAD_EXTENSION_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+ * @file download_extension.h
+ */
+
+ /**
+ * @addtogroup CAPI_WEB_DOWNLOAD_MODULE
+ * @{
+ */
+
+
+/**
+ * @brief Sets the max size of the cache.
+ *
+ * @since_tizen 7.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/download
+ *
+ * @remarks The default size is 1000 MB.
+ *
+ * @param[in] size  The max size of the cache (MB)
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #DOWNLOAD_ERROR_NONE              Successful
+ * @retval #DOWNLOAD_ERROR_NOT_SUPPORTED     Not supported
+ * @retval #DOWNLOAD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND      No download ID
+ *
+ * @see download_get_cache_max_size()
+ */
+int download_set_cache_max_size(unsigned int size);
+
+
+/**
+ * @brief Gets the max size of the cache.
+ *
+ * @since_tizen 7.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/download
+ *
+ * @param[out] size  The max size of the cache (MB)
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #DOWNLOAD_ERROR_NONE              Successful
+ * @retval #DOWNLOAD_ERROR_NOT_SUPPORTED     Not supported
+ * @retval #DOWNLOAD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND      No download ID
+ *
+ * @see download_set_cache_max_size()
+ */
+int download_get_cache_max_size(unsigned int *size);
+
+
+/**
+ * @brief Clears all cache.
+ *
+ * @since_tizen 7.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/download
+ *
+ * @return 0 on success, otherwise a negative error value
+ *
+ * @retval #DOWNLOAD_ERROR_NONE              Successful
+ * @retval #DOWNLOAD_ERROR_NOT_SUPPORTED     Not supported
+ * @retval #DOWNLOAD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND      No download ID
+ */
+int download_reset_all_cache(void);
+
+
+/**
+ * @brief Sets the path of the cache stored.
+ *
+ * @since_tizen 7.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/download
+ *
+ * @param[in] path  the path of the cache stored
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #DOWNLOAD_ERROR_NONE              Successful
+ * @retval #DOWNLOAD_ERROR_NOT_SUPPORTED     Not supported
+ * @retval #DOWNLOAD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND      No download ID
+ *
+ * @see download_get_cache_path()
+ */
+int download_set_cache_path(const char *path);
+
+
+/**
+ * @brief Gets the path of the cache stored.
+ *
+ * @since_tizen 7.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/download
+ *
+ * @param[out] path  the path of the cache stored
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #DOWNLOAD_ERROR_NONE              Successful
+ * @retval #DOWNLOAD_ERROR_NOT_SUPPORTED     Not supported
+ * @retval #DOWNLOAD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND      No download ID
+ *
+ * @see download_set_cache_path()
+ */
+int download_get_cache_path(char **path);
+
+
+/**
+ * @brief Sets the life cycle of the cache.
+ *
+ * @since_tizen 7.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/download
+ *
+ * @remarks The default time is 48 * 3600 seconds.
+ *
+ * @param[in] time  The life cycle of the cache (seconds)
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #DOWNLOAD_ERROR_NONE              Successful
+ * @retval #DOWNLOAD_ERROR_NOT_SUPPORTED     Not supported
+ * @retval #DOWNLOAD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND      No download ID
+ *
+ * @see download_get_cache_lifecycle()
+ */
+int download_set_cache_lifecycle(unsigned int time);
+
+
+/**
+ * @brief Gets the life cycle of the cache.
+ *
+ * @since_tizen 7.5
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/download
+ *
+ * @param[out] time  The life cycle of the cache (seconds)
+ *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ *
+ * @retval #DOWNLOAD_ERROR_NONE              Successful
+ * @retval #DOWNLOAD_ERROR_NOT_SUPPORTED     Not supported
+ * @retval #DOWNLOAD_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #DOWNLOAD_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #DOWNLOAD_ERROR_ID_NOT_FOUND      No download ID
+ *
+ * @see download_set_cache_lifecycle()
+ */
+int download_get_cache_lifecycle(unsigned int *time);
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_WEB_DOWNLOAD_EXTENSION_H__ */
index 522b94d..8883b5b 100755 (executable)
@@ -1,6 +1,6 @@
 Name:  capi-web-url-download
 Summary:       CAPI for content download with web url
-Version:       1.2.11
+Version:       1.2.12
 Release:       0
 Group:         Development/Libraries
 License:       Apache-2.0
@@ -88,6 +88,7 @@ genhtml %{name}.info -o out --legend --show-details
 %{_includedir}/web/download.h
 %{_includedir}/web/download_product.h
 %{_includedir}/web/download_private.h
+%{_includedir}/web/download_extension.h
 %exclude %{_includedir}/web/download_doc.h
 
 %if 0%{?gcov:1}
index 4506d90..2627c21 100755 (executable)
@@ -9,6 +9,7 @@
 #include <unistd.h>
 
 #include <download.h>
+#include <download_extension.h>
 #include <download_private.h>
 #include <download-provider-interface.h>
 
@@ -448,3 +449,162 @@ int download_set_verify_host(int download_id, bool enable)
        CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
        return dp_interface_set_verify_host(download_id, (int)enable);
 }
+
+int download_set_cache(int download_id, bool enable)
+{
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       return dp_interface_set_cache(download_id, enable);
+}
+
+int download_get_cache(int download_id, bool *enable)
+{
+       int is_set = 0;
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       if (enable == NULL) {
+               TRACE_ERROR("Parameter NULL Check");
+               return DOWNLOAD_ERROR_INVALID_PARAMETER;
+       }
+       int ret = dp_interface_get_cache(download_id, &is_set);
+       if (ret == DOWNLOAD_ADAPTOR_ERROR_NONE)
+               *enable = (bool)is_set;
+       return ret;
+}
+
+int download_reset_cache(void)
+{
+       int id, ret;
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       ret = dp_interface_create(&id);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE)
+               return ret;
+       ret = dp_interface_reset_cache(id);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE) {
+               dp_interface_destroy(id);
+               return ret;
+       }
+       return dp_interface_destroy(id);
+}
+
+int download_set_cache_max_size(unsigned int size)
+{
+       int id, ret;
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       ret = dp_interface_create(&id);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE)
+               return ret;
+       ret = dp_interface_set_cache_max_size(id, size);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE) {
+               dp_interface_destroy(id);
+               return ret;
+       }
+       return dp_interface_destroy(id);
+}
+
+int download_get_cache_max_size(unsigned int *size)
+{
+       int id, ret;
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       if (size == NULL)
+               return DOWNLOAD_ERROR_INVALID_PARAMETER;
+
+       ret = dp_interface_create(&id);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE)
+               return ret;
+       ret = dp_interface_get_cache_max_size(id, size);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE) {
+               dp_interface_destroy(id);
+               return ret;
+       }
+       return dp_interface_destroy(id);
+}
+
+int download_reset_all_cache(void)
+{
+       int id, ret;
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       ret = dp_interface_create(&id);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE)
+               return ret;
+       ret = dp_interface_reset_all_cache(id);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE) {
+               dp_interface_destroy(id);
+               return ret;
+       }
+       return dp_interface_destroy(id);
+}
+
+int download_set_cache_path(const char *path)
+{
+       int id, ret;
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       ret = dp_interface_create(&id);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE)
+               return ret;
+       ret = dp_interface_set_cache_path(id, path);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE) {
+               dp_interface_destroy(id);
+               return ret;
+       }
+       return dp_interface_destroy(id);
+}
+
+int download_get_cache_path(char **path)
+{
+       int id, ret;
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       if (path == NULL)
+               return DOWNLOAD_ERROR_INVALID_PARAMETER;
+
+       ret = dp_interface_create(&id);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE)
+               return ret;
+       ret = dp_interface_get_cache_path(id, path);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE) {
+               dp_interface_destroy(id);
+               return ret;
+       }
+       return dp_interface_destroy(id);
+}
+
+int download_set_cache_lifecycle(unsigned int time)
+{
+       int id, ret;
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       ret = dp_interface_create(&id);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE)
+               return ret;
+       ret = dp_interface_set_cache_lifecycle(id, time);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE) {
+               dp_interface_destroy(id);
+               return ret;
+       }
+       return dp_interface_destroy(id);
+}
+
+int download_get_cache_lifecycle(unsigned int *time)
+{
+       int id, ret;
+       TRACE_INFO("");
+       CHECK_FEATURE_SUPPORTED(DOWNLOAD_FEATURE);
+       if (time == NULL)
+               return DOWNLOAD_ERROR_INVALID_PARAMETER;
+
+       ret = dp_interface_create(&id);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE)
+               return ret;
+       ret = dp_interface_get_cache_lifecycle(id, time);
+       if (ret != DOWNLOAD_ADAPTOR_ERROR_NONE) {
+               dp_interface_destroy(id);
+               return ret;
+       }
+       return dp_interface_destroy(id);
+}