849dc4f7d532c7e5ab824461b6731be6f75bb3db
[apps/agl-service-homescreen.git] / src / hs-config.h
1 /*
2  * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef HOMESCREEN_CONFIG_H
17 #define HOMESCREEN_CONFIG_H
18
19 #include <array>
20 #include <vector>
21 #include <unordered_map>
22 #include "hs-helper.h"
23
24 #define RECOVER_MAX 3
25
26 struct handshake_info {
27     int times;    // sleep times
28     int sleep;    // sleep x ms
29 };
30
31 struct recover_app_info {
32     std::string appid;  // application id like "dashboard"
33     std::string area;   // application default display area
34     bool visibility;    // the visibility when system starting
35 };
36
37 using recover_map = std::unordered_map<std::string, std::vector<struct recover_app_info>>;
38
39 class HS_Config {
40 public:
41     HS_Config() :  m_hs_conf(nullptr), m_lastmode(nullptr), m_handshake_info({20000, 50}) {}
42     ~HS_Config() {json_object_put(m_hs_conf);json_object_put(m_lastmode);}
43     HS_Config(HS_Config const &) = delete;
44     HS_Config &operator=(HS_Config const &) = delete;
45     HS_Config(HS_Config &&) = delete;
46     HS_Config &operator=(HS_Config &&) = delete;
47
48     int readConfig(void);
49     const struct handshake_info* getHandshakeInfo(void) const {return &m_handshake_info;}
50     recover_map& getRecoverMap(void) {return m_recover_map;}
51     static const std::array<std::string, RECOVER_MAX> keys_recover_type;   // based on hs-conf.json
52
53 private:
54     int parseConfig(void);
55     std::vector<struct recover_app_info> getRecoverAppInfo(struct json_object *obj);
56
57     const std::string hs_conf_json = "hs-conf.json";
58     const std::string lastmode_json = "lastmode.json";
59     const std::string key_handshake = "handshake";
60     const std::string key_times = "times";
61     const std::string key_sleep = "sleep";
62     const std::string key_recover = "recover";
63     const std::string key_appid = "appid";
64     const std::string key_visibility = "visibility";
65     const std::string key_area = "area";
66
67     struct json_object *m_hs_conf;
68     struct json_object *m_lastmode;
69     recover_map m_recover_map;
70     struct handshake_info m_handshake_info;
71 };
72 #endif // HOMESCREEN_CONFIG_H