summaryrefslogtreecommitdiffstats
path: root/policy_manager/policy_manager.hpp
diff options
context:
space:
mode:
authorYuta Doi <yuta-d@witz-inc.co.jp>2018-07-09 17:23:31 +0900
committerYuta Doi <yuta-d@witz-inc.co.jp>2018-08-15 10:46:04 +0900
commitc1d85371b1eb693128cf9553c356ea77e609d9a3 (patch)
treef4e69885b1c7c5e4116cf4eea7e5237412ce82c0 /policy_manager/policy_manager.hpp
parent38255dcda8e7e9462ed3b16ebe39c638bc9b349f (diff)
Readd Policy Manager as plugin
This patch reverts commit c6f9a9b8468b3746a3dec7ee2a0b7d84ec9fb44a and update it. Policy Manager decides next layout by inputed event and current state based on the policy table. And Policy Manager is plugin for Window Manager. Therefore the OEMs can replace it. This patch provides Policy Manager I/F as reference implementation and does not have policy table. Therefore Policy Manager updates each layers to draw the applications in requested area in accordance with just like activate/deactivate request. [APIs of Policy Manager class] - int initialize(void) Initialize Policy Manger. in: none out: 0(success), -1(error) - void registerCallback(CallbackTable callback_table) Register callback functions. in: the pointers of callback handlers out: none "CallbackTable" type is as follows: typedef struct { Handler onStateTransitioned; Handler onError; } CallbackTable; "Handler" type is as follows: using Handler = std::function<void(json_object *)>; - int setInputEventData(json_object *json_in) Set input event data for the policy table. in: input event data as json_object out: 0(success), -1(error) - int executeStateTransition(void) Execute state transition by using set input event data. in: none out: 0(success), -1(error) - void undoState(void) Undo state only once per once state transition. in: none out: none [Callbacks of Policy Manager class] - void onStateTransitioned(json_object *json_out) When state transition succeeds, this callback is called. The argument json_out has the state after transition. - void onError(json_object *json_out) When state transition fails, this callback is called. The argument json_out has the error information like message, inputed event datas and etc.. Bug-AGL: SPEC-1537 Change-Id: Ib8c71f2e544cb90b6763d07fad56dc1c453e9a97 Signed-off-by: Yuta Doi <yuta-d@witz-inc.co.jp>
Diffstat (limited to 'policy_manager/policy_manager.hpp')
-rw-r--r--policy_manager/policy_manager.hpp149
1 files changed, 149 insertions, 0 deletions
diff --git a/policy_manager/policy_manager.hpp b/policy_manager/policy_manager.hpp
new file mode 100644
index 0000000..798b706
--- /dev/null
+++ b/policy_manager/policy_manager.hpp
@@ -0,0 +1,149 @@
+/*
+ * 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 <functional>
+#include <unordered_map>
+#include <vector>
+#include <queue>
+
+struct json_object;
+struct sd_event;
+struct sd_event_source;
+struct StmState;
+
+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();
+
+ // Do not use these functions
+ int transitionState(sd_event_source *source, void *data);
+ int timerEvent(sd_event_source *source, uint64_t usec, void *data);
+
+ 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;
+
+ typedef struct AreaState
+ {
+ std::string name;
+ std::string category;
+ std::string role;
+ } AreaState;
+
+ typedef std::vector<AreaState> AreaList;
+ typedef struct LayoutState
+ {
+ std::string name;
+ std::map<std::string, int> category_num;
+ AreaList area_list;
+ } LayoutState;
+
+ typedef struct LayerState
+ {
+ std::string name;
+ LayoutState layout_state;
+ bool changed;
+ } LayerState;
+
+ typedef std::vector<std::string> Areas;
+ typedef std::vector<std::string> Categories;
+ typedef std::vector<std::string> Roles;
+
+ // 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, Areas> category2areas;
+ std::unordered_map<std::string, Categories> layer2categories;
+
+ std::queue<EventInfo> event_info_queue;
+ std::map<int, struct sd_event_source *> event_source_list;
+ std::map<int, std::string> req_role_list;
+
+ CallbackTable callback;
+
+ std::unordered_map<std::string, LayerState> prv_layers;
+ std::unordered_map<std::string, LayerState> crr_layers;
+
+ std::unordered_map<std::string, LayoutState> default_layouts;
+
+ std::map<std::string, Roles> invisible_role_history;
+
+ void initializeState();
+ void initializeLayerState();
+ void updateState(int event_id, StmState crr_state);
+ void updateLayer(int event_id, StmState crr_state);
+ int updateLayout(int event_id, int layer_no,
+ std::string crr_layout_name, LayoutState &crr_layout_state);
+ void createOutputInformation(StmState crr_state, json_object **json_out);
+ int setStateTransitionProcessToSystemd(int event, uint64_t delay_ms, std::string role);
+
+ void pushInvisibleRoleHistory(std::string category, std::string role);
+ std::string popInvisibleRoleHistory(std::string category);
+
+ int loadRoleDb();
+ int loadStateDb();
+
+ void dumpLayerState(std::unordered_map<std::string, LayerState> &layers);
+ void dumpInvisibleRoleHistory();
+
+ void addStateToJson(const char *name, bool changed,
+ std::string state, json_object **json_out);
+ void addStateToJson(const char *layer_name, bool changed,
+ AreaList area_list, json_object **json_out);
+ 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);
+
+ static const char *kDefaultRoleDb;
+ static const char *kDefaultStateDb;
+};
+
+#endif // TMCAGLWM_POLICY_MANAGER_HPP