added low memory event
authorsungmin ha <sungmin82.ha@samsung.com>
Mon, 6 Apr 2015 08:06:36 +0000 (17:06 +0900)
committersungmin ha <sungmin82.ha@samsung.com>
Tue, 21 Apr 2015 09:41:05 +0000 (18:41 +0900)
Change-Id: I2d61c3d1836279b3a37c7406c88d08154805a940
Signed-off-by: sungmin ha <sungmin82.ha@samsung.com>
include/emuld.h
include/mobile.h
include/tv.h
packaging/emuld.spec
src/common.cpp
src/emuld.cpp
src/mobile.cpp
src/tv.cpp
src/wearable.cpp

index d0f4cb571d4bafacc8a94820ef127402ad5bfe68..73b2bdd21e4abb0bde0b73cd427652397bcca335 100644 (file)
 #ifndef __EMULD_H__
 #define __EMULD_H__
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
 #include <sys/epoll.h>
+#include <vconf.h>
+#include <iostream>
+#include <cassert>
 
 #include <map>
 
@@ -62,6 +66,7 @@ enum
 #define TID_SDCARD          2
 #define TID_LOCATION        3
 #define TID_HDS             4
+#define TID_VCONF           6
 
 extern pthread_t tid[MAX_CLIENT + 1];
 extern int g_fd[fdtype_max];
@@ -181,6 +186,7 @@ int recv_data(int event_fd, char** r_databuf, int size);
 void recv_from_evdi(evdi_fd fd);
 bool accept_proc(const int server_fd);
 
+void set_vconf_cb(void);
 void send_to_ecs(const char* cat, int group, int action, char* data);
 void send_emuld_connection(void);
 void send_default_suspend_req(void);
@@ -195,6 +201,7 @@ int parse_val(char *buff, unsigned char data, char *parsbuf);
 #define IJTYPE_CMD          "cmd"
 #define IJTYPE_PACKAGE      "package"
 #define IJTYPE_BOOT         "boot"
+#define IJTYPE_VCONF        "vconf"
 
 void msgproc_suspend(ijcommand* ijcmd);
 void msgproc_system(ijcommand* ijcmd);
@@ -206,10 +213,56 @@ void msgproc_location(ijcommand* ijcmd);
 void msgproc_sdcard(ijcommand* ijcmd);
 void* exec_cmd_thread(void *args);
 void msgproc_cmd(ijcommand* ijcmd);
+void msgproc_vconf(ijcommand* ijcmd);
+
+#define GROUP_MEMORY        30
+
+/* common vconf keys */
+#define VCONF_LOW_MEMORY    "memory/sysman/low_memory"
+#define VCONF_REPLAYMODE    "db/location/replay/ReplayMode"
+#define VCONF_FILENAME      "db/location/replay/FileName"
+#define VCONF_MLATITUDE     "db/location/replay/ManualLatitude"
+#define VCONF_MLONGITUDE    "db/location/replay/ManualLongitude"
+#define VCONF_MALTITUDE     "db/location/replay/ManualAltitude"
+#define VCONF_MHACCURACY    "db/location/replay/ManualHAccuracy"
+
+#define VCONF_SET 1
+#define VCONF_GET 0
+
+enum VCONF_TYPE {
+    SENSOR    = 0,
+    TELEPHONY = 1,
+    LOCATION  = 2,
+    TV        = 3,
+    MEMORY    = 4
+};
+
+struct vconf_res_type {
+    char *vconf_key;
+    char *vconf_val;
+    int group;
+    vconf_t vconf_type;
+};
+
+void add_vconf_map(VCONF_TYPE key, std::string value);
+void add_vconf_map_common(void);
+bool check_possible_vconf_key(std::string key);
 
 /*
  * For the multi-profile
  */
 bool extra_evdi_command(ijcommand* ijcmd);
+void add_vconf_map_profile(void);
+int get_vconf_status(char** value, vconf_t type, const char* key);
+
+static inline char* __tmpalloc(const int size)
+{
+    char* message = (char*)malloc(sizeof(char) * size);
+    if (!message) {
+        return NULL;
+    }
+    memset(message, 0, sizeof(char) * size);
+    return message;
+}
 
 #endif
index 004641857f53a665b0bdb2c43e290ea896095e8e..f2f32ac5e58a29a2abb63f7a3f8c6dfe46f4fe3f 100644 (file)
 
 #define IJTYPE_SENSOR       "sensor"
 
