From: hyunuktak Date: Tue, 19 Feb 2019 08:56:44 +0000 (+0900) Subject: Add some APIs to clone and destroy statistics info X-Git-Tag: submit/tizen/20190311.084912~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=09738c2e6f477f7327309d44359224ddd0a68bee;p=platform%2Fcore%2Fapi%2Fsmart-traffic-control.git Add some APIs to clone and destroy statistics info Change-Id: I16db33c7937239db0bbdae028c57147d59668854 Signed-off-by: hyunuktak --- diff --git a/include/stc.h b/include/stc.h index 80a599e..c9208df 100755 --- a/include/stc.h +++ b/include/stc.h @@ -784,6 +784,43 @@ int stc_stats_rule_get_iface_type(stc_stats_rule_h rule, 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 diff --git a/src/stc-info.c b/src/stc-info.c index affbe89..140144d 100755 --- a/src/stc-info.c +++ b/src/stc-info.c @@ -62,6 +62,58 @@ * 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);