From: Jinhyung Choi Date: Mon, 24 Oct 2016 06:35:04 +0000 (+0900) Subject: device: check capabilities from model-config.xml X-Git-Tag: submit/tizen/20161103.063935~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F00%2F93400%2F7;p=platform%2Fadaptation%2Femulator%2Femulator-daemon.git device: check capabilities from model-config.xml Change-Id: I77d2f920fcc5df6270cf59c9f00b6f9f9c78b655 Signed-off-by: Jinhyung Choi --- diff --git a/.gitignore b/.gitignore index 72255cf..ecc3d8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ emuld +tags diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fe3815..0eb3b09 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,7 @@ SET(PKG_MODULE edbus capi-network-connection eventsystem + libxml-2.0 ) pkg_check_modules(PKGS REQUIRED ${PKG_MODULE}) diff --git a/include/emuld.h b/include/emuld.h index 09c152c..cd4d01b 100644 --- a/include/emuld.h +++ b/include/emuld.h @@ -55,13 +55,6 @@ #define DBUS_PATH_BOOT_DONE "/Org/Tizen/System/DeviceD/Core" #define DBUS_IFACE_BOOT_DONE "org.tizen.system.deviced.core" -// Network -#define MAX_CLIENT 10000 -#define TID_NETWORK 1 -void* register_connection(void *data); -void destroy_connection(void); -extern pthread_t tid[MAX_CLIENT+1]; - // Common #define DEFAULT_MSGPROC "default" #define HDS_DEFAULT_ID "fsdef0" @@ -77,12 +70,18 @@ extern pthread_t tid[MAX_CLIENT+1]; #define GROUP_MEMORY 30 #define STATUS 15 -#define TID_NETWORK 1 -#define TID_LOCATION 3 -#define TID_HDS_ATTACH 4 -#define TID_HDS_DETACH 5 -#define TID_SENSOR 6 -#define TID_VCONF 7 +enum tid_list { + TID_NETWORK = 1, + TID_LOCATION = 3, + TID_HDS_ATTACH = 4, + TID_HDS_DETACH = 5, + TID_SENSOR = 6, + TID_VCONF = 7, + TID_CAPABILITY = 8, + TID_MAX +}; + +extern pthread_t tid[TID_MAX + 1]; /* common vconf keys */ #define VCONF_LOW_MEMORY "memory/sysman/low_memory" @@ -113,27 +112,46 @@ struct setting_device_param char type_cmd[ID_SIZE]; }; +// Helper +int parse_val(char *buff, unsigned char data, char *parsbuf); + +// Network +void * register_connection(void *data); +void destroy_connection(void); + +// Checking capabilities +void * check_capabilities(void *data); + +// Vconf +void set_vconf_cb(void); void add_vconf_map_common(void); void add_vconf_map_profile(void); -void send_default_suspend_req(void); + +// HDS void send_default_mount_req(void); -bool valid_hds_path(char* path); -int try_mount(char* tag, char* path); +bool valid_hds_path(char *path); +int try_mount(char *tag, char *path); void hds_unmount_all(void); -void set_vconf_cb(void); + +// Guest condition +void send_default_suspend_req(void); void send_emuld_connection(void); + +// Dbus +void dbus_send(const char *device, const char * target, const char * option); +void dbus_send_signal(const char *device, const char *target, const char *option); + +// Message proc void add_msg_proc_common(void); void add_msg_proc_ext(void); -void dbus_send(const char* device, const char* target, const char* option); -void dbus_send_signal(const char* device, const char* target, const char* option); -int parse_val(char *buff, unsigned char data, char *parsbuf); -bool msgproc_hds(ijcommand* ijcmd); -bool msgproc_cmd(ijcommand* ijcmd); -bool msgproc_suspend(ijcommand* ijcmd); -bool msgproc_system(ijcommand* ijcmd); -bool msgproc_package(ijcommand* ijcmd); -bool msgproc_vconf(ijcommand* ijcmd); -bool msgproc_location(ijcommand* ijcmd); +// Message proc handling +bool msgproc_hds(ijcommand *ijcmd); +bool msgproc_cmd(ijcommand *ijcmd); +bool msgproc_suspend(ijcommand *ijcmd); +bool msgproc_system(ijcommand *ijcmd); +bool msgproc_package(ijcommand *ijcmd); +bool msgproc_vconf(ijcommand *ijcmd); +bool msgproc_location(ijcommand *ijcmd); #endif // __EMULD_H__ diff --git a/include/ijcmd.h b/include/ijcmd.h index 5bd69b7..d188189 100644 --- a/include/ijcmd.h +++ b/include/ijcmd.h @@ -44,6 +44,7 @@ #define IJTYPE_BOOT "boot" #define IJTYPE_VCONF "vconf" #define IJTYPE_LOCATION "location" +#define IJTYPE_CAP "cap" // struct struct fd_info diff --git a/packaging/emuld.spec b/packaging/emuld.spec index 2d787e5..74dfada 100644 --- a/packaging/emuld.spec +++ b/packaging/emuld.spec @@ -17,6 +17,7 @@ Source0: %{name}-%{version}.tar.gz Group: SDK/Other BuildRequires: cmake +BuildRequires: libxml2-devel BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(deviced) BuildRequires: pkgconfig(dlog) diff --git a/src/common.cpp b/src/common.cpp index 4063ee5..a6f9a27 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -39,6 +39,8 @@ #include #include +#include + #include "emuld.h" #define CMD_BUF 1024 @@ -49,6 +51,9 @@ #define MKDIR_MODE (S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) #define MAX_DIGITS_INT 10 // in decimal +#define PATH_MODEL_CONFIG "/etc/config/model-config.xml" +#define NUM_CHECK_LIST 13 + unsigned int msize = MAX_PAYLOAD_SIZE; void add_vconf_map_common(void) @@ -240,6 +245,126 @@ void send_default_mount_req() send_to_ecs(IJTYPE_HDS, 0, 0, NULL); } +static const xmlChar* cap_check_list[] = { + (const xmlChar*)"tizen.org/feature/battery", + (const xmlChar*)"tizen.org/feature/location", + (const xmlChar*)"tizen.org/feature/network.nfc", + (const xmlChar*)"tizen.org/feature/network.telephony", + (const xmlChar*)"tizen.org/feature/sensor.accelerometer", + (const xmlChar*)"tizen.org/feature/sensor.gyroscope", + (const xmlChar*)"tizen.org/feature/sensor.magnetometer", + (const xmlChar*)"tizen.org/feature/sensor.proximity", + (const xmlChar*)"tizen.org/feature/sensor.photometer", + (const xmlChar*)"tizen.org/feature/sensor.barometer", + (const xmlChar*)"tizen.org/feature/sensor.heart_rate_monitor", + (const xmlChar*)"tizen.org/feature/sensor.ultraviolet", + (const xmlChar*)"tizen.org/feature/sensor.pedometer" +}; + +static int cap_device_list[] = { + 0x0001, // Battery + 0x0002, // Location + 0x0004, // NFC + 0x0008, // Telephony + 0x0010, // Accelerometer + 0x0020, // Gyroscope + 0x0040, // Magnetometer + 0x0080, // Proximity + 0x0100, // Light + 0x0200, // Pressure + 0x0400, // HeartRate + 0x0800, // Ultraviolet + 0x1000, // Pedometer +}; + +static void search_xml(xmlTextReaderPtr reader, int *list) +{ + const xmlChar** cap_list = cap_check_list; + const xmlChar *attr, *value; + int ret; + + attr = xmlTextReaderGetAttribute(reader, (const xmlChar*)"name"); + + for (unsigned int i = 0; i < NUM_CHECK_LIST; i++) { + if (list[i] == 0 && xmlStrEqual(attr, cap_list[i])) { + ret = xmlTextReaderRead(reader); + if (ret == 1 && xmlTextReaderHasValue(reader)) { + value = xmlTextReaderConstValue(reader); + if (xmlStrEqual(value, (const xmlChar*)"true")) { + list[i] = 1; + } + } + LOGINFO("Found: %s, value: %d", attr, list[i]); + } + } +} + +static int check_model_config(int* data) +{ + xmlTextReaderPtr reader = NULL; + int ret; + int cap_result_list [NUM_CHECK_LIST]; + const char* path = PATH_MODEL_CONFIG; + + reader = xmlReaderForFile(path, NULL, 0); + if (reader == NULL) { + LOGERR("Could not parse file %s", path); + return -1; + } + + memset(cap_result_list, 0, sizeof(cap_result_list)); + + ret = xmlTextReaderRead(reader); + while (ret == 1) { + search_xml(reader, cap_result_list); + ret = xmlTextReaderRead(reader); + } + + xmlFreeTextReader(reader); + + if (ret != 0) { + LOGERR("Failed to parse : %d", ret); + return -1; + } + + for (int i = 0; i < NUM_CHECK_LIST; i++) { + if (cap_result_list[i] == 1) { + *data |= cap_device_list[i]; + } + } + + return 0; +} + +void* check_capabilities(void *data) +{ + int ret; + int cap_check = 0; + + usleep(1000000); // XXX: wait 1 sec to be ready the networking + + ret = check_model_config(&cap_check); + if (ret < 0) { + LOGERR("Failed to check model config."); + return NULL; + } + + LOGINFO("Check capability: %x, %d", cap_check, cap_check); + + char *buf = (char*)malloc(MAX_DIGITS_INT + 1); + if (!buf) { + LOGERR("insufficient memory available"); + return NULL; + } + + snprintf(buf, MAX_DIGITS_INT + 1, "%d", cap_check); + send_to_ecs(IJTYPE_CAP, 0, 0, buf); + + free(buf); + + return NULL; +} + static void low_memory_cb(keynode_t* pKey, void* pData) { switch (vconf_keynode_get_type(pKey)) { diff --git a/src/emuld.cpp b/src/emuld.cpp index a4b8da8..f2db62f 100644 --- a/src/emuld.cpp +++ b/src/emuld.cpp @@ -38,7 +38,7 @@ #include "emuld.h" -pthread_t tid[MAX_CLIENT + 1]; +pthread_t tid[TID_MAX + 1]; int g_epoll_fd; struct epoll_event g_events[MAX_EVENTS]; void* dl_handles[MAX_PLUGINS]; @@ -489,13 +489,17 @@ int main( int argc , char *argv[]) init_plugins(); if (pthread_create(&conn_thread_t, NULL, register_connection, NULL) < 0) { - LOGERR("network connection pthread create fail!"); + LOGERR("network connection thread is failed to create!"); return -1; } - if (pthread_create(&tid[TID_NETWORK], NULL, handling_network, NULL) != 0) - { - LOGERR("boot noti pthread create fail!"); + if (pthread_create(&tid[TID_NETWORK], NULL, handling_network, NULL) != 0) { + LOGERR("boot notification thread is failed to create!"); + return -1; + } + + if (pthread_create(&tid[TID_CAPABILITY], NULL, check_capabilities, NULL) != 0) { + LOGERR("checking capabilities thread is failed to create!"); return -1; } @@ -511,12 +515,17 @@ int main( int argc , char *argv[]) ret = pthread_join(tid[TID_NETWORK], &retval); if (ret < 0) { - LOGERR("message loop pthread join is failed."); + LOGERR("message loop thread is failed to join."); } ret = pthread_join(conn_thread_t, &retval); if (ret < 0) { - LOGERR("network connection pthread join is failed."); + LOGERR("network connection thread is failed to join."); + } + + ret = pthread_join(tid[TID_CAPABILITY], &retval); + if (ret < 0) { + LOGERR("checking capabilities thread is failed to join."); } emuld_exit();