+#define VCONF_DBTAP      "memory/private/sensor/800004"
+#define VCONF_SHAKE      "memory/private/sensor/800002"
+#define VCONF_SNAP       "memory/private/sensor/800001"
+#define VCONF_MOVETOCALL "memory/private/sensor/800020"
+
+#define VCONF_RSSI       "memory/telephony/rssi"
+
 void msgproc_sensor(ijcommand* ijcmd);
 
 #endif
index 47703af8ebc0fa497dfbee2ac5a1be82531983f7..14d2b55973132b661c0b843f60f88cf7c9a84577 100644 (file)
 #define IJTYPE_VOICE        "voice"
 #define IJTYPE_EI           "ei"
 
+#define VCONF_HDMI1 "memory/sysman/hdmi1"
+#define VCONF_HDMI2 "memory/sysman/hdmi2"
+#define VCONF_HDMI3 "memory/sysman/hdmi3"
+#define VCONF_HDMI4 "memory/sysman/hdmi4"
+#define VCONF_AV1   "memory/sysman/av1"
+#define VCONF_AV2   "memory/sysman/av1"
+#define VCONF_COMP1 "memory/sysman/comp1"
+#define VCONF_COMP2 "memory/sysman/comp1"
+
 bool msgproc_gesture(ijcommand* ijcmd);
 bool msgproc_voice(ijcommand* ijcmd);
 bool msgproc_extinput(ijcommand* ijcmd);
index 82c68b603326bdbfd0a139e35f71571d6de97d22..3d3185c42d3ca4859fcbf6fc52894fafa4adf148 100644 (file)
@@ -1,5 +1,5 @@
 Name: emuld
-Version: 0.9.0
+Version: 0.9.1
 Release: 0
 Summary: Emulator daemon
 License: Apache-2.0
index ce1e258764abb24e8d0b56ba424d63862a367f0a..05bd34d4fa49f23399165e2e3e798509646efb48 100644 (file)
@@ -34,6 +34,7 @@
 #include <stdio.h>
 #include <unistd.h>
 #include <errno.h>
+#include <utility>
 
 #include <E_DBus.h>
 #include <Ecore.h>
@@ -43,7 +44,6 @@
 #include <stdlib.h>
 #include <mntent.h>
 
-#include <vconf.h>
 #include <vconf-keys.h>
 
 #include "emuld.h"
@@ -65,6 +65,39 @@ static pthread_mutex_t mutex_cmd = PTHREAD_MUTEX_INITIALIZER;
 
 static struct timeval tv_start_poweroff;
 
