Add some APIs to clone and destroy statistics info 19/200119/5
authorhyunuktak <hyunuk.tak@samsung.com>
Tue, 19 Feb 2019 08:56:44 +0000 (17:56 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Mon, 25 Feb 2019 05:12:17 +0000 (05:12 +0000)
Change-Id: I91852bf3986e0765b67bed361d841a1f06bf70b8
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
include/stc.h
src/stc-info.c

index 7cd58c5..0b84c17 100755 (executable)
@@ -697,6 +697,43 @@ int stc_stats_rule_get_time_period(stc_stats_rule_h rule,
                stc_time_period_e *time_period);
 
 /**
+ * @brief Clones the statistics info handle.
+ * @since_tizen 5.5
+ * @remarks You must release @a cloned using stc_stats_info_destroy().
+ *
+ * @param[in] info            The origin statistics info handle
+ * @param[out] cloned         The cloned statistics info handle
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #STC_ERROR_NONE                    Successful
+ * @retval #STC_ERROR_OUT_OF_MEMORY           Out of memory
+ * @retval #STC_ERROR_INVALID_PARAMETER       Invalid parameter
+ * @retval #STC_ERROR_NOT_SUPPORTED           Not supported
+ *
+ * @see stc_h
+ * @see stc_stats_info_h
+ * @see stc_initialize()
+ * @see stc_stats_info_destroy()
+ */
+int stc_stats_info_clone(stc_stats_info_h info, stc_stats_info_h *cloned);
+
+/**
+ * @brief Destroys the statistics info handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] info          The statistics info handle
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #STC_ERROR_NONE                    Successful
+ * @retval #STC_ERROR_INVALID_PARAMETER       Invalid parameter
+ * @retval #STC_ERROR_NOT_SUPPORTED           Not supported
+ *
+ * @see stc_stats_info_h
+ * @see stc_stats_info_clone()
+ */
+int stc_stats_info_destroy(stc_stats_info_h info);
+
+/**
  * @brief Gets the application ID from statistics information.
  * @since_tizen 4.0
  * @remarks You must release @a app_id using free().
index affbe89..140144d 100755 (executable)
  *  Local Functions Definition
  *****************************************************************************/
 
+EXPORT_API int stc_stats_info_clone(stc_stats_info_h info, stc_stats_info_h *cloned)
+{
+       CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC);
+
+       if (info == NULL || cloned == NULL) {
+               STC_LOGE("Invalid parameter");
+               return STC_ERROR_INVALID_PARAMETER;
+       }
+
+       stc_stats_info_s *stats_info = MALLOC0(stc_stats_info_s, 1);
+       if (!stats_info) {
+               STC_LOGE("Memory allocation failed");
+               return STC_ERROR_OUT_OF_MEMORY;
+       }
+
+       stc_stats_info_s *origin_info = (stc_stats_info_s *)info;
+
+       g_strlcpy(stats_info->app_id, origin_info->app_id, STC_APP_ID_LEN);
+       g_strlcpy(stats_info->iface_name, origin_info->iface_name, STC_IFNAME_LEN);
+       g_strlcpy(stats_info->subscriber_id, origin_info->subscriber_id, STC_SUBSCRIBER_ID_LEN);
+       stats_info->interval.from = origin_info->interval.from;
+       stats_info->interval.to = origin_info->interval.to;
+       stats_info->iface_type = origin_info->iface_type;
+       stats_info->cnt.incoming_bytes = origin_info->cnt.incoming_bytes;
+       stats_info->cnt.outgoing_bytes = origin_info->cnt.outgoing_bytes;
+       stats_info->roaming_type = origin_info->roaming_type;
+       stats_info->protocol_type = origin_info->protocol_type;
+       stats_info->process_state = origin_info->process_state;
+
+       *cloned = (stc_stats_info_h)stats_info;
+
+       STC_LOGI("Stats info successfully cloned");
+
+       return STC_ERROR_NONE;
+}
+
+EXPORT_API int stc_stats_info_destroy(stc_stats_info_h info)
+{
+       CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC);
+
+       if (info == NULL) {
+               STC_LOGE("Invalid parameter");
+               return STC_ERROR_INVALID_PARAMETER;
+       }
+
+       FREE(info);
+
+       STC_LOGI("Stats rule successfully destroyed");
+
+       return STC_ERROR_NONE;
+}
+
 EXPORT_API int stc_stats_info_get_app_id(stc_stats_info_h info, char **app_id)
 {
        CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC);