device: check capabilities from model-config.xml 00/93400/7
authorJinhyung Choi <jinh0.choi@samsung.com>
Mon, 24 Oct 2016 06:35:04 +0000 (15:35 +0900)
committerJinhyung Choi <jinh0.choi@samsung.com>
Wed, 2 Nov 2016 04:12:01 +0000 (13:12 +0900)
Change-Id: I77d2f920fcc5df6270cf59c9f00b6f9f9c78b655
Signed-off-by: Jinhyung Choi <jinh0.choi@samsung.com>
.gitignore
CMakeLists.txt
include/emuld.h
include/ijcmd.h
packaging/emuld.spec
src/common.cpp
src/emuld.cpp

index 72255cf7ba31424ab8a63463eae5c02422b6affb..ecc3d8ff7b44ff0e125f848861ccd91dfb057bc9 100644 (file)
@@ -1 +1,2 @@
 emuld
+tags
index 5fe38153c89cc724422ed96211fdcdbff0f43240..0eb3b09d843fdf5024f55d4b9a0d94ea89038c74 100644 (file)
@@ -94,6 +94,7 @@ SET(PKG_MODULE
     edbus
     capi-network-connection
     eventsystem
+    libxml-2.0
 )
 
 pkg_check_modules(PKGS REQUIRED ${PKG_MODULE})
index 09c152c60f3150fc9baa84031dc2554ab07831e9..cd4d01b2bd6c3d6fef2e111f72cb0ed6c729e683 100644 (file)
 #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(charpath);
-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__
index 5bd69b738e95bff7b2722a4ce306351f1c3ebf42..d1881894bc13bb45ee813be345d298ae844a620c 100644 (file)
@@ -44,6 +44,7 @@
 #define IJTYPE_BOOT         "boot"
 #define IJTYPE_VCONF        "vconf"
 #define IJTYPE_LOCATION     "location"
+#define IJTYPE_CAP          "cap"
 
 // struct
 struct fd_info
index 2d787e54cbdbbf1dc43cef5b021e7b4bee5a81e0..74dfadae551dedde087bbf4f7d3746de2857e8cb 100644 (file)
@@ -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)
index 4063ee55902bc021412607c5562ed622048260df..a6f9a276f673f3f80f8e219344da936a4431b189 100644 (file)
@@ -39,6 +39,8 @@
 #include <stdlib.h>
 #include <mntent.h>
 
+#include <libxml/xmlreader.h>
+
 #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)) {
index a4b8da86ef048fd01478f955b81403f23ebd146f..f2db62f726d002e5b7229190acf4df2684a40532 100644 (file)
@@ -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();