read json file
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Wed, 10 Apr 2019 11:51:23 +0000 (19:51 +0800)
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>
Wed, 10 Apr 2019 11:51:23 +0000 (19:51 +0800)
Change-Id: Ie1a97fc8c3c6585d49574a051920a018a438deb6

src/homescreen.cpp

index c02f62b..eeba767 100644 (file)
@@ -32,6 +32,14 @@ const char _display_message[] = "display_message";
 const char _reply_message[] = "reply_message";
 const char _keyData[] = "data";
 const char _keyId[] = "id";
+const char _HS_CONF_JSON[] = "hs-conf.json";
+const char _LASTMODE_JSON[] = "lastmode.json";
+
+struct hs_config {
+    struct json_object *hs_conf;
+    struct json_object *lastmode;
+};
+static struct hs_config g_hs_config;
 
 struct hs_instance {
   HS_ClientManager *client_manager;   // the connection session manager
@@ -533,8 +541,20 @@ static const afb_verb_t verbs[]= {
  */
 static int preinit(afb_api_t api)
 {
-   AFB_DEBUG("binding preinit (was register)");
-   return 0;
+    AFB_DEBUG("binding preinit (was register)");
+    auto rootdir = std::string(getenv("AFM_APP_INSTALL_DIR"));
+    auto path = rootdir + "/etc/" + _HS_CONF_JSON;
+    if(readJsonFile(path.c_str(), &g_hs_config.hs_conf) < 0) {
+        AFB_ERROR("read %s failed.", _HS_CONF_JSON);
+        return -1;
+    }
+
+    path = rootdir + "/etc/" + _LASTMODE_JSON;
+    if(readJsonFile(path.c_str(), &g_hs_config.lastmode) < 0) {
+        AFB_ERROR("read %s failed.", _LASTMODE_JSON);
+        return -1;
+    }
+    return 0;
 }
 
 /**