aboutsummaryrefslogtreecommitdiffstats
path: root/src/policy_manager/policy_manager.hpp
blob: fd7314ca62228690865e92434eb46e67854dde6f (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * Copyright (c) 2018 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 TMCAGLWM_POLICY_MANAGER_HPP
#define TMCAGLWM_POLICY_MANAGER_HPP


#include <unordered_map>
#include <vector>
#include <queue>


struct json_object;
struct sd_event;


class PolicyManager {

public:
    explicit PolicyManager();
    ~PolicyManager() = default;

    using Handler = std::function<void(json_object *)>;

    typedef struct {
        Handler  onStateTransitioned;
        Handler  onError;
    } CallbackTable;

    int initialize();
    void registerCallback(CallbackTable callback_table);
    int setInputEventData(json_object* json_in);
    int executeStateTransition();
    void undoState();

private:
    // Disable copy and move
    PolicyManager(PolicyManager const &) = delete;
    PolicyManager &operator=(PolicyManager const &) = delete;
    PolicyManager(PolicyManager &&) = delete;
    PolicyManager &operator=(PolicyManager &&) = delete;

    typedef struct EventInfo {
        int event;
        std::string role;
        uint64_t delay;
    } EventInfo;

    // Convert map
    std::unordered_map<std::string, int> eventname2no;
    std::unordered_map<std::string, int> categoryname2no;
    std::unordered_map<std::string, int> areaname2no;

    std::unordered_map<std::string, std::string> role2category;
    std::unordered_map<std::string, std::string> category2role;
    std::unordered_map<std::string, std::string> role2defaultarea;

    std::queue<EventInfo> event_info_queue;

    void initializeLocalState();
    int initializeSdEventLoop();

    // Load role.db
    int loadRoleDb();

    // Load layout.db
    int loadLayoutDb();

    const char* getStringFromJson(json_object* obj, const char* key);
    int inputJsonFilie(const char* file, json_object** obj);
    std::vector<std::string> parseString(std::string str, char delimiter);
    std::string deleteSpace(std::string str);

};


#endif  // TMCAGLWM_POLICY_MANAGER_HPP