heart : add dbus method about HEART-CPU sync 84/106284/2 accepted/tizen/3.0/common/20161223.110548 accepted/tizen/3.0/ivi/20161223.081345 accepted/tizen/3.0/mobile/20161223.081300 accepted/tizen/3.0/tv/20161223.081316 accepted/tizen/3.0/wearable/20161223.081322 submit/tizen_3.0/20161222.085113
authorKichan Kwon <k_c.kwon@samsung.com>
Wed, 21 Dec 2016 08:10:31 +0000 (17:10 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 21 Dec 2016 08:14:30 +0000 (17:14 +0900)
- org.tizen.resourced.logging.SyncCpuData
- It will update cache and write into the DB
- Return value : 0(success), -1(fail), TID(running)

Change-Id: Ic7fc4b8f3dc86a4b6ccd38ee1db7e2789b8e9589
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/heart/heart-cpu.c
src/heart/include/logging.h
src/heart/logging.c

index f17dea2..f6a6aff 100644 (file)
@@ -1408,6 +1408,26 @@ static DBusMessage *edbus_heart_update_cpu_data(E_DBus_Object *obj, DBusMessage
        return reply;
 }
 
+static DBusMessage *edbus_heart_sync_cpu_data(E_DBus_Object *obj, DBusMessage *msg)
+{
+       int ret = 0;
+       DBusMessage *reply;
+       DBusMessageIter iter;
+
+       heart_cpu_update_app_list(NULL);
+
+       reply = dbus_message_new_method_return(msg);
+
+       ret = logging_sync_and_reply(reply);
+       if (!ret)
+               return NULL;
+       ret = -ret;
+
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
 static DBusMessage *edbus_heart_save_to_file(E_DBus_Object *obj, DBusMessage *msg)
 {
        int ret;
@@ -1442,6 +1462,7 @@ static struct edbus_method edbus_methods[] = {
        { "GetCpuDataList",  "ii",   "a(sii)", edbus_heart_get_cpu_data_list },
        { "ResetCpuData",    NULL,   "i",      edbus_heart_reset_cpu_data },
        { "UpdateCpuData",   NULL,   "i",      edbus_heart_update_cpu_data },
+       { "SyncCpuData",     NULL,   "i",      edbus_heart_sync_cpu_data },
        { "SaveCpuData",     NULL,   "i",      edbus_heart_save_to_file },
 };
 
index 2e269ad..f9862ac 100644 (file)
@@ -29,6 +29,7 @@
 #include <time.h>
 #include <sqlite3.h>
 #include "const.h"
+#include "edbus-handler.h"
 
 #ifndef CLOCK_BOOTTIME
 #define CLOCK_BOOTTIME                          7
@@ -130,6 +131,7 @@ int logging_read_foreach(char *name, char *appid, char *pkgid,
                time_t start_time, time_t end_time, logging_info_cb callback, void *user_data);
 void logging_update(int force);
 void logging_save_to_storage(int force);
+int logging_sync_and_reply(DBusMessage *reply);
 int logging_leveldb_put(char *key, unsigned int key_len, char *value, unsigned int value_len);
 int logging_leveldb_putv(char *key, unsigned int key_len, const char *fmt, ...);
 int logging_leveldb_read(char *key, unsigned int key_len, char *value, unsigned int value_len);
index 2652038..a83b4f2 100644 (file)
@@ -121,6 +121,8 @@ struct logging_listerner {
 
 static const struct module_ops logging_modules_ops;
 
+static pthread_t logging_sync_thread = 0;
+
 static pthread_t logging_data_thread = 0;
 static pthread_mutex_t logging_data_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t logging_data_cond = PTHREAD_COND_INITIALIZER;
@@ -1318,6 +1320,71 @@ void logging_save_to_storage(int force)
        }
 }
 
+static void *logging_sync_thread_main(void *arg)
+{
+       int ret = 0;
+       DBusMessage *reply = (DBusMessage *)arg;
+       DBusMessageIter iter;
+
+       ret = pthread_mutex_lock(&logging_data_mutex);
+       if (ret) {
+               _E("logging sync thread::pthread_mutex_lock() failed (%d)", ret);
+               ret = -1;
+               goto reply;
+       }
+
+       logging_save_to_storage(true);
+
+       ret = pthread_mutex_unlock(&logging_data_mutex);
+       if (ret) {
+               _E("logging sync thread::pthread_mutex_unlock() failed (%d)", ret);
+               ret = -1;
+               goto reply;
+       }
+
+       ret = pthread_mutex_lock(&logging_update_mutex);
+       if (ret) {
+               _E("logging sync thread::pthread_mutex_lock() failed (%d)", ret);
+               ret = -1;
+               goto reply;
+       }
+
+       logging_update(true);
+
+       ret = pthread_mutex_unlock(&logging_update_mutex);
+       if (ret) {
+               _E("logging sync thread::pthread_mutex_unlock() failed (%d)", ret);
+               ret = -1;
+       }
+
+reply:
+
+       logging_sync_thread = 0;
+
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+
+       if (dbus_message_reply(reply) != RESOURCED_ERROR_NONE)
+               _E("Failed to reply sync request");
+
+       return NULL;
+}
+
+int logging_sync_and_reply(DBusMessage *reply)
+{
+       if (logging_sync_thread) {
+               _I("logging sync thread %u is already running", (unsigned)logging_sync_thread);
+               return logging_sync_thread;
+       }
+
+       if (!pthread_create(&logging_sync_thread, NULL, (void *)logging_sync_thread_main, reply))
+               return 0;
+
+       _E("Failed to create logging sync thread");
+       logging_sync_thread = 0;
+       return -1;
+}
+
 static void *logging_data_thread_main(void *arg)
 {
        int ret = 0;