+static std::multimap<int, std::string> vconf_multimap;
+
+void add_vconf_map(VCONF_TYPE key, std::string value)
+{
+    vconf_multimap.insert(std::pair<int, std::string>(key, value));
+}
+
+void add_vconf_map_common(void)
+{
+    /* location */
+    add_vconf_map(LOCATION, VCONF_REPLAYMODE);
+    add_vconf_map(LOCATION, VCONF_FILENAME);
+    add_vconf_map(LOCATION, VCONF_MLATITUDE);
+    add_vconf_map(LOCATION, VCONF_MLONGITUDE);
+    add_vconf_map(LOCATION, VCONF_MALTITUDE);
+    add_vconf_map(LOCATION, VCONF_MHACCURACY);
+
+    /* memory */
+    add_vconf_map(MEMORY, VCONF_LOW_MEMORY);
+}
+
+bool check_possible_vconf_key(std::string key)
+{
+    std::multimap<int, std::string>::iterator it;
+    for(it = vconf_multimap.begin(); it != vconf_multimap.end(); it++) {
+        if (it->second.compare(key) == 0) {
+            return true;
+        }
+    }
+
+    return false;
+}
+
 void systemcall(const char* param)
 {
     if (!param)
@@ -440,7 +473,6 @@ void* dbus_booting_done_check(void* data)
 char SDpath[256];
 
 // Location
-#define STATUS              15
 #define LOCATION_STATUS     120
 char command[512];
 
@@ -795,12 +827,217 @@ void msgproc_cmd(ijcommand* ijcmd)
     strncpy(cmd, ijcmd->data, ijcmd->msg.length);
     LOGDEBUG("cmd: %s, length: %d", cmd, ijcmd->msg.length);
 
-    if (pthread_create(&cmd_thread_id, NULL, exec_cmd_thread, (void*)cmd) != 0)
-    {
+    if (pthread_create(&cmd_thread_id, NULL, exec_cmd_thread, (void*)cmd) != 0) {
         LOGERR("cmd pthread create fail!");
     }
 }
 
+int get_vconf_status(char** value, vconf_t type, const char* key)
+{
+    if (type == VCONF_TYPE_INT) {
+        int status;
+        int ret = vconf_get_int(key, &status);
+        if (ret != 0) {
+            LOGERR("cannot get vconf key - %s", key);
+            return 0;
+        }
+
+        ret = asprintf(value, "%d", status);
+        if (ret == -1) {
+            LOGERR("insufficient memory available");
+            return 0;
+        }
+    } else if (type == VCONF_TYPE_DOUBLE) {
+        LOGERR("not implemented");
+        assert(type == VCONF_TYPE_INT);
+        return 0;
+    } else if (type == VCONF_TYPE_STRING) {
+        LOGERR("not implemented");
+        assert(type == VCONF_TYPE_INT);
+        return 0;
+    } else if (type == VCONF_TYPE_BOOL) {
+        LOGERR("not implemented");
+        assert(type == VCONF_TYPE_INT);
+        return 0;
+    } else if (type == VCONF_TYPE_DIR) {
+        LOGERR("not implemented");
+        assert(type == VCONF_TYPE_INT);
+        return 0;
+    } else {
+        LOGERR("undefined vconf type");
+        assert(type == VCONF_TYPE_INT);
+        return 0;
+    }
+
+    return strlen(*value);
+}
+
+static void* get_vconf_value(void* data)
+{
+    pthread_detach(pthread_self());
+
+    char *value = NULL;
+    vconf_res_type *vrt = (vconf_res_type*)data;
+
+    if (!check_possible_vconf_key(vrt->vconf_key)) {
+        LOGERR("%s is not available key.");
+    } else {
+        int length = get_vconf_status(&value, vrt->vconf_type, vrt->vconf_key);
+        if (length == 0 || !value) {
+            LOGERR("send error message to injector");
+            send_to_ecs(IJTYPE_VCONF, vrt->group, STATUS, NULL);
+        } else {
+            LOGDEBUG("send data to injector");
+            send_to_ecs(IJTYPE_VCONF, vrt->group, STATUS, value);
+            free(value);
+        }
+    }
+
+    free(vrt->vconf_key);
+    free(vrt);
+
+    pthread_exit((void *) 0);
+}
+
+static void* set_vconf_value(void* data)
+{
+    pthread_detach(pthread_self());
+
+    vconf_res_type *vrt = (vconf_res_type*)data;
+
+    if (!check_possible_vconf_key(vrt->vconf_key)) {
+        LOGERR("%s is not available key.");
+    } else {
+        keylist_t *get_keylist;
+        keynode_t *pkey_node = NULL;
+        get_keylist = vconf_keylist_new();
+        if (!get_keylist) {
+            LOGERR("vconf_keylist_new() failed");
+        } else {
+            vconf_get(get_keylist, vrt->vconf_key, VCONF_GET_ALL);
+            int ret = vconf_keylist_lookup(get_keylist, vrt->vconf_key, &pkey_node);
+            if (ret == 0) {
+                LOGERR("%s key not found", vrt->vconf_key);
+            } else {
+                if (vconf_keynode_get_type(pkey_node) != vrt->vconf_type) {
+                    LOGERR("inconsistent type (prev: %d, new: %d)",
+                                vconf_keynode_get_type(pkey_node), vrt->vconf_type);
+                }
+            }
+            vconf_keylist_free(get_keylist);
+        }
+
+        /* TODO: to be implemented another type */
+        if (vrt->vconf_type == VCONF_TYPE_INT) {
+            int val = atoi(vrt->vconf_val);
+            vconf_set_int(vrt->vconf_key, val);
+            LOGDEBUG("key: %s, val: %d", vrt->vconf_key, val);
+        } else if (vrt->vconf_type == VCONF_TYPE_DOUBLE) {
+            LOGERR("not implemented");
+        } else if (vrt->vconf_type == VCONF_TYPE_STRING) {
+            LOGERR("not implemented");
+        } else if (vrt->vconf_type == VCONF_TYPE_BOOL) {
+            LOGERR("not implemented");
+        } else if (vrt->vconf_type == VCONF_TYPE_DIR) {
+            LOGERR("not implemented");
+        } else {
+            LOGERR("undefined vconf type");
+        }
+    }
+
+    free(vrt->vconf_key);
+    free(vrt->vconf_val);
+    free(vrt);
+
+    pthread_exit((void *) 0);
+}
+
+void msgproc_vconf(ijcommand* ijcmd)
+{
+    LOGDEBUG("msgproc_vconf");
+
+    const int tmpsize = ijcmd->msg.length;
+    char token[] = "\n";
+    char tmpdata[tmpsize];
+    memcpy(tmpdata, ijcmd->data, tmpsize);
+
+    char* ret = NULL;
+    ret = strtok(tmpdata, token);
+    if (!ret) {
+        LOGERR("vconf type is empty");
+        return;
+    }
+
+    vconf_res_type *vrt = (vconf_res_type*)malloc(sizeof(vconf_res_type));
+    if (!vrt) {
+        LOGERR("insufficient memory available");
+        return;
+    }
+
+    if (strcmp(ret, "int") == 0) {
+        vrt->vconf_type = VCONF_TYPE_INT;
+    } else if (strcmp(ret, "double") == 0) {
+        vrt->vconf_type = VCONF_TYPE_DOUBLE;
+    } else if (strcmp(ret, "string") == 0) {
+        vrt->vconf_type = VCONF_TYPE_STRING;
+    } else if (strcmp(ret, "bool") == 0) {
+        vrt->vconf_type = VCONF_TYPE_BOOL;
+    } else if (strcmp(ret, "dir") ==0) {
+        vrt->vconf_type = VCONF_TYPE_DIR;
+    } else {
+        LOGERR("undefined vconf type");
+        free(vrt);
+        return;
+    }
+
+    ret = strtok(NULL, token);
+    if (!ret) {
+        LOGERR("vconf key is empty");
+        free(vrt);
+        return;
+    }
+
+    vrt->vconf_key = (char*)malloc(strlen(ret) + 1);
+    if (!vrt->vconf_key) {
+        LOGERR("insufficient memory available");
+        free(vrt);
+        return;
+    }
+    sprintf(vrt->vconf_key, "%s", ret);
+
+    if (ijcmd->msg.action == VCONF_SET) {
+        ret = strtok(NULL, token);
+        if (!ret) {
+            LOGERR("vconf value is empty");
+            free(vrt->vconf_key);
+            free(vrt);
+            return;
+        }
+
+        vrt->vconf_val = (char*)malloc(strlen(ret) + 1);
+        if (!vrt->vconf_val) {
+            LOGERR("insufficient memory available");
+            free(vrt->vconf_key);
+            free(vrt);
+            return;
+        }
+        sprintf(vrt->vconf_val, "%s", ret);
+
+        if (pthread_create(&tid[TID_VCONF], NULL, set_vconf_value, (void*)vrt) != 0) {
+            LOGERR("set vconf pthread create fail!");
+            return;
+        }
+    } else if (ijcmd->msg.action == VCONF_GET) {
+        vrt->group = ijcmd->msg.group;
+        if (pthread_create(&tid[TID_VCONF], NULL, get_vconf_value, (void*)vrt) != 0) {
+            LOGERR("get vconf pthread create fail!");
+            return;
+        }
+    } else {
+        LOGERR("undefined action %d", ijcmd->msg.action);
+    }
+}
+
 /*
  * Location function
  */
@@ -1148,3 +1385,36 @@ void msgproc_hds(ijcommand* ijcmd)
     }
 }
 
