Update managing layout information
[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
24
25 struct json_object;
26 struct sd_event;
27
28
29 class PolicyManager {
30
31 public:
32     explicit PolicyManager();
33     ~PolicyManager() = default;
34
35     using Handler = std::function<void(json_object *)>;
36
37     typedef struct {
38         Handler  onStateTransitioned;
39         Handler  onError;
40     } CallbackTable;
41
42     int initialize();
43     void registerCallback(CallbackTable callback_table);
44     int inputEvent(json_object* json_in);
45     std::string roleToCategory(const char* role);
46
47 private:
48     // Disable copy and move
49     PolicyManager(PolicyManager const &) = delete;
50     PolicyManager &operator=(PolicyManager const &) = delete;
51     PolicyManager(PolicyManager &&) = delete;
52     PolicyManager &operator=(PolicyManager &&) = delete;
53
54     // Convert map
55     std::unordered_map<std::string, int> eventname2no_;
56     std::unordered_map<std::string, int> categoryname2no_;
57     std::unordered_map<std::string, int> areaname2no_;
58
59     std::unordered_map<std::string, std::string> role2category_;
60     std::unordered_map<std::string, std::string> category2role_;
61     std::unordered_map<std::string, std::string> role2defaultarea_;
62
63 #if 0
64     struct AreaState {
65         std::string name;
66         std::string role;
67     } AreaState;
68
69     struct LayoutState {
70         std::string name;
71         std::vector<AreaState> areas;
72     } LayoutState;
73
74     struct LayerState {
75         std::string name;
76         LayoutState layout;
77     } LayerState;
78 #endif
79
80     int initializeSdEventLoop();
81
82     // Load role.db
83     int loadRoleDb();
84
85     // Load layout.db
86     int loadLayoutDb();
87
88     const char* getStringFromJson(json_object* obj, const char* key);
89     int inputJsonFilie(const char* file, json_object** obj);
90     std::vector<std::string> parseString(std::string str, char delimiter);
91     std::string deleteSpace(std::string str);
92
93 };
94
95
96 extern const char* getStringFromJson(json_object* obj, const char* key);
97 extern int getIntFromJson(json_object* obj, const char* key);
98
99
100 #endif  // TMCAGLWM_POLICY_MANAGER_HPP