aboutsummaryrefslogtreecommitdiffstats
path: root/src/hs-config.h
blob: d422248ef217bee7a2f49fe4b745342e7eb2f9da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * 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.
 */
#ifndef HOMESCREEN_CONFIG_H
#define HOMESCREEN_CONFIG_H

#include <array>
#include <vector>
#include <unordered_map>
#include "hs-helper.h"

#define RECOVER_MAX 3

struct handshake_info {
    int times;    // sleep times
    int sleep;    // sleep x ms
};

struct recover_app_info {
    std::string appid;  // application id like "dashboard"
    bool visibility;    // the visibility when system starting
};

using recover_map = std::unordered_map<std::string, std::vector<struct recover_app_info>>;

class HS_Config {
public:
    HS_Config() :  m_hs_conf(nullptr), m_lastmode(nullptr), m_handshake_info({20000, 50}) {}
    ~HS_Config() {json_object_put(m_hs_conf);json_object_put(m_lastmode);}
    HS_Config(HS_Config const &) = delete;
    HS_Config &operator=(HS_Config const &) = delete;
    HS_Config(HS_Config &&) = delete;
    HS_Config &operator=(HS_Config &&) = delete;

    int readConfig(void);
    const struct handshake_info* getHandshakeInfo(void) const {return &m_handshake_info;}
    recover_map& getRecoverMap(void) {return m_recover_map;}
    static const std::array<std::string, RECOVER_MAX> keys_recover_type;   // based on hs-conf.json

private:
    int parseConfig(void);
    std::vector<struct recover_app_info> getRecoverAppInfo(struct json_object *obj);

    const std::string hs_conf_json = "hs-conf.json";
    const std::string lastmode_json = "lastmode.json";
    const std::string key_handshake = "handshake";
    const std::string key_times = "times";
    const std::string key_sleep = "sleep";
    const std::string key_recover = "recover";
    const std::string key_appid = "appid";
    const std::string key_visibility = "visibility";

    struct json_object *m_hs_conf;
    struct json_object *m_lastmode;
    recover_map m_recover_map;
    struct handshake_info m_handshake_info;
};
#endif // HOMESCREEN_CONFIG_H