+static void low_memory_cb(keynode_t* pKey, void* pData)
+{
+    switch (vconf_keynode_get_type(pKey)) {
+        case VCONF_TYPE_INT:
+        {
+            int value = vconf_keynode_get_int(pKey);
+            LOGDEBUG("key = %s, value = %d(int)", vconf_keynode_get_name(pKey), value);
+            char *buf = (char*)malloc(sizeof(int));
+            if (!buf) {
+                LOGERR("insufficient memory available");
+                return;
+            }
+
+            sprintf(buf, "%d", vconf_keynode_get_int(pKey));
+            send_to_ecs(IJTYPE_VCONF, GROUP_MEMORY, STATUS, buf);
+
+            free(buf);
+            break;
+        }
+        default:
+            LOGERR("type mismatch in key: %s", vconf_keynode_get_name(pKey));
+            break;
+    }
+}
+
+void set_vconf_cb(void)
+{
+    int ret = 0;
+    ret = vconf_notify_key_changed(VCONF_LOW_MEMORY, low_memory_cb, NULL);
+    if (ret) {
+        LOGERR("vconf_notify_key_changed() failed");
+    }
+}
index 2517ae6df3c97026eff99c478c1da2d298493b61..c7122fd514a28495c9ca72451b2bc0a90d656c64 100644 (file)
@@ -177,6 +177,10 @@ static void process_evdi_command(ijcommand* ijcmd)
     {
         msgproc_cmd(ijcmd);
     }
