2 * Copyright (c) 2018 TOYOTA MOTOR CORPORATION
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef TMCAGLWM_POLICY_MANAGER_HPP
18 #define TMCAGLWM_POLICY_MANAGER_HPP
21 #include <unordered_map>
27 struct sd_event_source;
33 explicit PolicyManager();
34 ~PolicyManager() = default;
36 using Handler = std::function<void(json_object *)>;
40 Handler onStateTransitioned;
45 void registerCallback(CallbackTable callback_table);
46 int setInputEventData(json_object *json_in);
47 int executeStateTransition();
50 // Do not use these functions
51 int transitionState(sd_event_source *source, void *data);
52 int timerEvent(sd_event_source *source, uint64_t usec, void *data);
55 // Disable copy and move
56 PolicyManager(PolicyManager const &) = delete;
57 PolicyManager &operator=(PolicyManager const &) = delete;
58 PolicyManager(PolicyManager &&) = delete;
59 PolicyManager &operator=(PolicyManager &&) = delete;
61 typedef struct EventInfo
68 typedef struct AreaState
75 typedef std::vector<AreaState> AreaList;
76 typedef struct LayoutState
79 std::map<std::string, int> category_num;
83 typedef struct LayerState
86 LayoutState layout_state;
90 typedef std::vector<std::string> Areas;
91 typedef std::vector<std::string> Categories;
92 typedef std::vector<std::string> Roles;
95 std::unordered_map<std::string, int> eventname2no;
96 std::unordered_map<std::string, int> categoryname2no;
97 std::unordered_map<std::string, int> areaname2no;
99 std::unordered_map<std::string, std::string> role2category;
100 std::unordered_map<std::string, std::string> category2role;
101 std::unordered_map<std::string, Areas> category2areas;
102 std::unordered_map<std::string, Categories> layer2categories;
104 std::queue<EventInfo> event_info_queue;
105 std::map<int, struct sd_event_source *> event_source_list;
106 std::map<int, std::string> req_role_list;
108 CallbackTable callback;
110 std::unordered_map<std::string, LayerState> prv_layers;
111 std::unordered_map<std::string, LayerState> crr_layers;
113 std::unordered_map<std::string, LayoutState> default_layouts;
115 std::map<std::string, Roles> invisible_role_history;
117 void initializeState();
118 void initializeLayerState();
119 void updateState(int event_id, StmState crr_state);
120 void updateLayer(int event_id, StmState crr_state);
121 int updateLayout(int event_id, int layer_no,
122 std::string crr_layout_name, LayoutState &crr_layout_state);
123 void createOutputInformation(StmState crr_state, json_object **json_out);
124 int setStateTransitionProcessToSystemd(int event, uint64_t delay_ms, std::string role);
126 void pushInvisibleRoleHistory(std::string category, std::string role);
127 std::string popInvisibleRoleHistory(std::string category);
132 void dumpLayerState(std::unordered_map<std::string, LayerState> &layers);
133 void dumpInvisibleRoleHistory();
135 void addStateToJson(const char *name, bool changed,
136 std::string state, json_object **json_out);
137 void addStateToJson(const char *layer_name, bool changed,
138 AreaList area_list, json_object **json_out);
139 const char *getStringFromJson(json_object *obj, const char *key);
140 int inputJsonFilie(const char *file, json_object **obj);
142 std::vector<std::string> parseString(std::string str, char delimiter);
143 std::string deleteSpace(std::string str);
145 static const char *kDefaultRoleDb;
146 static const char *kDefaultStateDb;
149 #endif // TMCAGLWM_POLICY_MANAGER_HPP