aboutsummaryrefslogtreecommitdiffstats
path: root/src/hs-config.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/hs-config.cpp')
-rw-r--r--src/hs-config.cpp149
1 files changed, 149 insertions, 0 deletions
diff --git a/src/hs-config.cpp b/src/hs-config.cpp
new file mode 100644
index 0000000..dad3a7e
--- /dev/null
+++ b/src/hs-config.cpp
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "hs-config.h"
+
+
+/**
+ * read configuration file to memory
+ *
+ * #### Parameters
+ * - Nothing
+ *
+ * #### Return
+ * None
+ *
+ */
+int HS_Config::readConfig(void)
+{
+ auto rootdir = std::string(getenv("AFM_APP_INSTALL_DIR"));
+ auto path = rootdir + "/etc/" + hs_conf_json;
+ if(readJsonFile(path.c_str(), &m_hs_conf) < 0) {
+ AFB_ERROR("read %s failed.", hs_conf_json.c_str());
+ return -1;
+ }
+
+ path = rootdir + "/etc/" + lastmode_json;
+ if(readJsonFile(path.c_str(), &m_lastmode) < 0) {
+ AFB_ERROR("read %s failed.", lastmode_json.c_str());
+ m_lastmode = nullptr;
+ }
+
+ return parseConfig();
+}
+
+/**
+ * parse configuration file contents
+ *
+ * #### Parameters
+ * - Nothing
+ *
+ * #### Return
+ * 0 : success
+ * 1 : fail
+ *
+ */
+int HS_Config::parseConfig(void)
+{
+ struct json_object *handshake_obj, *times_obj, *sleep_obj;
+ if(json_object_object_get_ex(m_hs_conf, key_handshake.c_str(), &handshake_obj)
+ && json_object_object_get_ex(handshake_obj, key_times.c_str(), &times_obj)
+ && json_object_object_get_ex(handshake_obj, key_sleep.c_str(), &sleep_obj)) {
+ m_handshake_info.times = json_object_get_int(times_obj);
+ m_handshake_info.sleep = json_object_get_int(sleep_obj);
+ }
+ else {
+ AFB_WARNING("get handshake info error, use default value.");
+ }
+
+ struct json_object *recover_obj;
+ if(json_object_object_get_ex(m_hs_conf, key_recover.c_str(), &recover_obj)) {
+ for(auto &m : keys_recover_type) {
+ struct json_object *obj;
+ if(json_object_object_get_ex(recover_obj, m.c_str(), &obj)) {
+ if(json_object_get_type(obj) != json_type_array ) {
+ continue;
+ }
+ m_recover_map[m] = std::move(getRecoverAppInfo(obj));
+ }
+ }
+
+ if(m_recover_map.empty()) {
+ AFB_ERROR("get homescreen recover list failed.");
+ return -1;
+ }
+ }
+ else {
+ AFB_ERROR("get homescreen recover object failed.");
+ return -1;
+ }
+
+ if(json_object_get_type(m_lastmode) == json_type_array ) {
+ struct std::vector<recover_app_info> v_lastmode = std::move(getRecoverAppInfo(m_lastmode));
+ if(!v_lastmode.empty()) { // got saving lastmode isn't null, instead of default lastmode
+ m_recover_map[keys_recover_type[1]] = std::move(v_lastmode);
+ }
+ }
+
+ return 0;
+}
+
+/**
+ * get recover application information
+ * appid, visibility, display area
+ *
+ * #### Parameters
+ * - obj : application information
+ *
+ * #### Return
+ * recover_app_info vector
+ *
+ */
+std::vector<struct recover_app_info> HS_Config::getRecoverAppInfo(struct json_object *obj)
+{
+ int array_len = json_object_array_length(obj);
+ std::vector<struct recover_app_info> v_app_info;
+ for (int i = 0; i < array_len; ++i) {
+ struct json_object *info_obj = json_object_array_get_idx(obj, i);
+ struct recover_app_info info;
+ struct json_object *value_obj;
+ if(json_object_object_get_ex(info_obj, key_appid.c_str(), &value_obj)) {
+ info.appid = json_object_get_string(value_obj);
+ }
+ else {
+ AFB_ERROR("recover infomation doesn't include appid.");
+ v_app_info.clear();
+ return v_app_info;
+ }
+ if(json_object_object_get_ex(info_obj, key_area.c_str(), &value_obj)) {
+ info.area = json_object_get_string(value_obj);
+ }
+ else {
+ info.area = "normal.full";
+ }
+ if(json_object_object_get_ex(info_obj, key_visibility.c_str(), &value_obj)) {
+ std::string visibility = json_object_get_string(value_obj);
+ info.visibility = (visibility == "visible") ? true:false;
+ }
+ else {
+ info.visibility = false;
+ }
+ v_app_info.push_back(info);
+ }
+
+ return v_app_info;
+} \ No newline at end of file