From: sungmin ha Date: Mon, 6 Apr 2015 08:06:36 +0000 (+0900) Subject: added low memory event X-Git-Tag: submit/tizen/20150527.025434^2~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b26cf5b4489bb411a66a59bc9ffd60d0d1c20a7d;p=platform%2Fadaptation%2Femulator%2Femulator-daemon.git added low memory event Change-Id: I2d61c3d1836279b3a37c7406c88d08154805a940 Signed-off-by: sungmin ha --- diff --git a/include/emuld.h b/include/emuld.h index d0f4cb5..73b2bdd 100644 --- a/include/emuld.h +++ b/include/emuld.h @@ -31,10 +31,14 @@ #ifndef __EMULD_H__ #define __EMULD_H__ +#include #include #include #include #include +#include +#include +#include #include @@ -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 diff --git a/include/mobile.h b/include/mobile.h index 0046418..f2f32ac 100644 --- a/include/mobile.h +++ b/include/mobile.h @@ -34,6 +34,13 @@ #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 diff --git a/include/tv.h b/include/tv.h index 47703af..14d2b55 100644 --- a/include/tv.h +++ b/include/tv.h @@ -34,6 +34,15 @@ #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); diff --git a/packaging/emuld.spec b/packaging/emuld.spec index 82c68b6..3d3185c 100644 --- a/packaging/emuld.spec +++ b/packaging/emuld.spec @@ -1,5 +1,5 @@ Name: emuld -Version: 0.9.0 +Version: 0.9.1 Release: 0 Summary: Emulator daemon License: Apache-2.0 diff --git a/src/common.cpp b/src/common.cpp index ce1e258..05bd34d 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,6 @@ #include #include -#include #include #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 vconf_multimap; + +void add_vconf_map(VCONF_TYPE key, std::string value) +{ + vconf_multimap.insert(std::pair(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::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"); + } +} diff --git a/src/emuld.cpp b/src/emuld.cpp index 2517ae6..c7122fd 100644 --- a/src/emuld.cpp +++ b/src/emuld.cpp @@ -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(); diff --git a/src/mobile.cpp b/src/mobile.cpp index fa1fb3b..d777911 100644 --- a/src/mobile.cpp +++ b/src/mobile.cpp @@ -27,8 +27,6 @@ * */ -#include -#include #include #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); +} diff --git a/src/tv.cpp b/src/tv.cpp index 57f0d3d..f6c5231 100644 --- a/src/tv.cpp +++ b/src/tv.cpp @@ -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); +} diff --git a/src/wearable.cpp b/src/wearable.cpp index 7e62a37..9ba76d9 100644 --- a/src/wearable.cpp +++ b/src/wearable.cpp @@ -298,3 +298,7 @@ bool extra_evdi_command(ijcommand* ijcmd) { } return false; } + +void add_vconf_map_profile(void) +{ +}