Bug fix: Always changed flag becomes true when restriction mode is changed
[apps/agl-service-windowmanager.git] / src / policy_manager / policy_manager.hpp
1 /*
2  * Copyright (c) 2018 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
17 #ifndef TMCAGLWM_POLICY_MANAGER_HPP
18 #define TMCAGLWM_POLICY_MANAGER_HPP
19
20
21 #include <unordered_map>
22 #include <vector>
23 #include <queue>
24
25
26 struct json_object;
27 struct sd_event;
28
29
30 class PolicyManager {
31
32 public:
33     explicit PolicyManager();
34     ~PolicyManager() = default;
35
36     using Handler = std::function<void(json_object *)>;
37
38     typedef struct {
39         Handler  onStateTransitioned;
40         Handler  onError;
41     } CallbackTable;
42
43     int initialize();
44     void registerCallback(CallbackTable callback_table);
45     int setInputEventData(json_object* json_in);
46     int executeStateTransition();
47     void undoState();
48
49 private:
50     // Disable copy and move
51     PolicyManager(PolicyManager const &) = delete;
52     PolicyManager &operator=(PolicyManager const &) = delete;
53     PolicyManager(PolicyManager &&) = delete;
54     PolicyManager &operator=(PolicyManager &&) = delete;
55
56     typedef struct EventInfo {
57         int event;
58         std::string role;
59         uint64_t delay;
60     } EventInfo;
61
62     // Convert map
63     std::unordered_map<std::string, int> eventname2no;
64     std::unordered_map<std::string, int> categoryname2no;
65     std::unordered_map<std::string, int> areaname2no;
66
67     std::unordered_map<std::string, std::string> role2category;
68     std::unordered_map<std::string, std::string> category2role;
69     std::unordered_map<std::string, std::string> role2defaultarea;
70
71     std::queue<EventInfo> event_info_queue;
72
73     void initializeLocalState();
74     int initializeSdEventLoop();
75
76     // Load role.db
77     int loadRoleDb();
78
79     // Load layout.db
80     int loadLayoutDb();
81
82     const char* getStringFromJson(json_object* obj, const char* key);
83     int inputJsonFilie(const char* file, json_object** obj);
84     std::vector<std::string> parseString(std::string str, char delimiter);
85     std::string deleteSpace(std::string str);
86
87 };
88
89
90 #endif  // TMCAGLWM_POLICY_MANAGER_HPP