+    else if (strcmp(ijcmd->cmd, IJTYPE_VCONF) == 0)
+    {
+        msgproc_vconf(ijcmd);
+    }
     else
     {
         if (!extra_evdi_command(ijcmd)) {
@@ -358,6 +362,10 @@ int main( int argc , char *argv[])
 
     LOGINFO("[START] epoll & device init success");
 
+    add_vconf_map_common();
+    add_vconf_map_profile();
+    set_vconf_cb();
+
     send_emuld_connection();
 
     send_default_suspend_req();
index fa1fb3b9aa63bf79ee568fb52554b05ade05dd50..d777911fb761e56875f165935a01be6839c8ee80 100644 (file)
@@ -27,8 +27,6 @@
  *
  */
 
-#include <stdio.h>
-#include <vconf/vconf.h>
 #include <vconf/vconf-keys.h>
 
 #include "emuld.h"
@@ -445,31 +443,10 @@ void setting_sensor(char *buffer)
     }
 }
 
-
-static int inline get_vconf_status(char* msg, const char* key, int buf_len)
-{
-    int status;
-    int ret = vconf_get_int(key, &status);
-    if (ret != 0) {
-        LOGERR("cannot get vconf key - %s", key);
-        return -1;
-    }
-
-    sprintf(msg, "%d", status);
-    return strlen(msg);
-}
-
-char* __tmpalloc(const int size)
-{
-    char* message = (char*)malloc(sizeof(char) * size);
-    memset(message, 0, sizeof(char) * size);
-    return message;
-}
-
 char* get_rssi_level(void* p)
 {
-    char* message = __tmpalloc(5);
-    int length = get_vconf_status(message, "memory/telephony/rssi", 5);
+    char* message = NULL;
+    int length = get_vconf_status(&message, VCONF_TYPE_INT, "memory/telephony/rssi");
     if (length < 0){
         return 0;
     }
@@ -596,3 +573,15 @@ bool extra_evdi_command(ijcommand* ijcmd) {
     }
     return false;
 }
+
+void add_vconf_map_profile(void)
+{
+    /* sensor */
+    add_vconf_map(SENSOR, VCONF_DBTAP);
+    add_vconf_map(SENSOR, VCONF_SHAKE);
+    add_vconf_map(SENSOR, VCONF_SNAP);
+    add_vconf_map(SENSOR, VCONF_MOVETOCALL);
+
+    /* telephony */
+    add_vconf_map(TELEPHONY, VCONF_RSSI);
+}
index 57f0d3dc62c8573ad02be11b6a5d477c7ad4cf7b..f6c523174a72ad2a98d66195a2c5335879d75f26 100644 (file)
@@ -525,3 +525,16 @@ bool extra_evdi_command(ijcommand* ijcmd) {
 
     return false;
 }
+
+void add_vconf_map_profile(void)
+{
+    /* tv */
+    add_vconf_map(TV, VCONF_HDMI1);
+    add_vconf_map(TV, VCONF_HDMI2);
+    add_vconf_map(TV, VCONF_HDMI3);
+    add_vconf_map(TV, VCONF_HDMI4);
+    add_vconf_map(TV, VCONF_AV1);
+    add_vconf_map(TV, VCONF_AV2);
+    add_vconf_map(TV, VCONF_COMP1);
+    add_vconf_map(TV, VCONF_COMP2);
+}
index 7e62a375864f6105e6782166cc611a492ea98876..9ba76d995becf455fd049233ace45bcf9c7ce6a4 100644 (file)
@@ -298,3 +298,7 @@ bool extra_evdi_command(ijcommand* ijcmd) {
     }
     return false;
 }
+
+void add_vconf_map_profile(void)
+{
+}