Add support of app_id in GetAll method call on statistics interface 17/209617/2
authorNishant Chaprana <n.chaprana@samsung.com>
Tue, 9 Jul 2019 09:23:05 +0000 (14:53 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Tue, 9 Jul 2019 09:41:47 +0000 (15:11 +0530)
Change-Id: I8afdfedd60ee2ce1b6708eec4034119dd405f85a
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
packaging/stc-manager.spec
src/database/include/table-statistics.h
src/database/tables/table-statistics.c
src/stc-statistics.c

index 55396af..4228bd8 100644 (file)
@@ -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
index 284fb48..a510f32 100755 (executable)
@@ -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);
 
index 719b9a2..7d13a3f 100755 (executable)
@@ -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)
 {
index 0d5a761..9c0559b 100755 (executable)
@@ -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__;