Merge "Return errors to caller" into tizen_5.5
[platform/core/connectivity/stc-manager.git] / src / stc-statistics.c
index 70cf48c..feee566 100755 (executable)
@@ -21,9 +21,6 @@
 
 #define STATISTICS_DBUS_ERROR_NAME "net.stc.statistics.Error.Failed"
 
-#define STC_DBUS_REPLY(invocation, parameters) \
-       g_dbus_method_invocation_return_value((invocation), parameters);
-
 #define STC_STATISTICS_DBUS_REPLY_ERROR(invocation, err_num) \
        g_dbus_method_invocation_return_dbus_error((invocation), \
                                                   STATISTICS_DBUS_ERROR_NAME, \
@@ -36,7 +33,9 @@ static const gchar *stc_err_strs[] = {
        "OUT_OF_MEMORY",
        "INVALID_PARAMETER",
        "NO_DATA",
+       "ALREADY_DATA",
        "UNINITIALIZED",
+       "PERMISSION_DENIED",
        "NOTIMPL"
 };
 
@@ -77,6 +76,15 @@ 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 if (!g_strcmp0(key, "granularity")) {
+               rule->granularity = g_variant_get_int32(value);
+               STC_LOGD("granularity: [%d]", rule->granularity);
+
        } else {
                STC_LOGD("Unknown select rule"); //LCOV_EXCL_LINE
        }
@@ -248,6 +256,8 @@ gboolean handle_statistics_get_all(StcStatistics *object,
        GVariant *return_parameters = NULL;
        stc_error_e ret;
 
+       stc_set_keep_alive(TRUE);
+
        /* Total statistics since epoch */
        rule.from = epoch;
        rule.to = cur_time;
@@ -276,6 +286,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
        }
@@ -286,15 +297,18 @@ 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__;
 
+       stc_set_keep_alive(TRUE);
+
        STC_LOGI("stc statistics initialized");
        stc_statistics_complete_init(object, invocation);
 
@@ -316,6 +330,8 @@ gboolean handle_statistics_get(StcStatistics *object,
        GVariant *return_parameters = NULL;
        stc_error_e ret;
 
+       stc_set_keep_alive(TRUE);
+
        /* Total statistics since epoch */
        rule.from = epoch;
        rule.to = cur_time;
@@ -344,6 +360,7 @@ gboolean handle_statistics_get(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
        }
@@ -354,6 +371,7 @@ gboolean handle_statistics_get(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;
 }
@@ -368,6 +386,8 @@ gboolean handle_statistics_reset(StcStatistics *object,
        GVariant *return_parameters = NULL;
        stc_error_e ret;
 
+       stc_set_keep_alive(TRUE);
+
        if (reset_rule != NULL) {
                DEBUG_GDBUS_VARIANT("Selection rule: ", reset_rule);
                GVariantIter *iter = NULL;