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;
{ "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 },
};
#include <time.h>
#include <sqlite3.h>
#include "const.h"
+#include "edbus-handler.h"
#ifndef CLOCK_BOOTTIME
#define CLOCK_BOOTTIME 7
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);
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;
}
}
+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;