From 6e941f446a33913f02b02ffa42836dc4e48936ce Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Tue, 9 Jul 2019 14:53:05 +0530 Subject: [PATCH] Add support of app_id in GetAll method call on statistics interface Change-Id: I8afdfedd60ee2ce1b6708eec4034119dd405f85a Signed-off-by: Nishant Chaprana --- packaging/stc-manager.spec | 2 +- src/database/include/table-statistics.h | 3 ++- src/database/tables/table-statistics.c | 12 +++++++++--- src/stc-statistics.c | 9 ++++++++- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packaging/stc-manager.spec b/packaging/stc-manager.spec index 55396af..4228bd8 100644 --- a/packaging/stc-manager.spec +++ b/packaging/stc-manager.spec @@ -1,6 +1,6 @@ Name: stc-manager Summary: STC(Smart Traffic Control) manager -Version: 0.0.93 +Version: 0.0.94 Release: 0 Group: Network & Connectivity/Other License: Apache-2.0 diff --git a/src/database/include/table-statistics.h b/src/database/include/table-statistics.h index 284fb48..a510f32 100755 --- a/src/database/include/table-statistics.h +++ b/src/database/include/table-statistics.h @@ -37,6 +37,7 @@ typedef struct { } table_statistics_reset_rule; typedef struct { + char *app_id; time_t from; time_t to; stc_iface_type_e iftype; @@ -55,7 +56,7 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul void *user_data); stc_error_e table_statistics_per_app(const char *app_id, - table_statistics_select_rule *rule, + const table_statistics_select_rule *rule, table_statistics_info_cb info_cb, void *user_data); diff --git a/src/database/tables/table-statistics.c b/src/database/tables/table-statistics.c index 719b9a2..7d13a3f 100755 --- a/src/database/tables/table-statistics.c +++ b/src/database/tables/table-statistics.c @@ -440,13 +440,19 @@ stc_error_e table_statistics_foreach_app(const table_statistics_select_rule *rul bind parameters in the query */ stc_db_tm_interval_s interval; - memset(&data, 0, sizeof(data)); - if (!rule || !info_cb) { __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE } + memset(&data, 0, sizeof(data)); + + if (rule->app_id) { + int ret = table_statistics_per_app(rule->app_id, rule, info_cb, user_data); + __STC_LOG_FUNC_EXIT__; + return ret; + } + /* pick a statement depending on parameters */ if (rule->granularity) { stmt = __is_iftype_defined(rule->iftype) ? @@ -508,7 +514,7 @@ handle_error: } API stc_error_e table_statistics_per_app(const char *app_id, - table_statistics_select_rule *rule, + const table_statistics_select_rule *rule, table_statistics_info_cb info_cb, void *user_data) { diff --git a/src/stc-statistics.c b/src/stc-statistics.c index 0d5a761..9c0559b 100755 --- a/src/stc-statistics.c +++ b/src/stc-statistics.c @@ -76,6 +76,11 @@ void __stc_extract_select_rule(const char *key, GVariant *value, rule->iftype = g_variant_get_uint16(value); STC_LOGD("iftype: [%u]", (unsigned int) rule->iftype); + } else if (!g_strcmp0(key, "app_id")) { + gsize length = 0; + rule->app_id = g_variant_dup_string(value, &length); + STC_LOGD("app_id: [%s]", rule->app_id); + } else { STC_LOGD("Unknown select rule"); //LCOV_EXCL_LINE } @@ -277,6 +282,7 @@ gboolean handle_statistics_get_all(StcStatistics *object, if (ret < STC_ERROR_NONE) { g_variant_builder_unref(builder); //LCOV_EXCL_LINE STC_STATISTICS_DBUS_REPLY_ERROR(invocation, ret); //LCOV_EXCL_LINE + g_free(rule.app_id); __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE return TRUE; //LCOV_EXCL_LINE } @@ -287,12 +293,13 @@ gboolean handle_statistics_get_all(StcStatistics *object, DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters); STC_DBUS_REPLY(invocation, return_parameters); + g_free(rule.app_id); __STC_LOG_FUNC_EXIT__; return TRUE; } gboolean handle_statistics_init(StcStatistics *object, - GDBusMethodInvocation *invocation) + GDBusMethodInvocation *invocation) { __STC_LOG_FUNC_ENTER__; -- 2.7.4